Skip to content

Commit 934ccc6

Browse files
committed
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 #1905
1 parent ef01382 commit 934ccc6

File tree

2 files changed

+131
-42
lines changed

2 files changed

+131
-42
lines changed

bundles/org.eclipse.jface/src/org/eclipse/jface/dialogs/PopupDialog.java

+129-42
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,29 @@ public void run() {
183183
}
184184
}
185185

186+
private class PinAction extends Action {
187+
PinAction() {
188+
super(JFaceResources.getString("PopupDialog.pinDialog"), IAction.AS_CHECK_BOX); //$NON-NLS-1$
189+
setChecked(pinDialog);
190+
}
191+
192+
@Override
193+
public void run() {
194+
pinDialog = isChecked();
195+
}
196+
}
197+
198+
private class CloseAction extends Action {
199+
CloseAction() {
200+
super(JFaceResources.getString("PopupDialog.close"), IAction.AS_PUSH_BUTTON); //$NON-NLS-1$
201+
}
202+
203+
@Override
204+
public void run() {
205+
close();
206+
}
207+
}
208+
186209
/**
187210
*
188211
* Remember location action for the dialog.
@@ -341,6 +364,9 @@ private static GridLayoutFactory getPopupLayout() {
341364
* shown.
342365
*/
343366
private boolean persistLocation = false;
367+
368+
private boolean pinDialog = false;
369+
344370
/**
345371
* Flag specifying whether to use new 3.4 API instead of the old one.
346372
*
@@ -358,6 +384,8 @@ private static GridLayoutFactory getPopupLayout() {
358384
*/
359385
private String infoText;
360386

387+
private boolean showPinAction;
388+
361389
/**
362390
* Constructs a new instance of <code>PopupDialog</code>.
363391
*
@@ -407,51 +435,103 @@ public PopupDialog(Shell parent, int shellStyle, boolean takeFocusOnOpen,
407435
boolean showDialogMenu, boolean showPersistActions,
408436
String titleText, String infoText) {
409437
this(parent, shellStyle, takeFocusOnOpen, persistSize, persistLocation,
410-
showDialogMenu, showPersistActions, titleText, infoText, true);
438+
showDialogMenu, showPersistActions, false, titleText, infoText, true);
439+
}
411440

441+
/**
442+
* Constructs a new instance of <code>PopupDialog</code>.
443+
*
444+
* @param parent The parent shell.
445+
* @param shellStyle The shell style.
446+
* @param takeFocusOnOpen A boolean indicating whether focus should be taken
447+
* by this popup when it opens.
448+
* @param persistSize A boolean indicating whether the size should be
449+
* persisted upon close of the dialog. The size can
450+
* only be persisted if the dialog settings for
451+
* persisting the bounds are also specified. If a menu
452+
* action will be provided that allows the user to
453+
* control this feature and the user hasn't changed
454+
* that setting, then this flag is used as initial
455+
* default for the menu.
456+
* @param persistLocation A boolean indicating whether the location should be
457+
* persisted upon close of the dialog. The location
458+
* can only be persisted if the dialog settings for
459+
* persisting the bounds are also specified. If a menu
460+
* action will be provided that allows the user to
461+
* control this feature and the user hasn't changed
462+
* that setting, then this flag is used as initial
463+
* default for the menu. default for the menu until
464+
* the user changed it.
465+
* @param showDialogMenu A boolean indicating whether a menu for moving and
466+
* resizing the popup should be provided.
467+
* @param showPersistActions A boolean indicating whether actions allowing the
468+
* user to control the persisting of the dialog bounds
469+
* and location should be shown in the dialog menu.
470+
* This parameter has no effect if
471+
* <code>showDialogMenu</code> is <code>false</code>.
472+
* @param showPinAction A boolean indicating whether actions allowing the
473+
* user to pin the dialog so it remains visible and
474+
* accessible when deactivated should be shown in the
475+
* dialog menu. This parameter has no effect if
476+
* <code>showDialogMenu</code> is <code>false</code>.
477+
* @param titleText Text to be shown in an upper title area, or
478+
* <code>null</code> if there is no title.
479+
* @param infoText Text to be shown in a lower info area, or
480+
* <code>null</code> if there is no info area.
481+
*
482+
* @see PopupDialog#getDialogSettings()
483+
*
484+
* @since 3.35
485+
*/
486+
public PopupDialog(Shell parent, int shellStyle, boolean takeFocusOnOpen,
487+
boolean persistSize, boolean persistLocation,
488+
boolean showDialogMenu, boolean showPersistActions, boolean showPinAction,
489+
String titleText, String infoText) {
490+
this(parent, shellStyle, takeFocusOnOpen, persistSize, persistLocation,
491+
showDialogMenu, showPersistActions, showPinAction, titleText, infoText, true);
412492
}
413493

