Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to auto collapse to definitions whenever you close a document?

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

like image 253
francis Avatar asked Nov 22 '10 12:11

francis


1 Answers

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
like image 98
Fraser Avatar answered Oct 03 '22 05:10

Fraser