Skip to content

Commit

Permalink
Use proper shell for modal dialogs
Browse files Browse the repository at this point in the history
This prevents the dialogs to appear behind the possible opened progress
dialog (or any other modal dialog).

Fixes eclipse-platform#1373
  • Loading branch information
iloveeclipse committed May 16, 2024
1 parent 6cb771e commit 08f15a2
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,22 @@ public static Shell getShell() {
return null;
}

/**
* Returns shell that can be used to get the best parenting possible for a modal
* dialog, or, if there is no one, currently active workbench window shell or
* <code>null</code> if none.
*
* @return the modal shell or currently active workbench window shell or
* <code>null</code>
*/
public static Shell getShellForModalDialog() {
Shell shell = PlatformUI.getWorkbench().getModalDialogShellProvider().getShell();
if (shell == null) {
shell = getShell();
}
return shell;
}

/**
* Returns the default label provider for the debug UI.
* @return the singleton {@link DefaultLabelProvider}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Object handleStatus(IStatus status, Object source) {
DebugUIPlugin.getStandardDisplay().syncExec(() -> {
String title = DebugUIMessages.WorkingDirectoryStatusHandler_Eclipse_Runtime_1;
String message = DebugUIMessages.WorkingDirectoryStatusHandler_0;
result[0] = (MessageDialog.openQuestion(DebugUIPlugin.getShell(), title, message));
result[0] = (MessageDialog.openQuestion(DebugUIPlugin.getShellForModalDialog(), title, message));
});
return Boolean.valueOf(result[0]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.IStatusHandler;
import org.eclipse.debug.internal.ui.DebugUIMessages;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.PlatformUI;
Expand All @@ -30,7 +31,7 @@ public class GroupCycleHandler implements IStatusHandler {

@Override
public Object handleStatus(IStatus status, final Object source) throws CoreException {
PlatformUI.getWorkbench().getDisplay().asyncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DebugUIMessages.GroupLaunch_Error, NLS.bind(DebugUIMessages.GroupLaunch_Cycle, source.toString())));
PlatformUI.getWorkbench().getDisplay().asyncExec(() -> MessageDialog.openError(DebugUIPlugin.getShellForModalDialog(), DebugUIMessages.GroupLaunch_Error, NLS.bind(DebugUIMessages.GroupLaunch_Cycle, source.toString())));
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.IStatusHandler;
import org.eclipse.debug.internal.ui.DebugUIMessages;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.PlatformUI;
Expand All @@ -35,7 +36,7 @@ public Object handleStatus(IStatus status, Object source) throws CoreException {
final String[] data = (String[]) source;
PlatformUI.getWorkbench().getDisplay()
.asyncExec(() -> MessageDialog.openError(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
DebugUIPlugin.getShellForModalDialog(),
DebugUIMessages.GroupLaunch_Error,
NLS.bind(DebugUIMessages.GroupLaunch_Cannot_launch, data[0], data[1])));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Object handleStatus(IStatus status, Object source) throws CoreException {
}
}
}
Shell shell = DebugUIPlugin.getShell();
Shell shell = DebugUIPlugin.getShellForModalDialog();
StringBuilder projectList = new StringBuilder();
//we need to limit this
int size = Math.min(20, projects.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Object handleStatus(IStatus status, Object source) throws CoreException {
}
}

Shell shell = DebugUIPlugin.getShell();
Shell shell = DebugUIPlugin.getShellForModalDialog();
String title = LaunchConfigurationsMessages.CompileErrorPromptStatusHandler_0;
String message = LaunchConfigurationsMessages.CompileErrorPromptStatusHandler_1;
IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Object handleStatus(IStatus status, Object source) throws CoreException {
}
}

Shell activeShell = DebugUIPlugin.getShell();
Shell activeShell = DebugUIPlugin.getShellForModalDialog();
String title = LaunchConfigurationsMessages.DebugModePromptStatusHandler_0;
String message = LaunchConfigurationsMessages.DebugModePromptStatusHandler_1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Object handleStatus(IStatus status, Object source) throws CoreException {
if(infos.length == 2) {
ILaunchConfiguration config = (ILaunchConfiguration) infos[0];
String mode = (String) infos[1];
Shell shell = DebugUIPlugin.getShell();
Shell shell = DebugUIPlugin.getShellForModalDialog();
HashSet<String> modes = new HashSet<>();
modes.add(mode);
modes.addAll(config.getModes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Object handleStatus(IStatus status, Object source) throws CoreException {
if(infos.length == 2) {
final ILaunchConfiguration config = (ILaunchConfiguration) infos[0];
final String mode = (String) infos[1];
final Shell shell = DebugUIPlugin.getShell();
final Shell shell = DebugUIPlugin.getShellForModalDialog();
Runnable runnable = () -> {
ILaunchGroup group = DebugUITools.getLaunchGroup(config, mode);
if (group != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ protected int showSaveDialog(IProject[] projects, boolean save, boolean prompt)
if(save) {
IResource[] resources = getScopedDirtyResources(projects);
if(prompt && (resources.length > 0)) {
ScopedResourcesSelectionDialog lsd = new ScopedResourcesSelectionDialog(DebugUIPlugin.getShell(),
ScopedResourcesSelectionDialog lsd = new ScopedResourcesSelectionDialog(DebugUIPlugin.getShellForModalDialog(),
new AdaptableList(resources),
new WorkbenchContentProvider(),
new SaveResourceDialogWorkbenchLabelProvider());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Object resolveSourceElement(List<?> sources) {
} else if(sources.isEmpty()) {
return null;
}
ElementListSelectionDialog dialog = new ElementListSelectionDialog(DebugUIPlugin.getShell(), new SourceElementLabelProvider());
ElementListSelectionDialog dialog = new ElementListSelectionDialog(DebugUIPlugin.getShellForModalDialog(), new SourceElementLabelProvider());
dialog.setMultipleSelection(false);
dialog.setTitle(SourceLookupUIMessages.ResolveDuplicatesHandler_0);
dialog.setMessage(SourceLookupUIMessages.ResolveDuplicatesHandler_1);
Expand Down

0 comments on commit 08f15a2

Please sign in to comment.