Introduction
Note: This is an enhancement of an article written by Kevin McFarlane. The original article can be found here.
When working in the .Net IDE, it's very easy to become overwhelmed by the numerous new tool windows. The macro presented here will automatically de/activate the tool windows. When the macro is called to deactivate the tool windows, it will note which tool windows are currently active before deactivating only those windows. Subsequently, only those windows that were deactivated will be re-activated. In this way, the same keyboard shortcut can be used to toggle between activating & deactivating the tool windows.
Background
As great as the .Net IDE is, having all the tool windows open can distract the programmer from focusing on the code. For example:
Here, it�s very hard to read the code, because of all the tool windows that are open. This macro will hide all the active tool windows:
so, now it�s much easier to concentrate on the code. The next invocation of the macro will restore all the tool windows.
Using the code
To use the macro, assign it a shortcut key. I assigned �Alt-T� to this macro, because it�s not preassigned by the IDE. Every time you press the shortcut key the tool windows will be de/activated.
Points of Interest
To check if a tool window is open, the macro calls CanToggleToolWindow
:
Function CanToggleToolWindow(ByVal vsWindowKind As String, _
ByRef ToolWin As Window) As Boolean
Try
ToolWin = DTE.Windows.Item(vsWindowKind)
Catch ex As System.IndexOutOfRangeException
Return False
Catch ex As System.Exception
MsgBox(ex.GetType().ToString() & vbNewLine & vbNewLine & ex.Message)
Return False
End Try
Return True
End Function
DTE.Windows.Item(vsWindowKind)
throws an exception if the index is out of range. If an exception is thrown we assume that the desired tool window is not open. Therefore, we will not de/activate that tool window. Otherwise, a reference to the window is returned.
To toggle a single tool window, use
Sub ToggleToolWindow(ByVal vsWindowKind As String, ByRef ShouldToggle As Boolean)
Dim ToolWin As Window
If (Not CanToggleToolWindow(vsWindowKind, ToolWin)) Then
ShouldToggle = False
Exit Sub
End If
If (ToolWindowsAreVisible) Then
If (ToolWin.Visible()) Then
ShouldToggle = True
End If
ToolWin.Visible = False
Else
If (ShouldToggle) Then
ToolWin.Visible = True
End If
End If
End Sub
The ShouldToggle
parameter indicates whether the macro deactivated this window the last time. The variable ToolWindowsAreVisible
is a toggle which controls de/activation.
Using the above two routines, the macro to toggle the tool windows is coded as:
Sub Toggle_Tool_Windows()
ToggleToolWindow(Constants.vsWindowKindClassView, ClassViewWasOpen)
ToggleToolWindow(Constants.vsWindowKindCommandWindow, CommandWindowWasOpen)
ToggleToolWindow(Constants.vsWindowKindMacroExplorer, MacroExplorerWasOpen)
ToggleToolWindow(Constants.vsWindowKindObjectBrowser, ObjectBrowserWasOpen)
ToggleToolWindow(Constants.vsWindowKindOutput, OutputWasOpen)
ToggleToolWindow(Constants.vsWindowKindProperties, PropertiesWasOpen)
ToggleToolWindow(Constants.vsWindowKindSolutionExplorer, SolutionExplorerWasOpen)
ToggleToolWindow(Constants.vsWindowKindTaskList, TaskListWasOpen)
ToggleToolWindow(Constants.vsWindowKindToolbox, ToolboxWasOpen)
ToolWindowsAreVisible = (Not ToolWindowsAreVisible)
End Sub
Finally, the toggles that determine the state of the tool windows are defined as:
Dim ToolWindowsAreVisible As Boolean = True
Dim ClassViewWasOpen As Boolean
Dim CommandWindowWasOpen As Boolean
Dim MacroExplorerWasOpen As Boolean
Dim ObjectBrowserWasOpen As Boolean
Dim OutputWasOpen As Boolean
Dim PropertiesWasOpen As Boolean
Dim SolutionExplorerWasOpen As Boolean
Dim TaskListWasOpen As Boolean
Dim ToolboxWasOpen As Boolean
You can define additional tool windows by defining a toggle for the window, and calling ToggleToolWindow
in Toggle_Tool_Windows
.
Hope you find this article helpful.
History
3/9/2003 Original version 1.0 by Behnam Nikbakht