Skip to content

Commit 75b8bca

Browse files
SougandhSlaeubi
authored andcommitted
Fix Add to run/debug favorite not showing
This commit fixes Add to run/debug favorite not showing in launch contexts and updates labels for launches if its already exists in run/debug config
1 parent ba9634b commit 75b8bca

File tree

4 files changed

+37
-28
lines changed

4 files changed

+37
-28
lines changed

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IDebugHelpContextIds.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2017 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 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
@@ -81,6 +81,7 @@ public interface IDebugHelpContextIds {
8181
String DEBUG_TOOLBAR_VIEW_ACTION = PREFIX + "debug_toolbar_view_action_context"; //$NON-NLS-1$
8282
String DEBUG_TOOLBAR_WINDOW_ACTION = PREFIX + "debug_toolbar_window_action_context"; //$NON-NLS-1$
8383
String DEBUG_TOOLBAR_BOTH_ACTION = PREFIX + "debug_toolbar_both_action_context"; //$NON-NLS-1$
84+
String ADD_LAUNCH_CONFIGURATION_TO_FAV_ACTION = PREFIX + "Add_launch_configuration_to_favorites_action_context"; //$NON-NLS-1$
8485

8586
// Views
8687
String DEBUG_VIEW = PREFIX + "debug_view_context"; //$NON-NLS-1$

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,6 @@ public class ActionMessages extends NLS {
253253
public static String EnableAllBreakpointsAction_1;
254254
public static String EnableAllBreakpointsAction_3;
255255
public static String BreakpointLabelDialog;
256+
public static String RemoveFromFavoritesAction;
256257

257258
}

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
AddToFavoritesAction_1=Add to {0} &Favorites
1717
AddToFavoritesAction_2=Error
1818
AddToFavoritesAction_3=Unable to add to favorites.
19+
RemoveFromFavoritesAction=Remove from {0} Favorites
1920

2021
ChangeVariableValue_errorDialogMessage=Setting the value failed.
2122
ChangeVariableValue_errorDialogTitle=Setting Value

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AddToFavoritesAction.java

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2018 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 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
@@ -52,7 +52,8 @@ public class AddToFavoritesAction extends SelectionListenerAction {
5252
public AddToFavoritesAction() {
5353
super(IInternalDebugCoreConstants.EMPTY_STRING);
5454
setEnabled(false);
55-
PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.EDIT_LAUNCH_CONFIGURATION_ACTION);
55+
PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
56+
IDebugHelpContextIds.ADD_LAUNCH_CONFIGURATION_TO_FAV_ACTION);
5657
}
5758

5859
/**
@@ -66,29 +67,42 @@ protected boolean updateSelection(IStructuredSelection selection) {
6667
if (selection.size() == 1) {
6768
Object object = selection.getFirstElement();
6869
ILaunch launch = null;
69-
if (object instanceof IAdaptable) {
70-
launch = ((IAdaptable)object).getAdapter(ILaunch.class);
70+
if (object instanceof IAdaptable iAdaptable) {
71+
launch = iAdaptable.getAdapter(ILaunch.class);
7172
}
7273
if (launch == null) {
73-
if (object instanceof ILaunch) {
74-
launch = (ILaunch)object;
75-
} else if (object instanceof IDebugElement) {
76-
launch = ((IDebugElement)object).getLaunch();
77-
} else if (object instanceof IProcess) {
78-
launch = ((IProcess)object).getLaunch();
74+
if (object instanceof ILaunch iLaunch) {
75+
launch = iLaunch;
76+
} else if (object instanceof IDebugElement iDebugElement) {
77+
launch = iDebugElement.getLaunch();
78+
} else if (object instanceof IProcess iProcess) {
79+
launch = iProcess.getLaunch();
7980
}
8081
}
8182
if (launch != null) {
8283
ILaunchConfiguration configuration = launch.getLaunchConfiguration();
8384
if (configuration != null) {
84-
ILaunchGroup group= DebugUITools.getLaunchGroup(configuration, getMode());
85+
ILaunchGroup group = DebugUITools.getLaunchGroup(configuration, launch.getLaunchMode());
8586
if (group == null) {
8687
return false;
8788
}
8889
setGroup(group);
8990
setLaunchConfiguration(configuration);
9091
setMode(launch.getLaunchMode());
91-
setText(MessageFormat.format(ActionMessages.AddToFavoritesAction_1, DebugUIPlugin.removeAccelerators(getGroup().getLabel())));
92+
try {
93+
List<String> favoriteGroups = configuration.getAttribute(IDebugUIConstants.ATTR_FAVORITE_GROUPS,
94+
new ArrayList<>());
95+
if (favoriteGroups.contains(group.getIdentifier())) {
96+
setText(MessageFormat.format(ActionMessages.RemoveFromFavoritesAction,
97+
fMode.substring(0, 1).toUpperCase() + fMode.substring(1)));
98+
} else {
99+
setText(MessageFormat.format(ActionMessages.AddToFavoritesAction_1,
100+
DebugUIPlugin.removeAccelerators(
101+
fMode.substring(0, 1).toUpperCase() + fMode.substring(1))));
102+
}
103+
} catch (CoreException e) {
104+
DebugUIPlugin.log(e);
105+
}
92106
}
93107
}
94108
}
@@ -101,20 +115,7 @@ protected boolean updateSelection(IStructuredSelection selection) {
101115
if (DebugUITools.isPrivate(config)) {
102116
return false;
103117
}
104-
105-
if (getGroup() != null) {
106-
try {
107-
List<String> groups = config.getAttribute(IDebugUIConstants.ATTR_FAVORITE_GROUPS, (List<String>) null);
108-
if (groups != null) {
109-
return !groups.contains(getGroup().getIdentifier());
110-
}
111-
return true;
112-
} catch (CoreException e) {
113-
}
114-
115-
}
116-
117-
return false;
118+
return true;
118119
}
119120

120121
/**
@@ -177,7 +178,12 @@ public void run() {
177178
if (list == null) {
178179
list = new ArrayList<>();
179180
}
180-
list.add(getGroup().getIdentifier());
181+
String groupIdentifier = getGroup().getIdentifier();
182+
if (list.contains(groupIdentifier)) {
183+
list.remove(groupIdentifier);
184+
} else {
185+
list.add(groupIdentifier);
186+
}
181187
ILaunchConfigurationWorkingCopy copy = getLaunchConfiguration().getWorkingCopy();
182188
copy.setAttribute(IDebugUIConstants.ATTR_FAVORITE_GROUPS, list);
183189
copy.doSave();

0 commit comments

Comments
 (0)