Skip to content

Commit cd70f45

Browse files
committed
[e4] Improve User Experience for saving a single part
Currently when a single part is saved this gives a very bad user experience as the user has to choose from a (single element) checkbox list with option [OK] and [CANCEL], but to *not* save the part one has to uncheck that part and then press [OK]. This now enhances the case of single element to asking the user with a simple dialog and the choice to [SAVE] / [DON'T SAVE] / [CANCEL] how it is done for the IDE with the e3 editors.
1 parent 228b669 commit cd70f45

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/SWTRenderersMessages.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public class SWTRenderersMessages extends NLS {
2424

2525
public static String choosePartsToSaveTitle;
2626
public static String choosePartsToSave;
27+
public static String choosePartsToSave_Button_Save;
28+
public static String choosePartsToSave_Button_Cancel;
29+
public static String choosePartsToSave_Button_Dont_Save;
30+
public static String saveSingleChangesQuestionTitle;
2731

2832
public static String menuClose;
2933
public static String menuCloseOthers;

bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/internal/workbench/renderers/swt/messages.properties

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616

1717
choosePartsToSaveTitle=Save Parts
1818
choosePartsToSave=Select the parts to save:
19+
choosePartsToSave_Button_Save=&Save
20+
choosePartsToSave_Button_Cancel=Cancel
21+
choosePartsToSave_Button_Dont_Save=Do&n't Save
22+
saveSingleChangesQuestionTitle=Save ''{0}''?
1923
menuClose = &Close
2024
menuCloseOthers = Close &Others
2125
menuCloseAll = Close &All
2226
menuCloseRight = Close Tabs to the &Right
2327
menuCloseLeft = Close Tabs to the &Left
2428
menuDetach= &Detach
25-
viewMenu = View Menu
29+
viewMenu = View Menu

bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/WBWRenderer.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@
6262
import org.eclipse.e4.ui.workbench.modeling.ISaveHandler;
6363
import org.eclipse.e4.ui.workbench.modeling.IWindowCloseHandler;
6464
import org.eclipse.jface.dialogs.Dialog;
65+
import org.eclipse.jface.dialogs.MessageDialog;
6566
import org.eclipse.jface.util.Geometry;
6667
import org.eclipse.jface.util.Util;
6768
import org.eclipse.jface.viewers.ArrayContentProvider;
6869
import org.eclipse.jface.viewers.CheckboxTableViewer;
6970
import org.eclipse.jface.window.IShellProvider;
7071
import org.eclipse.jface.window.Window;
72+
import org.eclipse.osgi.util.NLS;
7173
import org.eclipse.swt.SWT;
7274
import org.eclipse.swt.events.ControlEvent;
7375
import org.eclipse.swt.events.ControlListener;
@@ -446,7 +448,7 @@ public Object createWidget(MUIElement element, Object parent) {
446448
@Override
447449
public Save promptToSave(MPart dirtyPart) {
448450
Shell shell = (Shell) context.get(IServiceConstants.ACTIVE_SHELL);
449-
Object[] elements = promptForSave(shell, Collections.singleton(dirtyPart));
451+
Object[] elements = promptForSave(shell, List.of(dirtyPart));
450452
if (elements == null) {
451453
return Save.CANCEL;
452454
}
@@ -745,14 +747,36 @@ public void postProcess(MUIElement shellME) {
745747
}
746748
}
747749

748-
private Object[] promptForSave(Shell parentShell,
749-
Collection<MPart> saveableParts) {
750-
SaveablePartPromptDialog dialog = new SaveablePartPromptDialog(
751-
parentShell, saveableParts);
750+
private Object[] promptForSave(Shell parentShell, List<MPart> saveableParts) {
751+
if (saveableParts.size() == 1) {
752+
MPart part = saveableParts.get(0);
753+
String[] buttons;
754+
buttons = new String[] { SWTRenderersMessages.choosePartsToSave_Button_Save,
755+
SWTRenderersMessages.choosePartsToSave_Button_Dont_Save,
756+
SWTRenderersMessages.choosePartsToSave_Button_Cancel };
757+
758+
String message = NLS.bind(SWTRenderersMessages.saveSingleChangesQuestionTitle, part.getLabel());
759+
MessageDialog dialog = new MessageDialog(parentShell, SWTRenderersMessages.choosePartsToSaveTitle, null,
760+
message, MessageDialog.NONE, 0, buttons) {
761+
@Override
762+
protected int getShellStyle() {
763+
return SWT.CLOSE | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL | SWT.SHEET
764+
| getDefaultOrientation();
765+
}
766+
};
767+
switch (dialog.open()) {
768+
case 0:
769+
return new Object[] { part };
770+
case 1:
771+
return new Object[0];
772+
default:
773+
return null;
774+
}
775+
}
776+
SaveablePartPromptDialog dialog = new SaveablePartPromptDialog(parentShell, saveableParts);
752777
if (dialog.open() == Window.CANCEL) {
753778
return null;
754779
}
755-
756780
return dialog.getCheckedElements();
757781
}
758782

0 commit comments

Comments
 (0)