Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have written a macro that will auto-collapse code windows on opening. I don't know whether anyone else would find this a useful as I do but I'm posting it anyway.

 

  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.

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

Posted

I'm referring to outlining. If you still don't 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).

 

;)

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

Posted

Has no one else found this of any use? I'm 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?

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

Posted
I've found it very useful.

Nice. I'm glad that someone (other than me) thought it worthwhile. :)

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

Posted

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.....

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...