From 93df81afa7f4852f32f8836cbfa887f76d9c4463 Mon Sep 17 00:00:00 2001 From: Sougandh S Date: Mon, 6 Apr 2026 10:59:53 +0530 Subject: [PATCH] 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 --- .../ui/contextlaunching/ContextMessages.java | 3 +- .../ContextMessages.properties | 3 +- .../ui/contextlaunching/ContextRunner.java | 72 +++++++++++++++++-- 3 files changed, 72 insertions(+), 6 deletions(-) diff --git a/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextMessages.java b/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextMessages.java index 1cfa71d5917..8f4a4f64440 100644 --- a/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextMessages.java +++ b/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 IBM Corporation and others. + * Copyright (c) 2007, 2026 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -31,6 +31,7 @@ public class ContextMessages extends NLS { public static String ContextRunner_7; public static String LaunchingResourceManager_0; public static String LaunchingResourceManager_1; + public static String OpenLaunchConfigButton; static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, ContextMessages.class); diff --git a/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextMessages.properties b/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextMessages.properties index d37c86f45b1..33816e00e94 100644 --- a/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextMessages.properties +++ b/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2007, 2012 IBM Corporation and others. +# Copyright (c) 2007, 2026 IBM Corporation and others. # # This program and the accompanying materials # 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 ContextRunner_14=As... ContextRunner_15=... ContextRunner_1={0} Not Supported +OpenLaunchConfigButton=Open {0} Configuration #The possible values for {0} are the names of the launch configurations in the current workspace LaunchingResourceManager_0={0} (already running) diff --git a/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextRunner.java b/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextRunner.java index 978bc0f26fb..46d3b37a6ed 100644 --- a/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextRunner.java +++ b/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/contextlaunching/ContextRunner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2025 IBM Corporation and others. + * Copyright (c) 2007, 2026 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -38,6 +38,9 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.window.Window; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorPart; /** @@ -153,7 +156,9 @@ else if(esize > 1) { else if(esize < 1) { if(DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_LAUNCH_LAST_IF_NOT_LAUNCHABLE)) { if (!launchLast(group, isShift)) { - MessageDialog.openInformation(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_0, ContextMessages.ContextRunner_7); + openNoRecentLaunchDialog(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_7, mode, + group.getIdentifier()); + } } else { if(resource != null) { @@ -166,12 +171,13 @@ else if(esize < 1) { if(!resource.isAccessible()) { msg = MessageFormat.format(ContextMessages.ContextRunner_13, resource.getName()); } - MessageDialog.openInformation(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_0, msg); + openNoRecentLaunchDialog(DebugUIPlugin.getShell(), msg, mode, group.getIdentifier()); } } else { if (!launchLast(group, isShift)) { - MessageDialog.openInformation(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_0, ContextMessages.ContextRunner_7); + openNoRecentLaunchDialog(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_7, + mode, group.getIdentifier()); } } } @@ -188,6 +194,64 @@ else if(csize > 1){ } } + /** + * Returns the label for the launch configuration button based on the given + * launch mode. + * + * @param launchMode launch mode identifier (e.g., run or debug) + * @return the corresponding button label for opening the launch configuration + * dialog + */ + private String launchButtonName(String launchMode) { + String config = launchMode.substring(0, 1).toUpperCase() + launchMode.substring(1); + return NLS.bind(ContextMessages.OpenLaunchConfigButton, config); + } + + /** + * Opens a dialog informing the user that no recent launch configuration is + * available. The dialog provides an option to proceed with opening launch + * configuration using the given mode. + * + * @param shell the parent {@link Shell} for the dialog + * @param message the message to be displayed in the dialog + * @param mode the launch mode (e.g., run or debug) used to + * determine the button label + * @param launchIdentifier an identifier associated with the launch, used for + * handling the action + */ + private void openNoRecentLaunchDialog(Shell shell, String message, String mode, String launchIdentifier) { + LaunchFailedDialog launchDialog = new LaunchFailedDialog(shell, + ContextMessages.ContextRunner_0, null, message, MessageDialog.INFORMATION, + new String[] { launchButtonName(mode), IDialogConstants.OK_LABEL }, launchIdentifier); + launchDialog.open(); + } + /** + * Custom dialog shown when a launch fails with no recent configurations. + * Provides an option to directly open the corresponding launch configuration + * group. + */ + private static class LaunchFailedDialog extends MessageDialog { + + private final String launchGroup; + + LaunchFailedDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage, + int dialogImageType, String[] dialogButtonLabels, String launchGroup) { + super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, 1); + this.launchGroup = launchGroup; + } + + @Override + protected void buttonPressed(int buttonId) { + if (buttonId == 0) { + DebugUITools.openLaunchConfigurationDialogOnGroup(getShell(), null, launchGroup); + setReturnCode(buttonId); + close(); + return; + } + super.buttonPressed(buttonId); + } + } + /** * Validates the given launch mode and launches. *