Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -31,14 +32,17 @@
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;
import org.eclipse.jface.viewers.IStructuredContentProvider;
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;
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -398,10 +453,7 @@ protected IStatus run(IProgressMonitor monitor) {
monitor.worked(1);
}

// update added favorites
Iterator<ILaunchConfiguration> favs = current.iterator();
while (favs.hasNext()) {
ILaunchConfiguration configuration = favs.next();
for (ILaunchConfiguration configuration : current) {
try {
List<String> groups = configuration.getAttribute(IDebugUIConstants.ATTR_FAVORITE_GROUPS, (List<String>) null);
if (groups == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading