Skip to content

Commit 593ce9a

Browse files
committed
Improve No Recent Launch Dialog
This commit add an additional Run/Debug Launch config button to quickly open corresponding launch group from the dialog instead of closing and clicking the drop down to navigate the same
1 parent f9d3dc8 commit 593ce9a

3 files changed

Lines changed: 72 additions & 6 deletions

File tree

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextMessages.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2007, 2012 IBM Corporation and others.
2+
* Copyright (c) 2007, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -31,6 +31,7 @@ public class ContextMessages extends NLS {
3131
public static String ContextRunner_7;
3232
public static String LaunchingResourceManager_0;
3333
public static String LaunchingResourceManager_1;
34+
public static String OpenLaunchConfigButton;
3435
static {
3536
// initialize resource bundle
3637
NLS.initializeMessages(BUNDLE_NAME, ContextMessages.class);

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextMessages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###############################################################################
2-
# Copyright (c) 2007, 2012 IBM Corporation and others.
2+
# Copyright (c) 2007, 2026 IBM Corporation and others.
33
#
44
# This program and the accompanying materials
55
# are made available under the terms of the Eclipse Public License 2.0
@@ -18,6 +18,7 @@ ContextRunner_13=The resource ''{0}'' is not accessible for launching
1818
ContextRunner_14=As...
1919
ContextRunner_15=...
2020
ContextRunner_1={0} Not Supported
21+
OpenLaunchConfigButton=Open {0} Configuration
2122

2223
#The possible values for {0} are the names of the launch configurations in the current workspace
2324
LaunchingResourceManager_0={0} (already running)

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextRunner.java

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2007, 2025 IBM Corporation and others.
2+
* Copyright (c) 2007, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -38,6 +38,9 @@
3838
import org.eclipse.jface.viewers.IStructuredSelection;
3939
import org.eclipse.jface.viewers.StructuredSelection;
4040
import org.eclipse.jface.window.Window;
41+
import org.eclipse.osgi.util.NLS;
42+
import org.eclipse.swt.graphics.Image;
43+
import org.eclipse.swt.widgets.Shell;
4144
import org.eclipse.ui.IEditorPart;
4245

4346
/**
@@ -153,7 +156,9 @@ else if(esize > 1) {
153156
else if(esize < 1) {
154157
if(DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_LAUNCH_LAST_IF_NOT_LAUNCHABLE)) {
155158
if (!launchLast(group, isShift)) {
156-
MessageDialog.openInformation(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_0, ContextMessages.ContextRunner_7);
159+
openNoRecentLaunchDialog(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_7, mode,
160+
group.getIdentifier());
161+
157162
}
158163
} else {
159164
if(resource != null) {
@@ -166,12 +171,13 @@ else if(esize < 1) {
166171
if(!resource.isAccessible()) {
167172
msg = MessageFormat.format(ContextMessages.ContextRunner_13, resource.getName());
168173
}
169-
MessageDialog.openInformation(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_0, msg);
174+
openNoRecentLaunchDialog(DebugUIPlugin.getShell(), msg, mode, group.getIdentifier());
170175
}
171176
}
172177
else {
173178
if (!launchLast(group, isShift)) {
174-
MessageDialog.openInformation(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_0, ContextMessages.ContextRunner_7);
179+
openNoRecentLaunchDialog(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_7,
180+
mode, group.getIdentifier());
175181
}
176182
}
177183
}
@@ -188,6 +194,64 @@ else if(csize > 1){
188194
}
189195
}
190196

197+
/**
198+
* Returns the label for the launch configuration button based on the given
199+
* launch mode.
200+
*
201+
* @param launchMode launch mode identifier (e.g., run or debug)
202+
* @return the corresponding button label for opening the launch configuration
203+
* dialog
204+
*/
205+
private String launchButtonName(String launchMode) {
206+
String config = launchMode.substring(0, 1).toUpperCase() + launchMode.substring(1);
207+
return NLS.bind(ContextMessages.OpenLaunchConfigButton, config);
208+
}
209+
210+
/**
211+
* Opens a dialog informing the user that no recent launch configuration is
212+
* available. The dialog provides an option to proceed with opening launch
213+
* configuration using the given mode.
214+
*
215+
* @param shell the parent {@link Shell} for the dialog
216+
* @param message the message to be displayed in the dialog
217+
* @param mode the launch mode (e.g., run or debug) used to
218+
* determine the button label
219+
* @param launchIdentifier an identifier associated with the launch, used for
220+
* handling the action
221+
*/
222+
private void openNoRecentLaunchDialog(Shell shell, String message, String mode, String launchIdentifier) {
223+
LaunchFailedDialog launchDialog = new LaunchFailedDialog(shell,
224+
ContextMessages.ContextRunner_0, null, message, MessageDialog.INFORMATION,
225+
new String[] { launchButtonName(mode), IDialogConstants.OK_LABEL }, launchIdentifier);
226+
launchDialog.open();
227+
}
228+
/**
229+
* Custom dialog shown when a launch fails with no recent configurations.
230+
* Provides an option to directly open the corresponding launch configuration
231+
* group.
232+
*/
233+
private static class LaunchFailedDialog extends MessageDialog {
234+
235+
private final String launchGroup;
236+
237+
LaunchFailedDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage,
238+
int dialogImageType, String[] dialogButtonLabels, String launchGroup) {
239+
super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, 1);
240+
this.launchGroup = launchGroup;
241+
}
242+
243+
@Override
244+
protected void buttonPressed(int buttonId) {
245+
if (buttonId == 0) {
246+
DebugUITools.openLaunchConfigurationDialogOnGroup(getShell(), null, launchGroup);
247+
setReturnCode(buttonId);
248+
close();
249+
return;
250+
}
251+
super.buttonPressed(buttonId);
252+
}
253+
}
254+
191255
/**
192256
* Validates the given launch mode and launches.
193257
*

0 commit comments

Comments
 (0)