Autocollapsing macro

TechnoTone

Well-known member
Joined
Jan 20, 2003
Messages
224
Location
UK - London
I have written a macro that will auto-collapse code windows on opening. I dont know whether anyone else would find this a useful as I do but Im posting it anyway.

Code:
   Dim myWindows As New Collection
   Dim myThread As System.Threading.Thread

   Private Sub WindowEvents_WindowCreated(ByVal Window As EnvDTE.Window) Handles WindowEvents.WindowCreated

      Try
         myWindows.Add(Window)

         If myThread Is Nothing Then
            myThread = New System.Threading.Thread(AddressOf CollapseToDefinition)
         End If
         If myThread.ThreadState = System.Threading.ThreadState.Unstarted Then myThread.Start()

      Catch ex As System.Exception
         MsgBox(ex.Message)
      End Try

   End Sub

   Public Sub CollapseToDefinition()

      Dim myCount As Integer
      Do
         myCount = myWindows.Count
         myThread.Sleep(100)
      Loop Until myCount = myWindows.Count
      Dim myWindow As Window
      While myWindows.Count > 0
         Try
            myWindow = myWindows.Item(1)
            myWindows.Remove(1)
            myWindow.Activate()
            DTE.ExecuteCommand("Edit.CollapsetoDefinitions")
         Catch
         End Try
      End While
      myThread = Nothing
   End Sub
To install it, open the Macros IDE, open MyMacros-EnvironmentEvents, and copy-paste this code into the EnvironmentEvents module.

*It was written for VS.NET 2003.
 
Im referring to outlining. If you still dont know what I mean, open a code window (one with lots of code will work best), right-click and select Outlining - Collapse to Definitions (or press CTRL+MO).

;)
 
Has no one else found this of any use? Im surprised as I found the inability of the IDE to remember the outlined/collapsed state of a file to be one of the most annoying omissions. It really bothered me that every time I opened a code window I would have to manually collapse the code myself.


p.s. Moderators - is this a worthy entry for the Code Library?
 
Thanks for the post

I never actually knew that you could write macros for the enviornment im sure ill have fun with them,.. however ive often thought that this was something that was missing, im programming a rpg and scanning through 40 or 50 objects is annoying every time.....
 
Back
Top