locked
Show Save Changes Dialogs RRS feed

  • Question

  • Hi i'm searching a way of showing the same dialog VS shows when you try to close the IDE with unsaved files.


    I've spent few hours looking at all the Microsoft.VisualStudio.Shell.Interop (and friends) namespace to find a class for this purpose, but i only found this, but i'm afraid that is not what i was looking for.

    I need to show the classic Yes|No|Cancel dialog, and i really would like to reuse the built in one, not reinventing the wheel...

    Can somebody please point me in the right direction?

    P.S. VS Version is VS 2013.

    Thanks, Max

    Friday, September 20, 2013 6:29 PM

Answers

  • Hello,

    Based on my understanding, you want to add and display the built-in Save Dialog Box to your project in Visual Studio 2013.

    As far as I know, the built-in Save Dialog Box in Visual Studio is based on the RDT(Running Document Table).

    Any items that you expect to see in the Save Changes dialog box upon exiting the application should have records in the RDT. The RDT coordinates which documents are saved and whether the user is prompted about a save operation using the values specified in the Flags entry for each document. For more information on the RDT flags, see the _VSRDTFLAGS enumeration.

    Based on the information above,I suggest you to define your custom Save Dialog Box rather than resuse the built-in one.

    In addition,here is one related link about Save Dialog Box below:

    How to Display the Open and Save As Dialog Boxes

    Best Regards,

    Jane.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 23, 2013 11:58 AM
  • You don't show the dialog yourself, you register your documents to the IDE, and the IDE will call you back and eventually display dialogs for the user, this way the UI is consistent for all types of documents.

    So, you register your documents using the Running Document Table, with a method like RegisterAndLockDocument: http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivsrunningdocumenttable.registerandlockdocument.aspx

    When you call that method, you will pass an object in the punkDocData parameter. This object will have to implement interfaces that the IDE knows, specifically, IVsPersistDocData/IVsPersistDocData2 : http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivspersistdocdata.aspx

    Now, when the end user presses Close, the IDE will call your IsDocDataDirty implementation, if it's dirty, then it will determine what's the display name of your document and show the famous dialog box.

    Note you don't always have to implement IVsPersistDocData yourself, it may be implemented by some other packages for example.


    Simon Mourier

    Monday, September 23, 2013 3:30 PM
  • Thank you all for your replies, but i'm not satisfied from answer 1

    Based on the information above,I suggest you to define your custom Save Dialog Box rather than resuse the built-in one.

    The creation of a new custom save dialog will result in "strange" user experience and it would be too complicated, the second answer does not help me, because I haven't created a custom editor and then I do not know how to implement the interface IVsPersistDocData2.

    So after trying some tricks I came out with the following:

    1) Register for the DTE..Events.DTEEvents.OnBeginShutdown
    2) Invoke the command FIle.Exit through DTE object

    This way I get file dialogs for free (without code so no bugs ;) and the UX will remain coherent) and my code will handle IDE closing via the OnBeginShutdown event.

    Does this make sense for you?

    Thank for your time
    Massimiliano

    Monday, September 30, 2013 9:11 PM

All replies

  • Hello,

    Based on my understanding, you want to add and display the built-in Save Dialog Box to your project in Visual Studio 2013.

    As far as I know, the built-in Save Dialog Box in Visual Studio is based on the RDT(Running Document Table).

    Any items that you expect to see in the Save Changes dialog box upon exiting the application should have records in the RDT. The RDT coordinates which documents are saved and whether the user is prompted about a save operation using the values specified in the Flags entry for each document. For more information on the RDT flags, see the _VSRDTFLAGS enumeration.

    Based on the information above,I suggest you to define your custom Save Dialog Box rather than resuse the built-in one.

    In addition,here is one related link about Save Dialog Box below:

    How to Display the Open and Save As Dialog Boxes

    Best Regards,

    Jane.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 23, 2013 11:58 AM
  • You don't show the dialog yourself, you register your documents to the IDE, and the IDE will call you back and eventually display dialogs for the user, this way the UI is consistent for all types of documents.

    So, you register your documents using the Running Document Table, with a method like RegisterAndLockDocument: http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivsrunningdocumenttable.registerandlockdocument.aspx

    When you call that method, you will pass an object in the punkDocData parameter. This object will have to implement interfaces that the IDE knows, specifically, IVsPersistDocData/IVsPersistDocData2 : http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivspersistdocdata.aspx

    Now, when the end user presses Close, the IDE will call your IsDocDataDirty implementation, if it's dirty, then it will determine what's the display name of your document and show the famous dialog box.

    Note you don't always have to implement IVsPersistDocData yourself, it may be implemented by some other packages for example.


    Simon Mourier

    Monday, September 23, 2013 3:30 PM
  • Thank you all for your replies, but i'm not satisfied from answer 1

    Based on the information above,I suggest you to define your custom Save Dialog Box rather than resuse the built-in one.

    The creation of a new custom save dialog will result in "strange" user experience and it would be too complicated, the second answer does not help me, because I haven't created a custom editor and then I do not know how to implement the interface IVsPersistDocData2.

    So after trying some tricks I came out with the following:

    1) Register for the DTE..Events.DTEEvents.OnBeginShutdown
    2) Invoke the command FIle.Exit through DTE object

    This way I get file dialogs for free (without code so no bugs ;) and the UX will remain coherent) and my code will handle IDE closing via the OnBeginShutdown event.

    Does this make sense for you?

    Thank for your time
    Massimiliano

    Monday, September 30, 2013 9:11 PM
  • Hello,

    Thanks for sharing your solutions with us here.

    Best Regards,

    Jane.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, October 1, 2013 4:50 AM
  • I never talked about an editor in my answer. IVsPersistDocData2 is not specifically related to an editor, it's a "document oriented" interface, and it's the official way of making sure Visual Studio works gracefully with documents you own.

    I don't understand how your solution is supposed to work, so no, it doesn't really make sense, but that's fine if that suits you. Well, I hope so... as your assertion about "no code no bug" maybe true in other environment, but the Visual Studio context, this is not always true as your extension or package does not live alone, it's very easy to mess with Visual Studio itself of with the dozens of extensions and packages that run in the same process as you. Just google a bit about "devenv /SafeMode".


    Simon Mourier

    Tuesday, October 1, 2013 6:05 AM
  • Hi Simon

    Thank you for your reply, the extension was this and i was searching for a way to gracefully close visual studio showing all necessary stuff related to unsaved things.

    No code no bugs is a "code translation" for this italian proverb.



    Wednesday, October 2, 2013 8:52 PM