414494
/**
415495
* Constructs a new instance of <code>PopupDialog</code>.
416496
*
417-
* @param parent
418-
* The parent shell.
419-
* @param shellStyle
420-
* The shell style.
421-
* @param takeFocusOnOpen
422-
* A boolean indicating whether focus should be taken by this
423-
* popup when it opens.
424-
* @param persistSize
425-
* A boolean indicating whether the size should be persisted upon
426-
* close of the dialog. The size can only be persisted if the
427-
* dialog settings for persisting the bounds are also specified.
428-
* If a menu action will be provided that allows the user to
429-
* control this feature and the user hasn't changed that setting,
430-
* then this flag is used as initial default for the menu.
431-
* @param persistLocation
432-
* A boolean indicating whether the location should be persisted
433-
* upon close of the dialog. The location can only be persisted
434-
* if the dialog settings for persisting the bounds are also
435-
* specified. If a menu action will be provided that allows the
436-
* user to control this feature and the user hasn't changed that
437-
* setting, then this flag is used as initial default for the
438-
* menu. default for the menu until the user changed it.
439-
* @param showDialogMenu
440-
* A boolean indicating whether a menu for moving and resizing
441-
* the popup should be provided.
442-
* @param showPersistActions
443-
* A boolean indicating whether actions allowing the user to
444-
* control the persisting of the dialog bounds and location
445-
* should be shown in the dialog menu. This parameter has no
446-
* effect if <code>showDialogMenu</code> is <code>false</code>.
447-
* @param titleText
448-
* Text to be shown in an upper title area, or <code>null</code>
449-
* if there is no title.
450-
* @param infoText
451-
* Text to be shown in a lower info area, or <code>null</code>
452-
* if there is no info area.
453-
* @param use34API
454-
* <code>true</code> if 3.4 API should be used
497+
* @param parent The parent shell.
498+
* @param shellStyle The shell style.
499+
* @param takeFocusOnOpen A boolean indicating whether focus should be taken
500+
* by this popup when it opens.
501+
* @param persistSize A boolean indicating whether the size should be
502+
* persisted upon close of the dialog. The size can
503+
* only be persisted if the dialog settings for
504+
* persisting the bounds are also specified. If a menu
505+
* action will be provided that allows the user to
506+
* control this feature and the user hasn't changed
507+
* that setting, then this flag is used as initial
508+
* default for the menu.
509+
* @param persistLocation A boolean indicating whether the location should be
510+
* persisted upon close of the dialog. The location
511+
* can only be persisted if the dialog settings for
512+
* persisting the bounds are also specified. If a menu
513+
* action will be provided that allows the user to
514+
* control this feature and the user hasn't changed
515+
* that setting, then this flag is used as initial
516+
* default for the menu. default for the menu until
517+
* the user changed it.
518+
* @param showDialogMenu A boolean indicating whether a menu for moving and
519+
* resizing the popup should be provided.
520+
* @param showPersistActions A boolean indicating whether actions allowing the
521+
* user to control the persisting of the dialog bounds
522+
* and location should be shown in the dialog menu.
523+
* This parameter has no effect if
524+
* <code>showDialogMenu</code> is <code>false</code>.
525+
* @param showPinAction A boolean indicating whether actions allowing the
526+
* user to pin the dialog so it remains visible and
527+
* accessible when deactivated should be shown in the
528+
* dialog menu. This parameter has no effect if
529+
* <code>showDialogMenu</code> is <code>false</code>.
530+
* @param titleText Text to be shown in an upper title area, or
531+
* <code>null</code> if there is no title.
532+
* @param infoText Text to be shown in a lower info area, or
533+
* <code>null</code> if there is no info area.
534+
* @param use34API <code>true</code> if 3.4 API should be used
455535
*
456536
* @see PopupDialog#getDialogSettings()
457537
*
@@ -460,6 +540,7 @@ public PopupDialog(Shell parent, int shellStyle, boolean takeFocusOnOpen,
460540
private PopupDialog(Shell parent, int shellStyle, boolean takeFocusOnOpen,
461541
boolean persistSize, boolean persistLocation,
462542
boolean showDialogMenu, boolean showPersistActions,
543+
boolean showPinAction,
463544
String titleText, String infoText, boolean use34API) {
464545
super(parent);
465546
// 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,
477558
this.takeFocusOnOpen = takeFocusOnOpen;
478559
this.showDialogMenu = showDialogMenu;
479560
this.showPersistActions = showPersistActions;
561+
this.showPinAction = showPinAction;
480562
this.titleText = titleText;
481563
this.infoText = infoText;
482564

@@ -504,7 +586,7 @@ protected void configureShell(Shell shell) {
504586
* the asyncClose() call is disabled in GTK. See Eclipse Bugs
505587
* 466500 and 113577 for more information.
506588
*/
507-
if (listenToDeactivate && event.widget == getShell()
589+
if (!pinDialog && listenToDeactivate && event.widget == getShell()
508590
&& getShell().getShells().length == 0) {
509591
if (!Util.isGtk()) {
510592
asyncClose();
@@ -538,7 +620,7 @@ && getShell().getShells().length == 0) {
538620
if (parent != null) {
539621
if ((getShellStyle() & SWT.ON_TOP) != 0) {
540622
parentDeactivateListener = event -> {
541-
if (listenToParentDeactivate) {
623+
if (!pinDialog && listenToParentDeactivate) {
542624
asyncClose();
543625
} else {
544626
// Our first deactivate, now start listening on the Mac.
@@ -565,7 +647,7 @@ public void handleEvent(Event event) {
565647
* "Show all Instances" and "Show all References" do.
566648
* They all are InspectPopupDialog instances...
567649
*/
568-
if (event.widget != parent || !listenToDeactivate || parent.isDisposed()) {
650+
if (pinDialog || event.widget != parent || !listenToDeactivate || parent.isDisposed()) {
569651
return;
570652
}
571653
parent.removeListener(SWT.Activate, this);
@@ -893,6 +975,10 @@ protected void fillDialogMenu(IMenuManager dialogMenu) {
893975
dialogMenu.add(new PersistBoundsAction());
894976
}
895977
}
978+
if (this.showPinAction) {
979+
dialogMenu.add(new PinAction());
980+
}
981+
dialogMenu.add(new CloseAction());
896982
dialogMenu.add(new Separator("SystemMenuEnd")); //$NON-NLS-1$
897983
}
898984

@@ -1524,4 +1610,5 @@ private void handleDispose() {
15241610
}
15251611
titleFont = null;
15261612
}
1613+
15271614
}

bundles/org.eclipse.jface/src/org/eclipse/jface/messages.properties

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ PopupDialog.move = &Move
130130
PopupDialog.persistBounds = R&emember Size and Location
131131
PopupDialog.persistSize = Remember Si&ze
132132
PopupDialog.persistLocation = Remember &Location
133+
PopupDialog.pinDialog = &Pin Dialog
134+
PopupDialog.close = &Close
133135
PopupDialog.menuTooltip = Menu
134136

135137
############################################################

0 commit comments

Comments
 (0)