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