IMZRH的日志

努力成为一个有用的人

导航

VS中折叠/展开所有项目的宏

Posted on 2010-05-12 16:00  张荣华  阅读(3627)  评论(1编辑  收藏  举报

有些时候我们需要在解决方案管理器中将所有的项目都折叠或是展开,当解决方案中项目比较少时我们可以手工做,但当项目比较多时还手工处理就比较费劲了,好在我们有宏,完成可以利用宏代码来自动完成这些繁琐而重复的操作。 下面就是我写的一个用来折叠/展开所有项目的宏代码:

 

Collapse/ExpandMacro
Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module CollapseExpandAllProject

'-----------------------------------------------
'Collapse All projects
'Author:ZhangRongHua
'Date:2010-05-12
'-----------------------------------------------
Public Sub CollapseAllProject()
lastSlashIndex
= DTE.Solution.FullName.LastIndexOf("\") + 1 'Get the last slash index .
solutionNameWithExtension = DTE.Solution.FullName.Substring(lastSlashIndex) ' Get solution name with extension.
solutionName = solutionNameWithExtension.ToString().Substring(0, solutionNameWithExtension.ToString().Length - 4) ' Get the solution name without extension .
count = 0

For Each curProject As EnvDTE.Project In DTE.Solution.Projects
Try
DTE.ActiveWindow.Object.GetItem(solutionName
+ "\" + curProject.Name).UIHierarchyItems.Expanded = False
count
= count + 1
Catch ex As ArgumentException
Continue For
End Try
Next curProject

End Sub

'-----------------------------------------------
'Expand All projects
'Author:ZhangRongHua
'Date:2010-05-12
'-----------------------------------------------
Public Sub ExpandAllProject()
lastSlashIndex
= DTE.Solution.FullName.LastIndexOf("\") + 1 'Get the last slash index .
solutionNameWithExtension = DTE.Solution.FullName.Substring(lastSlashIndex) ' Get solution name with extension.
solutionName = solutionNameWithExtension.ToString().Substring(0, solutionNameWithExtension.ToString().Length - 4) ' Get the solution name without extension .
count = 0

For Each curProject As EnvDTE.Project In DTE.Solution.Projects
Try
DTE.ActiveWindow.Object.GetItem(solutionName
+ "\" + curProject.Name).UIHierarchyItems.Expanded = True
count
= count + 1
Catch ex As ArgumentException
Continue For
End Try
Next curProject

End Sub

End Module

 

 

关于一些其它有意思的宏你可以在这里找到:

利用宏自动在类文件中添加注释信息

让多线程调试更简单的宏代码---FreezeThawThreads