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 (-76 / +58 lines)
Lines 1-10 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
Lines 19-24 Link Here
19
import java.util.Hashtable;
19
import java.util.Hashtable;
20
import java.util.Iterator;
20
import java.util.Iterator;
21
import java.util.List;
21
import java.util.List;
22
import java.util.ListIterator;
22
import java.util.Map;
23
import java.util.Map;
23
24
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.CoreException;
Lines 47-52 Link Here
47
import org.eclipse.jface.util.IPropertyChangeListener;
48
import org.eclipse.jface.util.IPropertyChangeListener;
48
import org.eclipse.jface.util.PropertyChangeEvent;
49
import org.eclipse.jface.util.PropertyChangeEvent;
49
import org.eclipse.jface.util.SafeRunnable;
50
import org.eclipse.jface.util.SafeRunnable;
51
import org.eclipse.osgi.util.NLS;
50
import org.eclipse.swt.custom.BusyIndicator;
52
import org.eclipse.swt.custom.BusyIndicator;
51
import org.eclipse.swt.graphics.Image;
53
import org.eclipse.swt.graphics.Image;
52
import org.eclipse.swt.graphics.ImageData;
54
import org.eclipse.swt.graphics.ImageData;
Lines 68-73 Link Here
68
import org.eclipse.ui.IPersistableElement;
70
import org.eclipse.ui.IPersistableElement;
69
import org.eclipse.ui.IReusableEditor;
71
import org.eclipse.ui.IReusableEditor;
70
import org.eclipse.ui.ISaveablePart;
72
import org.eclipse.ui.ISaveablePart;
73
import org.eclipse.ui.ISaveablePart2;
71
import org.eclipse.ui.IWorkbenchPage;
74
import org.eclipse.ui.IWorkbenchPage;
72
import org.eclipse.ui.IWorkbenchPart;
75
import org.eclipse.ui.IWorkbenchPart;
73
import org.eclipse.ui.IWorkbenchPart2;
76
import org.eclipse.ui.IWorkbenchPart2;
Lines 141-151 Link Here
141
144
142
    private MultiStatus closingEditorStatus = null;
145
    private MultiStatus closingEditorStatus = null;
143
146
144
    private static final String RESOURCES_TO_SAVE_MESSAGE = WorkbenchMessages
147
    private static final String RESOURCES_TO_SAVE_MESSAGE = WorkbenchMessages.EditorManager_saveResourcesMessage; 
145
            .getString("EditorManager.saveResourcesMessage"); //$NON-NLS-1$
146
148
147
    private static final String SAVE_RESOURCES_TITLE = WorkbenchMessages
149
    private static final String SAVE_RESOURCES_TITLE = WorkbenchMessages.EditorManager_saveResourcesTitle;
148
            .getString("EditorManager.saveResourcesTitle"); //$NON-NLS-1$
