6

I know this might not sound very useful to most people, but i really like having all my code collapsed in VS and it's getting kinda annoying having to ctrl+m ctrl+o everytime i'm closing a document.

Is there some add-in that does this, or can someone give me general tips to create the add-in? thanks

francis
  • 700
  • 2
  • 7
  • 18

1 Answers1

2

You can achieve the functionality you desire by creating a macro in visual studio that executes the CollapsetoDefinitions command when ever the DocumentClosing event is raised.

Simply go: Tools -> Macros -> Macros IDE.

Then add the following code to the EnvironmentEvents module.

Private Sub DocumentEvents_DocumentClosing(ByVal Document As EnvDTE.Document) Handles DocumentEvents.DocumentClosing
    Dim thread As New System.Threading.Thread(AddressOf CollapsToDefinition)
    thread.Start()
End Sub

Public Sub CollapsToDefinition()
  Try
      If DTE.ActiveDocument Is Nothing Then Exit Sub
      DTE.ExecuteCommand("Edit.CollapsetoDefinitions")
  Catch
      'Ignore any error
  End Try
End Sub
Fraser
  • 15,275
  • 8
  • 53
  • 104
  • Hello, thanks for the answer. This macro only "auto-collapses" when you close a tab other than the one you have currently selected. I tried to adapt it so that it would execute the Edit.Collapse command before the current document closed but i just can't get it to work :( – francis Apr 24 '12 at 13:57
  • Not sure what you mean, this works as expected for me using VS 2010 Ultimate. Which version are you using? – Fraser Apr 24 '12 at 21:30
  • this would work great I assume, had there been a "Macros" key in the Tools tab... VS2012 appears to have removed macros... Why? I do not know... – 5tar-Kaster Nov 06 '13 at 09:45