I often run into situations where I’d like to undo all the work I’ve done in a file. Some applications refer to this as Revert-to-saved. Visual Studio 2005 does not seem to have a function to do this. So, I’ve written a couple macros to do this.
The first, RevertToSaved simply calls Undo until it can’t undo anymore. This is much faster than holding the Ctrl-Z key down, and keeps your undo buffer.
While DTE.ActiveDocument.Undo() = True
The second, RevertToSaved2, is a little more brute force–it simply closes the current project item and reopens it, attempting to return to the same cursor location.
Dim projectItem As EnvDTE.ProjectItem = DTE.ActiveDocument.ProjectItem
If Not projectItem Is Nothing Then
Dim activeLine As Integer = DTE.ActiveDocument.Selection.ActivePoint.Line
Dim lineCharOffset As Integer = DTE.ActiveDocument.Selection.ActivePoint.LineCharOffset
Dim window As EnvDTE.Window = projectItem.Open()
If Not window Is Nothing Then