Simulating the "View One Procedure" feature of the VB6 IDE. Remember the feature in VB6 where you could view one procedure at a time rather than all procedures with a line separating them? When you have very large procedures, this is still a useful feature. The following code will produce the same effect when executed as a macro or in an add-in. The code is currently set up to be run as a macro. You can put it in an add-in by simply changing the references to "DTE" to the applicationObject variable in the add-in.
| Public Sub HideAllButCurrentMethod() ' Collapses all code preceding and following ' procedure where cursor resides. This emulates ' the VB6 One Function View Feature. Try Dim ts As TextSelection = DTE.ActiveWindow.Selection ' where caret was Dim tsSave As EditPoint = ts.ActivePoint.CreateEditPoint ' where caret is currently as we move Dim ep As EditPoint = ts.ActivePoint.CreateEditPoint Dim i As Integer Dim j As Integer Dim k As Integer DTE.ExecuteCommand("Edit.StopOutlining") '' determine #chars from start of doc to line '' before start of current proc '' move to stare of current proc ep.MoveToPoint(ep.CodeElement(EnvDTE.vsCMElement. vsCMElementFunction).GetStartPoint(vsCMPart.vsCMPartWhole)) ep.LineUp() i = ep.AbsoluteCharOffset ' number of lines to hide at top Dim doc As TextDocument = oVB.ActiveDocument.Object Dim epStart As EditPoint = doc.StartPoint.CreateEditPoint epStart.OutlineSection(i) '' Move ep back in function and outline from end '' of proc to end of doc. ' move back to editpoint ts.MoveToPoint(tsSave, False) ep = ts.ActivePoint.CreateEditPoint ep.MoveToPoint(ep.CodeElement(EnvDTE.vsCMElement. vsCMElementFunction).GetEndPoint(vsCMPart.vsCMPartWhole)) ep.LineDown() j = ep.AbsoluteCharOffset ' #chars to end of proc Dim epEOD As EditPoint = doc.EndPoint.CreateEditPoint k = epEOD.AbsoluteCharOffset ep.OutlineSection(k - j) ts.MoveToPoint(tsSave) Catch ex As System.Exception End Try End Sub |
| Public Sub RedoOutlining() Try DTE.ExecuteCommand("Edit.StopOutlining") DTE.ExecuteCommand("Edit.StartAutomaticOutlining") DTE.ExecuteCommand("Edit.ToggleAllOutlining") Catch ex As System.Exception End Try End Sub |