149
150
150
    /**
151
    /**
151
     * EditorManager constructor comment.
152
     * EditorManager constructor comment.
Lines 191-198 Link Here
191
        if (closingEditorStatus == null) {
192
        if (closingEditorStatus == null) {
192
            createdStatus = true;
193
            createdStatus = true;
193
            closingEditorStatus = new MultiStatus(PlatformUI.PLUGIN_ID,
194
            closingEditorStatus = new MultiStatus(PlatformUI.PLUGIN_ID,
194
                    IStatus.OK, WorkbenchMessages
195
                    IStatus.OK, WorkbenchMessages.EditorManager_unableToOpenEditors,
195
                            .getString("EditorManager.unableToOpenEditors"), //$NON-NLS-1$
196
                    null);
196
                    null);
197
        }
197
        }
198
198
Lines 229-236 Link Here
229
        }
229
        }
230
        if (createdStatus) {
230
        if (createdStatus) {
231
            if (closingEditorStatus.getSeverity() == IStatus.ERROR) {
231
            if (closingEditorStatus.getSeverity() == IStatus.ERROR) {
232
                ErrorDialog.openError(window.getShell(), WorkbenchMessages
232
                ErrorDialog.openError(window.getShell(), WorkbenchMessages.EditorManager_unableToRestoreEditorTitle, 
233
                        .getString("EditorManager.unableToRestoreEditorTitle"), //$NON-NLS-1$
234
                        null, closingEditorStatus, IStatus.WARNING
233
                        null, closingEditorStatus, IStatus.WARNING
235
                                | IStatus.ERROR);
234
                                | IStatus.ERROR);
236
            }
235
            }
Lines 593-609 Link Here
593
592
594
        MessageDialog dialog = new MessageDialog(
593
        MessageDialog dialog = new MessageDialog(
595
                window.getShell(),
594
                window.getShell(),
596
                WorkbenchMessages
595
                WorkbenchMessages.EditorManager_reuseEditorDialogTitle, null, // accept the default window icon
597
                        .getString("EditorManager.reuseEditorDialogTitle"), null, // accept the default window icon //$NON-NLS-1$
596
                NLS.bind(WorkbenchMessages.EditorManager_saveChangesQuestion, dirtyEditor.getName()), 
598
                WorkbenchMessages
599
                        .format(
600
                                "EditorManager.saveChangesQuestion", new String[] { dirtyEditor.getName() }), //$NON-NLS-1$
601
                MessageDialog.QUESTION,
597
                MessageDialog.QUESTION,
602
                new String[] {
598
                new String[] {
603
                        IDialogConstants.YES_LABEL,
599
                        IDialogConstants.YES_LABEL,
604
                        IDialogConstants.NO_LABEL,
600
                        IDialogConstants.NO_LABEL,
605
                        WorkbenchMessages
601
                        WorkbenchMessages.EditorManager_openNewEditorLabel }, 
606
                                .getString("EditorManager.openNewEditorLabel") }, //$NON-NLS-1$
607
                0);
602
                0);
608
        int result = dialog.open();
603
        int result = dialog.open();
609
        if (result == 0) { //YES
604
        if (result == 0) { //YES
Lines 631-639 Link Here
631
        EditorDescriptor desc = (EditorDescriptor) reg.findEditor(editorId);
626
        EditorDescriptor desc = (EditorDescriptor) reg.findEditor(editorId);
632
        if (desc == null) {
627
        if (desc == null) {
633
            throw new PartInitException(
628
            throw new PartInitException(
634
                    WorkbenchMessages
629
                    NLS.bind(WorkbenchMessages.EditorManager_unknownEditorIDMessage,editorId )); 
635
                            .format(
636
                                    "EditorManager.unknownEditorIDMessage", new Object[] { editorId })); //$NON-NLS-1$
637
        }
630
        }
638
631
639
        IEditorReference result = openEditorFromDescriptor(new Editor(), desc,
632
        IEditorReference result = openEditorFromDescriptor(new Editor(), desc,
Lines 662-678 Link Here
662
            if (pathInput != null) {
655
            if (pathInput != null) {
663
                result = openSystemExternalEditor(pathInput.getPath());
656
                result = openSystemExternalEditor(pathInput.getPath());
664
            } else {
657
            } else {
665
                throw new PartInitException(WorkbenchMessages
658
                throw new PartInitException(WorkbenchMessages.EditorManager_systemEditorError); 
666
                        .getString("EditorManager.systemEditorError")); //$NON-NLS-1$
667
            }
659
            }
668
        } else if (desc.isOpenExternal()) {
660
        } else if (desc.isOpenExternal()) {
669
            result = openExternalEditor(desc, input);
661
            result = openExternalEditor(desc, input);
670
        } else {
662
        } else {
671
            // this should never happen
663
            // this should never happen
672
            throw new PartInitException(
664
            throw new PartInitException(
673
                    WorkbenchMessages
665
                    NLS.bind(WorkbenchMessages.EditorManager_invalidDescriptor, desc.getId() ));
674
                            .format(
675
                                    "EditorManager.invalidDescriptor", new String[] { desc.getId() })); //$NON-NLS-1$
676
        }
666
        }
677
667
678
        Workbench wb = (Workbench) window.getWorkbench();
668
        Workbench wb = (Workbench) window.getWorkbench();
Lines 711-726 Link Here
711
            });
701
            });
712
        } else {
702
        } else {
713
            throw new PartInitException(
703
            throw new PartInitException(
714
                    WorkbenchMessages
704
                    NLS.bind(WorkbenchMessages.EditorManager_errorOpeningExternalEditor, desc.getFileName(), desc.getId() ));
715
                            .format(
716
                                    "EditorManager.errorOpeningExternalEditor", new Object[] { desc.getFileName(), desc.getId() })); //$NON-NLS-1$
717
        }
705
        }
718
706
719
        if (ex[0] != null) {
707
        if (ex[0] != null) {
720
            throw new PartInitException(
708
            throw new PartInitException(
721
                    WorkbenchMessages
709
                    NLS.bind(WorkbenchMessages.EditorManager_errorOpeningExternalEditor, desc.getFileName(), desc.getId() ), ex[0]); 
722
                            .format(
723
                                    "EditorManager.errorOpeningExternalEditor", new Object[] { desc.getFileName(), desc.getId() }), ex[0]); //$NON-NLS-1$
724
        }
710
        }
725
711
726
        // we do not have an editor part for external editors
712
        // we do not have an editor part for external editors
Lines 749-757 Link Here
749
                    .findEditor(editorArray[i]);
735
                    .findEditor(editorArray[i]);
750
            if (innerDesc == null)
736
            if (innerDesc == null)
751
                throw new PartInitException(
737
                throw new PartInitException(
752
                        WorkbenchMessages
738
                        NLS.bind(WorkbenchMessages.EditorManager_unknownEditorIDMessage, editorArray[i] )); 
753
                                .format(
754
                                        "EditorManager.unknownEditorIDMessage", new Object[] { editorArray[i] })); //$NON-NLS-1$
755
            descArray[i] = innerDesc;
739
            descArray[i] = innerDesc;
756
            partArray[i] = createPart(descArray[i]);
740
            partArray[i] = createPart(descArray[i]);
757
            refArray[i] = new Editor();
741
            refArray[i] = new Editor();
Lines 821-833 Link Here
821
				UIStats.start(UIStats.INIT_PART, label);
805
				UIStats.start(UIStats.INIT_PART, label);
822
				part.init(site, input);
806
				part.init(site, input);
823
			} finally {
807
			} finally {
824
				UIStats.end(UIStats.INIT_PART, label);
808
				UIStats.end(UIStats.INIT_PART, part, label);
825
			}
809
			}
826
			if (part.getSite() != site)
810
			if (part.getSite() != site)
827
				throw new PartInitException(
811
				throw new PartInitException(
828
						WorkbenchMessages
812
						NLS.bind(WorkbenchMessages.EditorManager_siteIncorrect,  desc.getId() ));
829
								.format(
830
										"EditorManager.siteIncorrect", new Object[] { desc.getId() })); //$NON-NLS-1$
831
		} catch (Exception e) {
813
		} catch (Exception e) {
832
			disposeEditorActionBars((EditorActionBars) site.getActionBars());
814
			disposeEditorActionBars((EditorActionBars) site.getActionBars());
833
			site.dispose();
815
			site.dispose();
Lines 835-843 Link Here
835
				throw (PartInitException) e;
817
				throw (PartInitException) e;
836
818
837
			throw new PartInitException(
819
			throw new PartInitException(
838
					WorkbenchMessages
820
					NLS.bind(WorkbenchMessages.EditorManager_unableToInitialize,desc.getId(), e ), e);
839
							.format(
840
									"EditorManager.unableToInitialize", new Object[] { desc.getId(), e }), e); //$NON-NLS-1$        	
841
		}
821
		}
842
    }
822
    }
843
823
Lines 890-901 Link Here
890
        if (label == null) {
870
        if (label == null) {
891
            label = desc.getLabel();
871
            label = desc.getLabel();
892
        }
872
        }
893
        IEditorPart editor;
873
        IEditorPart editor = null;
894
        try {
874
        try {
895
            UIStats.start(UIStats.CREATE_PART, label);
875
            UIStats.start(UIStats.CREATE_PART, label);
896
            editor = createPart(desc);
876
            editor = createPart(desc);
897
        } finally {
877
        } finally {
898
            UIStats.end(UIStats.CREATE_PART, label);
878
            UIStats.end(UIStats.CREATE_PART, editor, label);
899
        }
879
        }
900
        // Open the instance.
880
        // Open the instance.
901
        createSite(ref, editor, desc, input);
881
        createSite(ref, editor, desc, input);
Lines 919-927 Link Here
919
899
920
        if (ex[0] != null)
900
        if (ex[0] != null)
921
            throw new PartInitException(
901
            throw new PartInitException(
922
                    WorkbenchMessages
902
                    NLS.bind(WorkbenchMessages.EditorManager_unableToInstantiate, desc.getId(), ex[0] )); 
923
                            .format(
924
                                    "EditorManager.unableToInstantiate", new Object[] { desc.getId(), ex[0] })); //$NON-NLS-1$
925
        
903
        
926
        IConfigurationElement element = desc.getConfigurationElement();
904
        IConfigurationElement element = desc.getConfigurationElement();
927
        if (element != null) {
905
        if (element != null) {
Lines 952-960 Link Here
952
930
953
        if (!result[0]) {
931
        if (!result[0]) {
954
            throw new PartInitException(
932
            throw new PartInitException(
955
                    WorkbenchMessages
933
                    NLS.bind(WorkbenchMessages.EditorManager_unableToOpenExternalEditor, location )); 
956
                            .format(
957
                                    "EditorManager.unableToOpenExternalEditor", new Object[] { location })); //$NON-NLS-1$
958
        }
934
        }
959
935
960
        // We do not have an editor part for external editors
936
        // We do not have an editor part for external editors
Lines 999-1006 Link Here
999
        final MultiStatus result = new MultiStatus(
975
        final MultiStatus result = new MultiStatus(
1000
                PlatformUI.PLUGIN_ID,
976
                PlatformUI.PLUGIN_ID,
1001
                IStatus.OK,
977
                IStatus.OK,
1002
                WorkbenchMessages
978
                WorkbenchMessages.EditorManager_problemsRestoringEditors, null); 
1003
                        .getString("EditorManager.problemsRestoringEditors"), null); //$NON-NLS-1$
1004
        final String activeWorkbookID[] = new String[1];
979
        final String activeWorkbookID[] = new String[1];
1005
        final ArrayList visibleEditors = new ArrayList(5);
980
        final ArrayList visibleEditors = new ArrayList(5);
1006
        final IEditorPart activeEditor[] = new IEditorPart[1];
981
        final IEditorPart activeEditor[] = new IEditorPart[1];
Lines 1057-1064 Link Here
1057
                                IStatus.ERROR,
1032
                                IStatus.ERROR,
1058
                                PlatformUI.PLUGIN_ID,
1033
                                PlatformUI.PLUGIN_ID,
1059
                                0,
1034
                                0,
1060
                                WorkbenchMessages
1035
                                WorkbenchMessages.EditorManager_exceptionRestoringEditor, e));
1061
                                        .getString("EditorManager.exceptionRestoringEditor"), e)); //$NON-NLS-1$
1062
            }
1036
            }
1063
        });
1037
        });
1064
        return result;
1038
        return result;
Lines 1161-1169 Link Here
1161
                IStatus.ERROR,
1135
                IStatus.ERROR,
1162
                PlatformUI.PLUGIN_ID,
1136
                PlatformUI.PLUGIN_ID,
1163
                0,
1137
                0,
1164
                WorkbenchMessages
1138
                NLS.bind(WorkbenchMessages.EditorManager_unableToCreateEditor, ref.getName() ), t); 
1165
                        .format(
1166
                                "EditorManager.unableToCreateEditor", new String[] { ref.getName() }), t); //$NON-NLS-1$
1167
    }
1139
    }
1168
1140
1169
    /**
1141
    /**
Lines 1185-1190 Link Here
1185
    public static boolean saveAll(List dirtyEditors, boolean confirm,
1157
    public static boolean saveAll(List dirtyEditors, boolean confirm,
1186
            final IWorkbenchWindow window) {
1158
            final IWorkbenchWindow window) {
1187
        if (confirm) {
1159
        if (confirm) {
1160
        	
1161
         	// process all editors that implement ISaveablePart2
1162
        	// these parts are removed from the list after saving them.
1163
        	ListIterator listIterator = dirtyEditors.listIterator();
1164
            while (listIterator.hasNext()) {
1165
                IEditorPart part = (IEditorPart) listIterator.next();
1166
                if (part instanceof ISaveablePart2) {
1167
                	window.getActivePage().bringToTop(part);
1168
                	if (!SaveableHelper.savePart(part, part, window, true))
1169
                		return false;
1170
                	listIterator.remove();
1171
                }
1172
            }	
1173
            
1174
        	// If the editor list is empty return.
1175
            if (dirtyEditors.isEmpty())
1176
            	return true;
1177
            
1188
            // Convert the list into an element collection.
1178
            // Convert the list into an element collection.
1189
            AdaptableList input = new AdaptableList(dirtyEditors);
1179
            AdaptableList input = new AdaptableList(dirtyEditors);
1190
1180
Lines 1207-1213 Link Here
1207
                return false;
1197
                return false;
1208
1198
1209
            // If the editor list is empty return.
1199
            // If the editor list is empty return.
1210
            if (dirtyEditors.size() == 0)
1200
            if (dirtyEditors.isEmpty())
1211
                return true;
1201
                return true;
1212
        }
1202
        }
1213
1203
Lines 1260-1267 Link Here
1260
        };
1250
        };
1261
1251
1262
        // Do the save.
1252
        // Do the save.
1263
        return SaveableHelper.runProgressMonitorOperation(WorkbenchMessages
1253
        return SaveableHelper.runProgressMonitorOperation(WorkbenchMessages.Save_All, progressOp, window);
1264
                .getString("Save_All"), progressOp, window); //$NON-NLS-1$
1265
    }
1254
    }
1266
1255
1267
    /*
1256
    /*
Lines 1287-1294 Link Here
1287
    public IStatus saveState(final IMemento memento) {
1276
    public IStatus saveState(final IMemento memento) {
1288
1277
1289
        final MultiStatus result = new MultiStatus(PlatformUI.PLUGIN_ID,
1278
        final MultiStatus result = new MultiStatus(PlatformUI.PLUGIN_ID,
1290
                IStatus.OK, WorkbenchMessages
1279
                IStatus.OK, WorkbenchMessages.EditorManager_problemsSavingEditors, null); 
1291
                        .getString("EditorManager.problemsSavingEditors"), null); //$NON-NLS-1$
1292
1280
1293
        // Save the editor area workbooks layout/relationship
1281
        // Save the editor area workbooks layout/relationship
1294
        IMemento editorAreaMem = memento
1282
        IMemento editorAreaMem = memento
Lines 1495-1505 Link Here
1495
                    ErrorDialog
1483
                    ErrorDialog
1496
                            .openError(
1484
                            .openError(
1497
                                    window.getShell(),
1485
                                    window.getShell(),
1498
                                    WorkbenchMessages
1486
                                    WorkbenchMessages.EditorManager_unableToRestoreEditorTitle,
1499
                                            .getString("EditorManager.unableToRestoreEditorTitle"), //$NON-NLS-1$
1487
                                    NLS.bind(WorkbenchMessages.EditorManager_unableToRestoreEditorMessage,  getName() ),
1500
                                    WorkbenchMessages
1501
                                            .format(
1502
                                                    "EditorManager.unableToRestoreEditorMessage", new String[] { getName() }), //$NON-NLS-1$
1503
                                    status, IStatus.WARNING | IStatus.ERROR);
1488
                                    status, IStatus.WARNING | IStatus.ERROR);
1504
                }
1489
                }
1505
            }
1490
            }
Lines 1584-1590 Link Here
1584
                        .log("Unable to restore editor - no input factory ID."); //$NON-NLS-1$
1569
                        .log("Unable to restore editor - no input factory ID."); //$NON-NLS-1$
1585
                return null;
1570
                return null;
1586
            }
1571
            }
1587
            IAdaptable input;
1572
            IAdaptable input = null;
1588
            String label = null; // debugging only
1573
            String label = null; // debugging only
1589
            if (UIStats.isDebugging(UIStats.CREATE_PART_INPUT)) {
1574
            if (UIStats.isDebugging(UIStats.CREATE_PART_INPUT)) {
1590
                label = getName() != null ? getName() : factoryID;
1575
                label = getName() != null ? getName() : factoryID;
Lines 1607-1613 Link Here
1607
                    return null;
1592
                    return null;
1608
                }
1593
                }
1609
            } finally {
1594
            } finally {
1610
                UIStats.end(UIStats.CREATE_PART_INPUT, label);
1595
                UIStats.end(UIStats.CREATE_PART_INPUT, input, label);
1611
            }
1596
            }
1612
            if (!(input instanceof IEditorInput)) {
1597
            if (!(input instanceof IEditorInput)) {
1613
                WorkbenchPlugin
1598
                WorkbenchPlugin
Lines 1822-1831 Link Here
1822
                                IStatus.ERROR,
1807
                                IStatus.ERROR,
1823
                                PlatformUI.PLUGIN_ID,
1808
                                PlatformUI.PLUGIN_ID,
1824
                                0,
1809
                                0,
1825
                                WorkbenchMessages
1810
                                NLS.bind(WorkbenchMessages.EditorManager_unableToSaveEditor, editorRef.getTitle() ), e));
1826
                                        .format(
1827
                                                "EditorManager.unableToSaveEditor", new String[] { editorRef.getTitle() }), //$NON-NLS-1$
1828
                                e));
1829
            }
1811
            }
1830
        });
1812
        });
1831
    }
1813
    }
Lines 1852-1855 Link Here
1852
            }
1834
            }
1853
        }
1835
        }
1854
    }
1836
    }
1855
}
1837
}
(-)Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java (-20 / +26 lines)
Lines 1-10 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004 IBM Corporation and others.
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
Lines 20-26 Link Here
20
import org.eclipse.jface.operation.IRunnableContext;
20
import org.eclipse.jface.operation.IRunnableContext;
21
import org.eclipse.jface.operation.IRunnableWithProgress;
21
import org.eclipse.jface.operation.IRunnableWithProgress;
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.ui.ISaveablePart;
24
import org.eclipse.ui.ISaveablePart;
25
import org.eclipse.ui.ISaveablePart2;
24
import org.eclipse.ui.IWorkbenchPart;
26
import org.eclipse.ui.IWorkbenchPart;
25
import org.eclipse.ui.IWorkbenchWindow;
27
import org.eclipse.ui.IWorkbenchWindow;
26
import org.eclipse.ui.PlatformUI;
28
import org.eclipse.ui.PlatformUI;
Lines 58-82 Link Here
58
		// If confirmation is required ..
60
		// If confirmation is required ..
59
		if (confirm) {
61
		if (confirm) {
60
			int choice = AutomatedResponse;
62
			int choice = AutomatedResponse;
61
			if (choice == -1) {
63
			if (choice == -1) {				
62
				String message = WorkbenchMessages.format("EditorManager.saveChangesQuestion", new Object[] { part.getTitle()}); //$NON-NLS-1$
64
				if (saveable instanceof ISaveablePart2) {
63
				// Show a dialog.
65
					choice = ((ISaveablePart2)saveable).promptToSaveOnClose();
64
				String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
66
				}
65
					MessageDialog d = new MessageDialog(
67
				if (choice == -1 || choice == ISaveablePart2.DEFAULT) {
66
						window.getShell(), WorkbenchMessages.getString("Save_Resource"), //$NON-NLS-1$
68
					String message = NLS.bind(WorkbenchMessages.EditorManager_saveChangesQuestion, part.getTitle()); 
67
						null, message, MessageDialog.QUESTION, buttons, 0);
69
					// Show a dialog.
68
				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
				}
69
			}
76
			}
70
77
71
			// Branch on the user choice.
78
			// Branch on the user choice.
72
			// 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.
73
			switch (choice) {
80
			switch (choice) {
74
				case 0 : //yes
81
				case ISaveablePart2.YES : //yes
75
					break;
82
					break;
76
				case 1 : //no
83
				case ISaveablePart2.NO : //no
77
					return true;
84
					return true;
78
				default :
85
				default :
79
				case 2 : //cancel
86
				case ISaveablePart2.CANCEL : //cancel
80
					return false;
87
					return false;
81
			}
88
			}
82
		}
89
		}
Lines 90-96 Link Here
90
		};
97
		};
91
98
92
		// Do the save.
99
		// Do the save.
93
		return runProgressMonitorOperation(WorkbenchMessages.getString("Save"), progressOp,window); //$NON-NLS-1$
100
		return runProgressMonitorOperation(WorkbenchMessages.Save, progressOp,window); 
94
	}
101
	}
95
	/**
102
	/**
96
	 * Runs a progress monitor operation.
103
	 * Runs a progress monitor operation.
Lines 114-124 Link Here
114
		try {
121
		try {
115
			ctx.run(false, true, runnable);
122
			ctx.run(false, true, runnable);
116
		} catch (InvocationTargetException e) {
123
		} catch (InvocationTargetException e) {
117
			String title = WorkbenchMessages.format("EditorManager.operationFailed", new Object[] { opName }); //$NON-NLS-1$
124
			String title = NLS.bind(WorkbenchMessages.EditorManager_operationFailed, opName ); 
118
			Throwable targetExc = e.getTargetException();
125
			Throwable targetExc = e.getTargetException();
119
			WorkbenchPlugin.log(title, new Status(IStatus.WARNING, PlatformUI.PLUGIN_ID, 0, title, targetExc));
126
			WorkbenchPlugin.log(title, new Status(IStatus.WARNING, PlatformUI.PLUGIN_ID, 0, title, targetExc));
120
			MessageDialog.openError(window.getShell(), WorkbenchMessages.getString("Error"), //$NON-NLS-1$
127
			MessageDialog.openError(window.getShell(), WorkbenchMessages.Error, title + ':' + targetExc.getMessage());
121
			title + ':' + targetExc.getMessage());
122
		} catch (InterruptedException e) {
128
		} catch (InterruptedException e) {
123
			// Ignore.  The user pressed cancel.
129
			// Ignore.  The user pressed cancel.
124
			wasCanceled[0] = true;
130
			wasCanceled[0] = true;
(-)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