Index: Eclipse UI/org/eclipse/ui/internal/EditorManager.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/EditorManager.java,v retrieving revision 1.67 diff -u -r1.67 EditorManager.java --- Eclipse UI/org/eclipse/ui/internal/EditorManager.java 11 Mar 2005 21:10:17 -0000 1.67 +++ Eclipse UI/org/eclipse/ui/internal/EditorManager.java 14 Mar 2005 16:13:47 -0000 @@ -17,6 +17,7 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.List; +import java.util.ListIterator; import java.util.Map; import org.eclipse.core.runtime.CoreException; @@ -68,6 +69,7 @@ import org.eclipse.ui.IPersistableElement; import org.eclipse.ui.IReusableEditor; import org.eclipse.ui.ISaveablePart; +import org.eclipse.ui.ISaveablePart2; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPart2; @@ -1276,6 +1278,23 @@ public static boolean saveAll(List dirtyEditors, boolean confirm, final IWorkbenchWindow window) { if (confirm) { + // process all editors that implement ISaveablePart2 + // these parts are removed from the list after saving them. + ListIterator listIterator = dirtyEditors.listIterator(); + while (listIterator.hasNext()) { + IEditorPart part = (IEditorPart) listIterator.next(); + if (part instanceof ISaveablePart2) { + window.getActivePage().bringToTop(part); + if (!SaveableHelper.savePart(part, part, window, true)) + return false; + listIterator.remove(); + } + } + + // If the editor list is empty return. + if (dirtyEditors.isEmpty()) + return true; + // Convert the list into an element collection. AdaptableList input = new AdaptableList(dirtyEditors); @@ -1298,7 +1317,7 @@ return false; // If the editor list is empty return. - if (dirtyEditors.size() == 0) + if (dirtyEditors.isEmpty()) return true; } Index: Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java,v retrieving revision 1.2 diff -u -r1.2 SaveableHelper.java --- Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java 7 Sep 2004 20:35:15 -0000 1.2 +++ Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java 14 Mar 2005 16:13:47 -0000 @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 + * Copyright (c) 2004, 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * + * http://www.eclipse.org/legal/epl-v10.html + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -20,7 +20,9 @@ import org.eclipse.jface.operation.IRunnableContext; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.window.ApplicationWindow; +import org.eclipse.osgi.util.NLS; import org.eclipse.ui.ISaveablePart; +import org.eclipse.ui.ISaveablePart2; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; @@ -58,25 +60,30 @@ // If confirmation is required .. if (confirm) { int choice = AutomatedResponse; - if (choice == -1) { - String message = WorkbenchMessages.format("EditorManager.saveChangesQuestion", new Object[] { part.getTitle()}); //$NON-NLS-1$ - // Show a dialog. - String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; - MessageDialog d = new MessageDialog( - window.getShell(), WorkbenchMessages.getString("Save_Resource"), //$NON-NLS-1$ - null, message, MessageDialog.QUESTION, buttons, 0); - choice = d.open(); + if (choice == -1) { + if (saveable instanceof ISaveablePart2) { + choice = ((ISaveablePart2)saveable).promptToSaveOnClose(); + } + if (choice == -1 || choice == ISaveablePart2.DEFAULT) { + String message = NLS.bind(WorkbenchMessages.EditorManager_saveChangesQuestion, part.getTitle()); + // Show a dialog. + String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }; + MessageDialog d = new MessageDialog( + window.getShell(), WorkbenchMessages.Save_Resource, + null, message, MessageDialog.QUESTION, buttons, 0); + choice = d.open(); + } } // Branch on the user choice. // The choice id is based on the order of button labels above. switch (choice) { - case 0 : //yes + case ISaveablePart2.YES : //yes break; - case 1 : //no + case ISaveablePart2.NO : //no return true; default : - case 2 : //cancel + case ISaveablePart2.CANCEL : //cancel return false; } } @@ -90,7 +97,7 @@ }; // Do the save. - return runProgressMonitorOperation(WorkbenchMessages.getString("Save"), progressOp,window); //$NON-NLS-1$ + return runProgressMonitorOperation(WorkbenchMessages.Save, progressOp,window); } /** * Runs a progress monitor operation. @@ -114,11 +121,10 @@ try { ctx.run(false, true, runnable); } catch (InvocationTargetException e) { - String title = WorkbenchMessages.format("EditorManager.operationFailed", new Object[] { opName }); //$NON-NLS-1$ + String title = NLS.bind(WorkbenchMessages.EditorManager_operationFailed, opName ); Throwable targetExc = e.getTargetException(); WorkbenchPlugin.log(title, new Status(IStatus.WARNING, PlatformUI.PLUGIN_ID, 0, title, targetExc)); - MessageDialog.openError(window.getShell(), WorkbenchMessages.getString("Error"), //$NON-NLS-1$ - title + ':' + targetExc.getMessage()); + MessageDialog.openError(window.getShell(), WorkbenchMessages.Error, title + ':' + targetExc.getMessage()); } catch (InterruptedException e) { // Ignore. The user pressed cancel. wasCanceled[0] = true; Index: Eclipse UI/org/eclipse/ui/ISaveablePart2.java =================================================================== RCS file: Eclipse UI/org/eclipse/ui/ISaveablePart2.java diff -N Eclipse UI/org/eclipse/ui/ISaveablePart2.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ Eclipse UI/org/eclipse/ui/ISaveablePart2.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.ui; + +/** + * Workbench parts implement or adapt to this interface to participate + * in actions that require a prompt for the user to provide input on + * what to do with unsaved data when the part is closed or the Workbench + * is shut down. + *

+ * + * @since 3.1 + */ +public interface ISaveablePart2 extends ISaveablePart { + + /** + * Standard return code constant (value 0) indicating that the part + * needs to be saved. + */ + public static final int YES = 0; + + /** + * Standard return code constant (value 1) indicating that the part + * does not need to be saved and the part should be closed. + */ + public static final int NO = 1; + + /** + * Standard return code constant (value 2) indicating that the part + * does not need to be saved and the part should not be closed. + */ + public static final int CANCEL = 2; + + /** + * Standard return code constant (value 3) indicating that the default + * behavior for prompting the user to save will be use. + */ + public static final int DEFAULT = 3; + + /** + * Prompts the user for input on what to do with unsaved data. + * This method is only called when the part is closed or when + * the Workbench is shutting down. + *

+ * Implementors are expected to open a custom dialog where the + * user will be able to determine what to do with the unsaved data. + * Implementors may also return a result of DEFAULT + * to get the default prompt handling from the Workbench. + *

+ * + * @return the return code, must be either YES, + * NO, CANCEL or DEFAULT. + */ + public int promptToSaveOnClose(); + +}