Posts VB 2005 Snippet Annoyance - A solution...
Post
Cancel

VB 2005 Snippet Annoyance - A solution...

With VB's snippet feature, every time you add a new snippet the coloring stays around until you close the file and re-open it.  This can quickly lead to a lot of visual clutter while your developing if you use snippets a lot.  And why shouldn't you leverage such a feature?

Well, during the beta I asked about whether this would be resolved in some manner and it was a bit late in the schedule.  So I set out to figure out a possible work around.  The work around consists of a simple macro that will save your current cursor location, save/close the file, open the file and return the cursor to it's current location.  You can configure the macro to work as a tool bar button and/or a keyboard combination. 

Here's what I'm referring to (visually):

Here's the macro.

Sub ReloadFile()

 

  ' Make a note of the current file.

  Dim file As String = DTE.ActiveDocument.FullName

 

  ' Make a note of the current cursor position.

  Dim ep As EditPoint = CType(DTE.ActiveDocument.Selection, TextSelection).ActivePoint.CreateEditPoint

 

<P class=MsoNormal style="MARGIN: 0in 0in 0pt">  ‘ Save the current file.</P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt">  DTE.ActiveDocument.Save()</P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"> </P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt">  ’ Close the current file.</P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt">  DTE.ActiveDocument.Close()</P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"> </P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt">  ’ Open the current file.</P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt">  DTE.ItemOperations.OpenFile(file)</P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"> </P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt">  ’ Move cursor to the previously saved position.</P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt">  CType(DTE.ActiveDocument.Selection, TextSelection).MoveToLineAndOffset(ep.Line, ep.LineCharOffset)</P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"> </P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt">End Sub</P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"> </P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt">Enjoy!</P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt"> </P> <P class=MsoNormal style="MARGIN: 0in 0in 0pt">Note:  For a step by step walk through on creating and consuming macros, see here.</P>

This post is licensed under CC BY 4.0 by the author.