Here is the code. The code is pretty simple and there minimal error
checking.
It was cobbled together quickly so it could probably be improved, but
it seems to work. It will only work if called while in a text
document.
I have a hotkey assigned to execute the GotoDefinition sub. That sub
in turn pushes a marker onto a stack (which is a class defined below).
It then executes the IDE's Edit.GoToDefinition command.
Then another hotkey executes the PopMarker sub which retrieves the
bookmark from the stack and jumps to it.
Sub GotoDefinition()
PushMarker()
DTE.ExecuteCommand("Edit.GoToDefinition")
End Sub
Sub PushMarker()
Dim txtDoc As TextDocument =
CType(DTE.ActiveDocument.Object("TextDocument"), TextDocument)
Dim edPt As EditPoint = txtDoc.StartPoint.CreateEditPoint
Dim sel As TextSelection = CType(DTE.ActiveWindow.Selection,
TextSelection)
edPt.MoveToLineAndOffset(sel.CurrentLine, sel.CurrentColumn)
edPt.SetBookmark()
MarkerStack.Push(New Marker(edPt, sel.CurrentLine,
sel.CurrentColumn))
End Sub
Public Sub PopMarker()
Try
Dim m As Marker = MarkerStack.Pop
If Not m Is Nothing Then
Dim txtDoc As TextDocument =
CType(DTE.ActiveDocument.Object("TextDocument"), TextDocument)
Dim objSel As TextSelection =
CType(DTE.ActiveDocument.Selection, TextSelection)
Dim edPt As EditPoint = m.ep
If edPt.TryToShow(vsPaneShowHow.vsPaneShowCentered) Then
edPt.ClearBookmark()
objSel.MoveToLineAndOffset(m.line, m.col)
End If
End If
Catch ex As Exception
Debug.WriteLine(ex.Message & ": " & ex.StackTrace)
End Try
End Sub
End Module
Public Class MarkerStack
Private Shared MarkerS As New Stack
Shared Sub Push(ByVal m As Marker)
MarkerS.Push(m)
End Sub
Shared Function Pop() As Marker
If MarkerS.Count > 0 Then
Return DirectCast(MarkerS.Pop, Marker)
Else
Return Nothing
End If
End Function
Shared Sub ClearStack()
MarkerS.Clear()
End Sub
End Class
Public Class Marker
Public Sub New(ByVal e As EditPoint, ByVal l As Integer, ByVal c As
Integer)
ep = e
line = l
col = c
End Sub
Public ep As EditPoint
Public line As Integer
Public col As Integer
End Class