适用于 Visual Studio .NET 的折叠全部宏






4.82/5 (14投票s)
2002 年 9 月 21 日

147777
一个简单的宏,
引言
Visual Studio .NET 具有一个很酷的功能,它可以自动将解决方案资源管理器与打开的文件同步。 然而,一个问题是,如果您有大量的项目,分支的数量很快就会失控——您会因为过多的分支而看不到树木,可以说。这是一个非常简单的宏,您可以用来折叠解决方案资源管理器中的所有项目节点。
宏代码
Sub CollapseAll()
' Get the the Solution Explorer tree
Dim UIHSolutionExplorer As UIHierarchy
UIHSolutionExplorer = DTE.Windows.Item( _
Constants.vsext_wk_SProjectWindow).Object()
' Check if there is any open solution
If (UIHSolutionExplorer.UIHierarchyItems.Count = 0) Then
' MsgBox("Nothing to collapse. You must have an open solution.")
Return
End If
' Get the top node (the name of the solution)
Dim UIHSolutionRootNode As UIHierarchyItem
UIHSolutionRootNode = UIHSolutionExplorer.UIHierarchyItems.Item(1)
' Collapse each project node
Dim UIHItem As UIHierarchyItem
For Each UIHItem In UIHSolutionRootNode.UIHierarchyItems
UIHItem.UIHierarchyItems.Expanded = False
Next
' Select the solution node, or else when you click
' on the solution window
' scrollbar, it will synchronize the open document
' with the tree and pop
' out the corresponding node which is probably not what you want.
UIHSolutionRootNode.Select(vsUISelectionType.vsUISelectionTypeSelect)
End Sub