gpt4 book ai didi

visual-studio - 宏在解决方案 Visual Studio 2010 中全部折叠

转载 作者:行者123 更新时间:2023-12-04 22:52:11 24 4
gpt4 key购买 nike

我在网上找到了在 vs2005 和 vs2008 中对我有用的 CollapseAll 宏。但是,这在vs2010中有效。看起来它只折叠顶部节点而不折叠任何可以扩展的子节点?有任何想法吗?

谢谢,
杆。

    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

最佳答案

(是的,我知道您将另一个答案标记为已接受,但从技术上讲,这并没有回答您的编码问题,尽管它确实给了您答案。然而,这正是您最初提出的问题。)

实际上,我认为这在任何版本的 Visual Studio 中都行不通,因为 Collapse 函数中的逻辑是错误的。与项目中的初始循环相同(我不知道为什么你只是没有将解决方案节点传递给折叠函数......)

具体来说,您在深入研究子项之前检查它是否已展开,因此如果文件夹折叠但其子项已展开,则不会进入内部并折叠子项,因为您的检查会导致跳过该文件夹。只需检查计数。毕竟,您确实想要深入研究一切以崩溃。

这是我使用您的版本作为起点创建的版本。我还添加了重新选择所选项目(如果有)的功能。我喜欢选择我正在处理的项目。如果我想让所有东西都折叠起来,我要么选择根节点,要么取消选择所有东西,在这两种情况下,它都会选择根(解决方案节点)。

我还添加了 MultiBeep 功能以提供声音反馈,因为我不喜欢消息框。 2 声表示成功,3 声表示您没有打开解决方案。

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

哈,

标记

关于visual-studio - 宏在解决方案 Visual Studio 2010 中全部折叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2884891/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com