From 57f6a99f3ade1e9d25dbe6631e84ba23730d4bd2 Mon Sep 17 00:00:00 2001 From: Mickael Istria Date: Fri, 31 May 2024 16:26:01 +0200 Subject: [PATCH] Add API enabing to Pin PopupDialog In some circumstances (eg comparisons), users may want PopopDialogs to remain visible when switching attention to another area. This introduces an opt-in flag to present a "Pin dialog" menu (and a "Close") to allow the dialog to stick when users selects it. Fixes https://github.com/eclipse-platform/eclipse.platform.ui/issues/1905 --- .../eclipse/jface/dialogs/PopupDialog.java | 171 +++++++++++++----- .../src/org/eclipse/jface/messages.properties | 2 + 2 files changed, 131 insertions(+), 42 deletions(-) diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/PopupDialog.java b/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/PopupDialog.java index c30d29ca64b..558447264db 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/PopupDialog.java +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/PopupDialog.java @@ -183,6 +183,29 @@ public void run() { } } + private class PinAction extends Action { + PinAction() { + super(JFaceResources.getString("PopupDialog.pinDialog"), IAction.AS_CHECK_BOX); //$NON-NLS-1$ + setChecked(pinDialog); + } + + @Override + public void run() { + pinDialog = isChecked(); + } + } + + private class CloseAction extends Action { + CloseAction() { + super(JFaceResources.getString("PopupDialog.close"), IAction.AS_PUSH_BUTTON); //$NON-NLS-1$ + } + + @Override + public void run() { + close(); + } + } + /** * * Remember location action for the dialog. @@ -341,6 +364,9 @@ private static GridLayoutFactory getPopupLayout() { * shown. */ private boolean persistLocation = false; + + private boolean pinDialog = false; + /** * Flag specifying whether to use new 3.4 API instead of the old one. * @@ -358,6 +384,8 @@ private static GridLayoutFactory getPopupLayout() { */ private String infoText; + private boolean showPinAction; + /** * Constructs a new instance of PopupDialog. * @@ -407,51 +435,103 @@ public PopupDialog(Shell parent, int shellStyle, boolean takeFocusOnOpen, boolean showDialogMenu, boolean showPersistActions, String titleText, String infoText) { this(parent, shellStyle, takeFocusOnOpen, persistSize, persistLocation, - showDialogMenu, showPersistActions, titleText, infoText, true); + showDialogMenu, showPersistActions, false, titleText, infoText, true); + } + /** + * Constructs a new instance of PopupDialog. + * + * @param parent The parent shell. + * @param shellStyle The shell style. + * @param takeFocusOnOpen A boolean indicating whether focus should be taken + * by this popup when it opens. + * @param persistSize A boolean indicating whether the size should be + * persisted upon close of the dialog. The size can + * only be persisted if the dialog settings for + * persisting the bounds are also specified. If a menu + * action will be provided that allows the user to + * control this feature and the user hasn't changed + * that setting, then this flag is used as initial + * default for the menu. + * @param persistLocation A boolean indicating whether the location should be + * persisted upon close of the dialog. The location + * can only be persisted if the dialog settings for + * persisting the bounds are also specified. If a menu + * action will be provided that allows the user to + * control this feature and the user hasn't changed + * that setting, then this flag is used as initial + * default for the menu. default for the menu until + * the user changed it. + * @param showDialogMenu A boolean indicating whether a menu for moving and + * resizing the popup should be provided. + * @param showPersistActions A boolean indicating whether actions allowing the + * user to control the persisting of the dialog bounds + * and location should be shown in the dialog menu. + * This parameter has no effect if + * showDialogMenu is false. + * @param showPinAction A boolean indicating whether actions allowing the + * user to pin the dialog so it remains visible and + * accessible when deactivated should be shown in the + * dialog menu. This parameter has no effect if + * showDialogMenu is false. + * @param titleText Text to be shown in an upper title area, or + * null if there is no title. + * @param infoText Text to be shown in a lower info area, or + * null if there is no info area. + * + * @see PopupDialog#getDialogSettings() + * + * @since 3.35 + */ + public PopupDialog(Shell parent, int shellStyle, boolean takeFocusOnOpen, + boolean persistSize, boolean persistLocation, + boolean showDialogMenu, boolean showPersistActions, boolean showPinAction, + String titleText, String infoText) { + this(parent, shellStyle, takeFocusOnOpen, persistSize, persistLocation, + showDialogMenu, showPersistActions, showPinAction, titleText, infoText, true); } /** * Constructs a new instance of PopupDialog. * - * @param parent - * The parent shell. - * @param shellStyle - * The shell style. - * @param takeFocusOnOpen - * A boolean indicating whether focus should be taken by this - * popup when it opens. - * @param persistSize - * A boolean indicating whether the size should be persisted upon - * close of the dialog. The size can only be persisted if the - * dialog settings for persisting the bounds are also specified. - * If a menu action will be provided that allows the user to - * control this feature and the user hasn't changed that setting, - * then this flag is used as initial default for the menu. - * @param persistLocation - * A boolean indicating whether the location should be persisted - * upon close of the dialog. The location can only be persisted - * if the dialog settings for persisting the bounds are also - * specified. If a menu action will be provided that allows the - * user to control this feature and the user hasn't changed that - * setting, then this flag is used as initial default for the - * menu. default for the menu until the user changed it. - * @param showDialogMenu - * A boolean indicating whether a menu for moving and resizing - * the popup should be provided. - * @param showPersistActions - * A boolean indicating whether actions allowing the user to - * control the persisting of the dialog bounds and location - * should be shown in the dialog menu. This parameter has no - * effect if showDialogMenu is false. - * @param titleText - * Text to be shown in an upper title area, or null - * if there is no title. - * @param infoText - * Text to be shown in a lower info area, or null - * if there is no info area. - * @param use34API - * true if 3.4 API should be used + * @param parent The parent shell. + * @param shellStyle The shell style. + * @param takeFocusOnOpen A boolean indicating whether focus should be taken + * by this popup when it opens. + * @param persistSize A boolean indicating whether the size should be + * persisted upon close of the dialog. The size can + * only be persisted if the dialog settings for + * persisting the bounds are also specified. If a menu + * action will be provided that allows the user to + * control this feature and the user hasn't changed + * that setting, then this flag is used as initial + * default for the menu. + * @param persistLocation A boolean indicating whether the location should be + * persisted upon close of the dialog. The location + * can only be persisted if the dialog settings for + * persisting the bounds are also specified. If a menu + * action will be provided that allows the user to + * control this feature and the user hasn't changed + * that setting, then this flag is used as initial + * default for the menu. default for the menu until + * the user changed it. + * @param showDialogMenu A boolean indicating whether a menu for moving and + * resizing the popup should be provided. + * @param showPersistActions A boolean indicating whether actions allowing the + * user to control the persisting of the dialog bounds + * and location should be shown in the dialog menu. + * This parameter has no effect if + * showDialogMenu is false. + * @param showPinAction A boolean indicating whether actions allowing the + * user to pin the dialog so it remains visible and + * accessible when deactivated should be shown in the + * dialog menu. This parameter has no effect if + * showDialogMenu is false. + * @param titleText Text to be shown in an upper title area, or + * null if there is no title. + * @param infoText Text to be shown in a lower info area, or + * null if there is no info area. + * @param use34API true if 3.4 API should be used * * @see PopupDialog#getDialogSettings() * @@ -460,6 +540,7 @@ public PopupDialog(Shell parent, int shellStyle, boolean takeFocusOnOpen, private PopupDialog(Shell parent, int shellStyle, boolean takeFocusOnOpen, boolean persistSize, boolean persistLocation, boolean showDialogMenu, boolean showPersistActions, + boolean showPinAction, String titleText, String infoText, boolean use34API) { super(parent); // Prior to 3.4, we encouraged use of SWT.NO_TRIM and provided a @@ -477,6 +558,7 @@ private PopupDialog(Shell parent, int shellStyle, boolean takeFocusOnOpen, this.takeFocusOnOpen = takeFocusOnOpen; this.showDialogMenu = showDialogMenu; this.showPersistActions = showPersistActions; + this.showPinAction = showPinAction; this.titleText = titleText; this.infoText = infoText; @@ -504,7 +586,7 @@ protected void configureShell(Shell shell) { * the asyncClose() call is disabled in GTK. See Eclipse Bugs * 466500 and 113577 for more information. */ - if (listenToDeactivate && event.widget == getShell() + if (!pinDialog && listenToDeactivate && event.widget == getShell() && getShell().getShells().length == 0) { if (!Util.isGtk()) { asyncClose(); @@ -538,7 +620,7 @@ && getShell().getShells().length == 0) { if (parent != null) { if ((getShellStyle() & SWT.ON_TOP) != 0) { parentDeactivateListener = event -> { - if (listenToParentDeactivate) { + if (!pinDialog && listenToParentDeactivate) { asyncClose(); } else { // Our first deactivate, now start listening on the Mac. @@ -565,7 +647,7 @@ public void handleEvent(Event event) { * "Show all Instances" and "Show all References" do. * They all are InspectPopupDialog instances... */ - if (event.widget != parent || !listenToDeactivate || parent.isDisposed()) { + if (pinDialog || event.widget != parent || !listenToDeactivate || parent.isDisposed()) { return; } parent.removeListener(SWT.Activate, this); @@ -893,6 +975,10 @@ protected void fillDialogMenu(IMenuManager dialogMenu) { dialogMenu.add(new PersistBoundsAction()); } } + if (this.showPinAction) { + dialogMenu.add(new PinAction()); + } + dialogMenu.add(new CloseAction()); dialogMenu.add(new Separator("SystemMenuEnd")); //$NON-NLS-1$ } @@ -1524,4 +1610,5 @@ private void handleDispose() { } titleFont = null; } + } diff --git a/bundles/org.eclipse.jface/src/org/eclipse/jface/messages.properties b/bundles/org.eclipse.jface/src/org/eclipse/jface/messages.properties index eac00949f9f..3783048e070 100644 --- a/bundles/org.eclipse.jface/src/org/eclipse/jface/messages.properties +++ b/bundles/org.eclipse.jface/src/org/eclipse/jface/messages.properties @@ -130,6 +130,8 @@ PopupDialog.move = &Move PopupDialog.persistBounds = R&emember Size and Location PopupDialog.persistSize = Remember Si&ze PopupDialog.persistLocation = Remember &Location +PopupDialog.pinDialog = &Pin dialog +PopupDialog.close = &Close PopupDialog.menuTooltip = Menu ############################################################