开发者

How to wire up to events associated with VS2010's Outlining model

I'm writing an extension for VS2开发者_高级运维010 that reorders a page of code by rearranging code sections and inserting #regions.

I want to be able to code in a call to the "Edit.CollapseToDefinitions" command after I've completed my text manipulations. I can invoke this command in the Visual Studio model by calling ExecuteCommand on my DTE2 object.

However, if I invoke the command immediately after moving my text around the document VS hasn't had time to update its outlining record. So, I want to be able to hook up to outlining events on the current Text Editor window. Does anyone know how to do this?


There's no great way to do it. You can listen for outlining region change events on the IOutliningManager (retrieved by [Import]ing an IOutliningManagerService), but there are no guarantees that the first event will be the one in which the language service re-introduces all the outlining regions it can. Most languages do it on the VS idle loop, but still at some delay so that it doesn't interrupt slow typing.

I would try playing around with something like:

  1. Complete your text edits
  2. Call collapse to definitions
  3. Subscribe to IOutliningManager.RegionsChanged
  4. If the next event is raised in, say, the next 5 seconds, call collapse to definitions again.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