Prevent closing the Application if file not saved
We have an application based on Eclipse-RCP. The problem I am trying to fix is as follows: Say the user has an unsaved model file, and tries to close the application. The application rightly prompts the user for options to Save the file, Ignore it, or Cancel closing the application. Ignore and cancel are no-brainers. If the user decides to save the file, there is another dialog box that gives the user an option to either save the file or cancel the save (its a custom editor, similar to a Save-As dialog).
Now, the question: How do I prevent killing the application when the user selects "Yes" in the first prompt, but cancel开发者_C百科s the save in the second? I thought of looking up the base class of the application, but couldn't find it. Or should I be looking at the custom-editor for the model file?
Thanks in advance, any help is appreciated...
If you are in RCP you have the luxury of returning false from WorkbenchAdvisor.preShutdown()
Let a workbench part holding the model implement org.eclipse.ui.ISaveablePart2
interface meant for cases like yours.
精彩评论