Thursday, January 18, 2007
Wednesday, January 17, 2007
VS macro for collapse of nodes, incl. projects
This is a combination of two sources:
- Edwin Evans posting to "The code project" :
- Additional "CollapseNode" method provided by Odd Helge Gravalid
Sub CollapseNode(ByRef item As UIHierarchyItem)
Dim subitem As UIHierarchyItem
For Each subitem In item.UIHierarchyItems
'No way of knowing type of the UIHierarchyItems, exclude non-Expandable ones on name to reduce Solution Explorer Tree redraw madness
Dim isValid As Boolean
isValid = subitem.Name.LastIndexOf(".cs").Equals(-1)
isValid = isValid And subitem.Name.LastIndexOf(".sql").Equals(-1)
isValid = isValid And subitem.Name.LastIndexOf(".bcp").Equals(-1)
isValid = isValid And subitem.Name.LastIndexOf(".resx").Equals(-1)
isValid = isValid And subitem.Name.LastIndexOf(".ico").Equals(-1)
isValid = isValid And subitem.Name.LastIndexOf(".jpg").Equals(-1)
isValid = isValid And subitem.Name.LastIndexOf(".bmp").Equals(-1)
isValid = isValid And subitem.Name.LastIndexOf(".xml").Equals(-1)
isValid = isValid And subitem.Name.LastIndexOf(".wsdl").Equals(-1)
isValid = isValid And subitem.Name.LastIndexOf(".xsd").Equals(-1)
isValid = isValid And subitem.Name.LastIndexOf(".asmx").Equals(-1)
isValid = isValid And subitem.Name.LastIndexOf(".aspx").Equals(-1)
isValid = isValid And subitem.Name.LastIndexOf(".asax").Equals(-1)
isValid = isValid And subitem.Name.LastIndexOf(".xslt").Equals(-1)
isValid = isValid And subitem.Name.LastIndexOf(".localrunconfig").Equals(-1)
isValid = isValid And subitem.Name.LastIndexOf(".vsmdi").Equals(-1)
isValid = isValid And subitem.Name.LastIndexOf(".config").Equals(-1)
'isValid = isValid And subitem.Name.LastIndexOf("Properties").Equals(-1)
'isValid = isValid And subitem.Name.LastIndexOf("References").Equals(-1)
If (isValid And item.UIHierarchyItems.Expanded) Then
CollapseNode(subitem)
subitem.UIHierarchyItems.Expanded = False
'Fix for buggy Visual Studio on Projects located in folder inside a folder
If (subitem.UIHierarchyItems.Expanded.Equals(True)) Then
Dim UIHSolutionExplorer As UIHierarchy
UIHSolutionExplorer = DTE.Windows.Item(Constants.vsext_wk_SProjectWindow).Object()
subitem.Select(vsUISelectionType.vsUISelectionTypeSelect)
UIHSolutionExplorer.DoDefaultAction()
End If
End If
Next
End Sub
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
Return
End If
' Get the top node (the name of the solution)
Dim UIHSolutionRootNode As UIHierarchyItem
UIHSolutionRootNode = UIHSolutionExplorer.UIHierarchyItems.Item(1)
CollapseNode(UIHSolutionRootNode)
' 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
Subscribe to:
Posts (Atom)