diff --git a/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/FavoritesDialog.java b/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/FavoritesDialog.java index f0e07f82662..4e1cb709d46 100644 --- a/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/FavoritesDialog.java +++ b/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/FavoritesDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2018 IBM Corporation and others. + * Copyright (c) 2000, 2026 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -15,6 +15,7 @@ import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -31,7 +32,9 @@ import org.eclipse.debug.internal.ui.SWTFactory; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.TrayDialog; import org.eclipse.jface.viewers.IContentProvider; import org.eclipse.jface.viewers.ISelectionChangedListener; @@ -39,6 +42,7 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; import org.eclipse.swt.events.KeyAdapter; import org.eclipse.swt.events.KeyEvent; @@ -155,6 +159,57 @@ protected void handleAddConfigButtonSelected() { } } + /** + * Returns whether the favorites have been modified. + * + * @return whether there are unsaved changes + */ + private boolean isDirty() { + return !Arrays.equals(getInitialFavorites(), getArray(getFavorites())); + } + + @Override + protected void cancelPressed() { + if (confirmSaveBeforeClose()) { + super.cancelPressed(); + } + } + + @Override + protected void handleShellCloseEvent() { + if (confirmSaveBeforeClose()) { + super.handleShellCloseEvent(); + } + } + + /** + * Prompts to save changes before closing the dialog. + * + * @return whether the dialog should be closed + */ + private boolean confirmSaveBeforeClose() { + if (!isDirty()) { + return true; + } + + MessageDialog dialog = new MessageDialog(getShell(), + LaunchConfigurationsMessages.FavoritesDialogPromptOnCloseTitle, null, + LaunchConfigurationsMessages.FavoritesDialogPromptOnClose, MessageDialog.QUESTION, + new String[] { LaunchConfigurationsMessages.FavoritesDialogPromptOnCloseSaveButton, + IDialogConstants.CANCEL_LABEL }, + 0); + + int option = dialog.open(); + if (option == Window.OK) { + saveFavorites(); + return true; + } + if (option == Window.CANCEL) { + return true; + } + return false; + } + /** * The 'remove favorites' button has been pressed */ @@ -398,10 +453,7 @@ protected IStatus run(IProgressMonitor monitor) { monitor.worked(1); } - // update added favorites - Iterator favs = current.iterator(); - while (favs.hasNext()) { - ILaunchConfiguration configuration = favs.next(); + for (ILaunchConfiguration configuration : current) { try { List groups = configuration.getAttribute(IDebugUIConstants.ATTR_FAVORITE_GROUPS, (List) null); if (groups == null) { diff --git a/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java b/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java index 75fa195c5dc..dc57ef58dba 100644 --- a/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java +++ b/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java @@ -319,4 +319,10 @@ public class LaunchConfigurationsMessages extends NLS { public static String QuickGroupLaunchActionToolTip; + public static String FavoritesDialogPromptOnClose; + + public static String FavoritesDialogPromptOnCloseTitle; + + public static String FavoritesDialogPromptOnCloseSaveButton; + } diff --git a/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties b/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties index 5418d644fcc..d10b5c8e813 100644 --- a/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties +++ b/debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties @@ -258,6 +258,9 @@ FavoritesDialog_6=Do&wn FavoritesDialog_7=Select &Launch Configurations: FavoritesDialog_0=Add {0} Favorites FavoritesDialog_8=Updating Favorites... +FavoritesDialogPromptOnClose=Save changes to your favorite launches before closing? +FavoritesDialogPromptOnCloseTitle=Save Changes +FavoritesDialogPromptOnCloseSaveButton=Save OrganizeFavoritesAction_0=Organize Fa&vorites... PerspectiveManager_12=Confirm Perspective Switch