Sometimes you need to comment out blocks of code, but you don't necessarily want to comment out each entire line. As I was performing this very chore today, I thought to myself, "Hey, wouldn't it be nice if there was a keyboard shortcut I could use to comment a selected block of text using comment delimiters?" Then I thought to myself, "I already know how to create macros thanks to Philip's great blogs on macros. Why don't I try writing my own?" So I did. Source code within.
See Philip's great blogs for instructions on how to install macros.
Imports SystemImports EnvDTEImports EnvDTE80Imports System.DiagnosticsPublic Module SolutionExplorer Sub CollapseNodes() ' 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) ' 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 windows 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 Sub ExpandNodes() ' 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) ' Collapse each project node Dim UIHItem As UIHierarchyItem For Each UIHItem In UIHSolutionRootNode.UIHierarchyItems UIHItem.UIHierarchyItems.Expanded = True Next ' Select the solution node, or else when you click ' on the solution windows 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 SubEnd Module
Remember Me
a@href@title, i, strike, u
Copyright © 2003-2008 Falafel Software Inc.
Subscribe to Falafel Blogs
The opinions expressed herein are Falafel's employees own personal opinions and do not represent Falafel Software's view in any way in case they go bananas!