Macro everything in visual studio 2010

I found the CollapseAll macro online that worked for me in vs2005 and vs2008. However, this half works in vs2010. It seems that he only collapses the top nodes, and not some trays that can be expanded? any ideas?

Thanks, core.

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) UIHSolutionRootNode.DTE.SuppressUI = True ' Collapse each project node Dim UIHItem As UIHierarchyItem For Each UIHItem In UIHSolutionRootNode.UIHierarchyItems 'UIHItem.UIHierarchyItems.Expanded = False If UIHItem.UIHierarchyItems.Expanded Then Collapse(UIHItem) End If 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) UIHSolutionRootNode.DTE.SuppressUI = False End Sub Private Sub Collapse(ByVal item As UIHierarchyItem) For Each eitem As UIHierarchyItem In item.UIHierarchyItems If eitem.UIHierarchyItems.Expanded AndAlso eitem.UIHierarchyItems.Count > 0 Then Collapse(eitem) End If Next item.UIHierarchyItems.Expanded = False End Sub End Module 
+4
source share
3 answers

(Yes, I know that you marked the other answer as accepted, but technically this did not answer your question with the encoding, although it gave you an answer. This, however, is what you originally asked.)

Actually, I don’t think it would work in any version of Visual Studio, because the logic in your Collapse function is wrong. Same thing with the initial loop in the project (which I'm not sure why you just didn't pass the node solution to the collapse function anyway ...)

In particular, you check to see if it has expanded before delving into the children, so if the folder crashes but its children are expanded, it will not go inside and will not hide the children, since the check will skip it. Just check the bill. In the end, you want to delve into everything in order to collapse.

Here is the version that I created from your point of view as a starting point. I also added the ability to re-select the selected item, if any. I like to have the item I'm working on. And if I want everything to crash, I either select the root node or deselect it, in both cases it selects the root (node ​​solution).

I also added a MultiBeep function for audible feedback, since I'm not a fan of messages. 2 beeps are successful, 3 means you do not have an open solution.

 Sub CollapseSolutionTree() ' Get the the Solution Explorer tree Dim SolutionExplorer As UIHierarchy = DTE.Windows.Item(Constants.vsext_wk_SProjectWindow).Object() ' Check if there is any open solution If (SolutionExplorer.UIHierarchyItems.Count = 0) Then MultiBeep(3) Return End If ' Get the selected node (if any) Dim SelectedNode As UIHierarchyItem Try SelectedNode = SolutionExplorer.SelectedItems(0) Catch End Try ' Get the top node (the name of the solution) Dim SolutionNode As UIHierarchyItem = SolutionExplorer.UIHierarchyItems.Item(1) SolutionNode.DTE.SuppressUI = True ' Collapse the solution tree CollapseSolutionExplorerNode(SolutionNode) ' If there was a selected item before the command, re-select it. Otherwise select the solution node. If SelectedNode isnot Nothing SelectedNode.Select(vsUISelectionType.vsUISelectionTypeSelect) Else SolutionNode.Select(vsUISelectionType.vsUISelectionTypeSelect) End If SolutionNode.DTE.SuppressUI = False MultiBeep(2) End Sub Private Sub CollapseSolutionExplorerNode(ByVal Folder As UIHierarchyItem) For Each Subfolder As UIHierarchyItem In Folder.UIHierarchyItems If Subfolder.UIHierarchyItems.Count Then CollapseSolutionExplorerNode(Subfolder) Next Folder.UIHierarchyItems.Expanded = False End Sub Private Sub MultiBeep(Count As Integer, Optional Spacing As Integer = 100) Beep For I = 2 to Count System.Threading.Thread.CurrentThread.Sleep(Spacing) Beep Next End Sub 

NTN

Mark

+8
source

This feature is part of the free Microsoft Productivity Power Tools extension for Visual Studio 11 and is likely to be found as a standard feature in the next version of Visual Studio.

0
source

Source: https://habr.com/ru/post/1310558/


All Articles