Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / February 2007

Tip: Looking for answers? Try searching our database.

Restore exact buffer window position after manipulating with a macro?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
glenn@glenncarr.com - 09 Jan 2007 21:38 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.