From e12099fa0a44a43e3ae959830cebe6405074c278 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 | 4 +- .../ContextMessages.properties | 4 +- .../ui/contextlaunching/ContextRunner.java | 65 +++++++++++++++++-- 3 files changed, 67 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..d333948ac5d 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,8 @@ public class ContextMessages extends NLS { public static String ContextRunner_7; public static String LaunchingResourceManager_0; public static String LaunchingResourceManager_1; + public static String OpenDebugConfigButton; + public static String OpenRunConfigButton; 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..e0086492808 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,8 @@ ContextRunner_13=The resource ''{0}'' is not accessible for launching ContextRunner_14=As... ContextRunner_15=... ContextRunner_1={0} Not Supported +OpenDebugConfigButton=Open Debug Config +OpenRunConfigButton=Open Run Config #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..5d5fa676a55 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 @@ -22,6 +22,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.ILaunchMode; import org.eclipse.debug.internal.ui.DebugUIPlugin; import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; @@ -38,6 +39,8 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.window.Window; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorPart; /** @@ -153,7 +156,12 @@ 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); + LaunchFailedDialog launchDialog = new LaunchFailedDialog(DebugUIPlugin.getShell(), + ContextMessages.ContextRunner_0, null, ContextMessages.ContextRunner_7, + MessageDialog.INFORMATION, + new String[] { launchButtonName(mode), IDialogConstants.OK_LABEL }, + group.getIdentifier()); + launchDialog.open(); } } else { if(resource != null) { @@ -166,12 +174,21 @@ else if(esize < 1) { if(!resource.isAccessible()) { msg = MessageFormat.format(ContextMessages.ContextRunner_13, resource.getName()); } - MessageDialog.openInformation(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_0, msg); + LaunchFailedDialog launchDialog = new LaunchFailedDialog(DebugUIPlugin.getShell(), + ContextMessages.ContextRunner_0, null, msg, MessageDialog.INFORMATION, + new String[] { launchButtonName(mode), IDialogConstants.OK_LABEL }, + group.getIdentifier()); + launchDialog.open(); } } else { if (!launchLast(group, isShift)) { - MessageDialog.openInformation(DebugUIPlugin.getShell(), ContextMessages.ContextRunner_0, ContextMessages.ContextRunner_7); + LaunchFailedDialog launchDialog = new LaunchFailedDialog(DebugUIPlugin.getShell(), + ContextMessages.ContextRunner_0, null, ContextMessages.ContextRunner_7, + MessageDialog.INFORMATION, + new String[] { launchButtonName(mode), IDialogConstants.OK_LABEL }, + group.getIdentifier()); + launchDialog.open(); } } } @@ -188,6 +205,46 @@ 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) { + if (ILaunchManager.DEBUG_MODE.equals(launchMode)) { + return ContextMessages.OpenDebugConfigButton; + } + return ContextMessages.OpenRunConfigButton; + } + + /** + * Custom dialog shown when a launch fails with no recent configurations. + * Provides an option to directly open the corresponding launch configuration + * group. + */ + class LaunchFailedDialog extends MessageDialog { + + private 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) { + super.buttonPressed(buttonId); + if (buttonId == 0) { + DebugUITools.openLaunchConfigurationDialogOnGroup(getShell(), null, launchGroup); + close(); + } + } + } + /** * Validates the given launch mode and launches. *