View | Details | Raw Unified | Return to bug 76768 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/EditorManager.java (-1 / +20 lines)
Lines 17-22 Link Here
17
import java.util.Hashtable;
17
import java.util.Hashtable;
18
import java.util.Iterator;
18
import java.util.Iterator;
19
import java.util.List;
19
import java.util.List;
20
import java.util.ListIterator;
20
import java.util.Map;
21
import java.util.Map;
21
22
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.CoreException;
Lines 68-73 Link Here
68
import org.eclipse.ui.IPersistableElement;
69
import org.eclipse.ui.IPersistableElement;
69
import org.eclipse.ui.IReusableEditor;
70
import org.eclipse.ui.IReusableEditor;
70
import org.eclipse.ui.ISaveablePart;
71
import org.eclipse.ui.ISaveablePart;
72
import org.eclipse.ui.ISaveablePart2;
71
import org.eclipse.ui.IWorkbenchPage;
73
import org.eclipse.ui.IWorkbenchPage;
72
import org.eclipse.ui.IWorkbenchPart;
74
import org.eclipse.ui.IWorkbenchPart;
73
import org.eclipse.ui.IWorkbenchPart2;
75
import org.eclipse.ui.IWorkbenchPart2;
Lines 1276-1281 Link Here
1276
    public static boolean saveAll(List dirtyEditors, boolean confirm,
1278
    public static boolean saveAll(List dirtyEditors, boolean confirm,
1277
            final IWorkbenchWindow window) {
1279
            final IWorkbenchWindow window) {
1278
        if (confirm) {
1280
        if (confirm) {
1281
         	// process all editors that implement ISaveablePart2
1282
        	// these parts are removed from the list after saving them.
1283
        	ListIterator listIterator = dirtyEditors.listIterator();
1284
            while (listIterator.hasNext()) {
1285
                IEditorPart part = (IEditorPart) listIterator.next();
1286
                if (part instanceof ISaveablePart2) {
1287
                	window.getActivePage().bringToTop(part);
1288
                	if (!SaveableHelper.savePart(part, part, window, true))
1289
                		return false;
1290
                	listIterator.remove();
1291
                }
1292
            }	
1293
            
1294
        	// If the editor list is empty return.
1295
            if (dirtyEditors.isEmpty())
1296
            	return true;
1297
            
1279
            // Convert the list into an element collection.
1298
            // Convert the list into an element collection.
1280
            AdaptableList input = new AdaptableList(dirtyEditors);
1299
            AdaptableList input = new AdaptableList(dirtyEditors);
1281
1300
Lines 1298-1304 Link Here
1298
                return false;
1317
                return false;
1299
1318
1300
            // If the editor list is empty return.
1319
            // If the editor list is empty return.
1301
            if (dirtyEditors.size() == 0)
1320
            if (dirtyEditors.isEmpty())
1302
                return true;
1321
                return true;
1303
        }
1322
        }
1304
1323
(-)Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java (-11 / +17 lines)
Lines 22-27 Link Here
22
import org.eclipse.jface.window.ApplicationWindow;
22
import org.eclipse.jface.window.ApplicationWindow;
23
import org.eclipse.osgi.util.NLS;
23
import org.eclipse.osgi.util.NLS;
24
import org.eclipse.ui.ISaveablePart;
24
import org.eclipse.ui.ISaveablePart;
25
import org.eclipse.ui.ISaveablePart2;
25
import org.eclipse.ui.IWorkbenchPart;
26
import org.eclipse.ui.IWorkbenchPart;
26
import org.eclipse.ui.IWorkbenchWindow;
27
import org.eclipse.ui.IWorkbenchWindow;
27
import org.eclipse.ui.PlatformUI;
28
import org.eclipse.ui.PlatformUI;
Lines 59-83 Link Here
59
		// If confirmation is required ..
60
		// If confirmation is required ..
60
		if (confirm) {
61
		if (confirm) {
61
			int choice = AutomatedResponse;
62
			int choice = AutomatedResponse;
62
			if (choice == -1) {
63
			if (choice == -1) {				
63
				String message = NLS.bind(WorkbenchMessages.EditorManager_saveChangesQuestion, part.getTitle()); 
64
				if (saveable instanceof ISaveablePart2) {
64
				// Show a dialog.
65
					choice = ((ISaveablePart2)saveable).promptToSaveOnClose();
65
				String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
66
				}
66
					MessageDialog d = new MessageDialog(
67
				if (choice == -1 || choice == ISaveablePart2.DEFAULT) {
67
						window.getShell(), WorkbenchMessages.Save_Resource,
68
					String message = NLS.bind(WorkbenchMessages.EditorManager_saveChangesQuestion, part.getTitle()); 
68
						null, message, MessageDialog.QUESTION, buttons, 0);
69
					// Show a dialog.
69
				choice = d.open();
70
					String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
71
						MessageDialog d = new MessageDialog(
72
							window.getShell(), WorkbenchMessages.Save_Resource,
73
							null, message, MessageDialog.QUESTION, buttons, 0);
74
					choice = d.open();
75
				}
70
			}
76
			}
71
77
72
			// Branch on the user choice.
78
			// Branch on the user choice.
73
			// The choice id is based on the order of button labels above.
79
			// The choice id is based on the order of button labels above.
74
			switch (choice) {
80
			switch (choice) {
75
				case 0 : //yes
81
				case ISaveablePart2.YES : //yes
76
					break;
82
					break;
77
				case 1 : //no
83
				case ISaveablePart2.NO : //no
78
					return true;
84
					return true;
79
				default :
85
				default :
80
				case 2 : //cancel
86
				case ISaveablePart2.CANCEL : //cancel
81
					return false;
87
					return false;
82
			}
88
			}
83
		}
89
		}
(-)Eclipse (+65 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ui;
13
14
/**
15
 * Workbench parts implement or adapt to this interface to participate
16
 * in actions that require a prompt for the user to provide input on 
17
 * what to do with unsaved data when the part is closed or the Workbench
18
 * is shut down.
19
 * <p>
20
 * 
21
 * @since 3.1
22
 */
23
public interface ISaveablePart2 extends ISaveablePart {
24
	
25
	/**
26
	 * Standard return code constant (value 0) indicating that the part
27
	 * needs to be saved.
28
	 */
29
	public static final int YES = 0;
30
	
31
	/**
32
	 * Standard return code constant (value 1) indicating that the part
33
	 * does not need to be saved and the part should be closed.
34
	 */
35
	public static final int NO = 1;
36
	
37
	/**
38
	 * Standard return code constant (value 2) indicating that the part
39
	 * does not need to be saved and the part should not be closed.
40
	 */
41
	public static final int CANCEL = 2;
42
	
43
	/**
44
	 * Standard return code constant (value 3) indicating that the default
45
	 * behavior for prompting the user to save will be use.
46
	 */
47
	public static final int DEFAULT = 3;
48
		
49
    /**
50
     * Prompts the user for input on what to do with unsaved data.  
51
     * This method is only called when the part is closed or when
52
     * the Workbench is shutting down.
53
     * <p>
54
     * Implementors are expected to open a custom dialog where the 
55
     * user will be able to determine what to do with the unsaved data.
56
     * Implementors may also return a result of <code>DEFAULT</code> 
57
     * to get the default prompt handling from the Workbench.
58
     * </p>
59
     * 
60
	 * @return the return code, must be either <code>YES</code>, 
61
	 * <code>NO</code>, <code>CANCEL</code> or <code>DEFAULT</code>.
62
	 */
63
	public int promptToSaveOnClose();
64
65
}

Return to bug 76768