I have a fairly simple macro which updates a copyright header comment
while saving .cs source files if the current year is more recent than
the year in the copyright header. The macro is run from the
DocumentSaved event, and everything works pretty well.
The only annoying problem is restoring the buffer/window location so
that nothing appears to have changed in the window. Currently, if the
file is saved, the macro is run, and I restore the original point
with...
activeEditPoint = Document.TextSelection.ActivePoint.CreateEditPoint
anchorEditPoint = Document.TextSelection.ActivePoint.CreateEditPoint
'... do work here ...
Document.TextSelection.MoveToPoint(anchorEditPoint)
Document.TextSelection.MoveToPoint(activeEditPoint)
The macro prompts to confirm I want to make the change, makes the
change, and then restores the location correctly. The problem is that
it doesn't scroll the window to the position it was originally at in
relation to the edit point.
E.g., before macro runs the visible line numbers are:
-----------------
100
101 x <- (current line position)
102
103
104
105
-----------------
After the macro runs the visible lines are:
-----------------
97
98
99
100
101 x <- (current line position)
102
-----------------
Any tips or pointers?
Thanks,
Glenn
Glenn - 11 Jan 2007 19:52 GMT
[Is there a better newsgroup to post a question like the following?]
I have a fairly simple macro which updates a copyright header comment
while saving .cs source files if the current year is more recent than
the year in the copyright header. The macro is run from the
DocumentSaved event, and everything works pretty well.
The only annoying problem is restoring the buffer/window location so
that nothing appears to have changed in the window. Currently, if the
file is saved, the macro is run, and I restore the original point
with...
activeEditPoint = Document.TextSelection.ActivePoint.CreateEditPoint
anchorEditPoint = Document.TextSelection.ActivePoint.CreateEditPoint
'... do work here ...
Document.TextSelection.MoveToPoint(anchorEditPoint)
Document.TextSelection.MoveToPoint(activeEditPoint)
The macro prompts to confirm I want to make the change, makes the
change, and then restores the location correctly. The problem is that
it doesn't scroll the window to the position it was originally at in
relation to the edit point.
E.g., before macro runs the visible line numbers are:
-----------------
100
101 x <- (current line position)
102
103
104
105
-----------------
After the macro runs the visible lines are:
-----------------
97
98
99
100
101 x <- (current line position)
102
-----------------
Any tips or pointers?
Thanks,
Glenn
Glenn - 01 Feb 2007 17:13 GMT
[Replying to my own post after I found a way to do this:]
Here's how to restore the window 'view' as it was before:
textWindow = DTE.ActiveWindow.Object
pane = textWindow.ActivePane
paneStartPoint = pane.StartPoint
' ...
paneStartPoint.TryToShow(vsPaneShowHow.vsPaneShowTop)
> [Is there a better newsgroup to post a question like the following?]
>
[quoted text clipped - 45 lines]
> Thanks,
> Glenn