Author Topic: Escape Macro  (Read 3807 times)

Dan112123

  • Community Member
  • Posts: 44
  • Hero Points: 2
Escape Macro
« on: September 13, 2011, 06:47:52 AM »
I'm new here so I would really appreciate some help in writing the follwoing macro. Here is the sequence:

1. If there is text selected ESC will unselect on the first press
2. On the second press it will hide all of the tool windows that are opened
3. Third press will open command line

If nothing selected start at #2, if nothing opened start at #3. If command line is already opened close it.

I have a macro that does this in Visual Studio so it would be nice to mimic this behavior. Here is what is looks like:

Code: [Select]
  Sub EscHandler()
        If Not DTE.ActiveDocument Is Nothing Then
            Dim sel As TextSelection = DTE.ActiveDocument.Selection
            If sel Is Nothing Then Exit Sub

            If sel.Text <> "" Then
                sel.Collapse()
                Exit Sub
            End If
        End If

        Dim activeWindow As Window = DTE.ActiveWindow
        If Not activeWindow Is Nothing Then


            If activeWindow.Kind = "Tool" Then
                activeWindow.AutoHides = True
                If Not DTE.ActiveDocument Is Nothing Then
                    DTE.ActiveDocument.ActiveWindow.Activate()
                End If
                Exit Sub
            End If
        End If

        MinimizeAllToolWindows()
        If Not DTE.ActiveDocument Is Nothing Then
            DTE.ActiveDocument.ActiveWindow.Activate()
        End If
    End Sub

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: Escape Macro
« Reply #1 on: September 13, 2011, 04:35:34 PM »
Which parts do you need help with?

Re: #1
- Test for selection is _isnull_selection.
- Unselect is deselect.

Re: #2
- This is the one I'd expect to be difficult in SE; the toolbar API surface area is limited, and is mostly undocumented.  Look in macros\toolbar.e for functions marked with "_command".
- To hide a toolbar, use tbHide( toolbar_form_name ).
- I don't know offhand how to dynamically find a list of "all known toolbars".  Scrounging in macros\toolbar.e might turn up something.
- I don't know offhand how to check whether any toolbars are visible.  Again, scrounging in macros\toolbar.e might turn up something.

Re: #3
- Toggling command line is cmdline_toggle.

Dan112123

  • Community Member
  • Posts: 44
  • Hero Points: 2
Re: Escape Macro
« Reply #2 on: September 13, 2011, 06:56:09 PM »
Thank you for your reply! Yes some help with #2 would be awesome as well. I will start looking at the file you mentioned. Looping through all of the avaliable windows and closing them by type would be best but to be honest the list of "mostly used" tool windows that I can close would be sufficient for now.