I work in Visual Studio 2008, and I would like to have Edit> Outlining> Collapse to Definitions run whenever I open a file. It would be nice if after that all regions were expanded. I tried the code that Kiralessa suggested in the comment. There is a problem with code folding , and it works very well as a macro that I need to run manually. I tried to extend this macro to act as an event by placing the following code in the EnvironmentEvents module in the Macro IDE:
Public Sub documentEvents_DocumentOpened(ByVal Document As EnvDTE.Document) Handles DocumentEvents.DocumentOpened Document.DTE.ExecuteCommand("Edit.CollapsetoDefinitions") DTE.SuppressUI = True Dim objSelection As TextSelection = DTE.ActiveDocument.Selection objSelection.StartOfDocument() Do While objSelection.FindText("#region", vsFindOptions.vsFindOptionsMatchInHiddenText) Loop objSelection.StartOfDocument() DTE.SuppressUI = False End Sub
However, this is not like when I open a file from my solution in VS. To verify that the macro was running, I put the MsgBox() operator in this routine and noticed that the code before Document.DTE.ExecuteCommand("Edit.CollapsetoDefinitions") worked fine, but nothing seemed to get after this line. When I debugged and set a breakpoint in the routine, I would hit F10 to go to the next line, and control would leave the routine as soon as this ExecuteCommand line was run. Despite this, this line does not seem to do anything, i.e. It does not destroy the description.
I also tried using only DTE.ExecuteCommand("Edit.CollapsetoDefinitions") inside the routine, but no luck.
This question tries to get the same end result as this one , but I ask what I can do wrong in my event processing macro.
Sarah vessels
source share