BeforeSave event or similar?

I want to have the option to modify a document right before it's saved by the text editor. Is there an event I can use for this I want the changes I make to be saved during the pending save operation.

In the event of a Save All command, I would want one BeforeSave notification for each modified document as it's about to be saved.



Answer this question

BeforeSave event or similar?

  • Karthik R

    Right now my plugin removes trailing whitespace from project files when they are opened. I would prefer it remove them when the file is saved. :)
  • Michael O. Schoneman

    I am also looking for this solution. If no before save notification is there, it would be better to add a delegate while save is invoked, like DocumentSavedEventHandler..

    Can anyone give pointer where I can find the IDE extensibility doc

    Thanks



  • tfinniga

    There doesn't appear to be an automation event like the DocumentEvent.DocumentOpening method, to receive a notification before a document is saved.

    However, if you have access to the Visual Studio SDK, you could leverage IVsRunningDocTableEvents3.OnBeforeSave. The VSCOOKIE passed to OnBeforeSave can be passed to IVsRunningDocumentTable.GetDocumentInfo, to get the filename (pbstrMkDocument), IVsHierarchy and itemID, and IUnknown of the DocData object.

    I don't know what sort of changes you're looking to make, but that DocData object also implements IVsTextLines which you can use to create an EditPoint to insert additional text into the buffer.

    Sincerely,



  • BeforeSave event or similar?