Skip to content

Commit ddce6f4

Browse files
committed
Add Toggle to Sort LaunchConfigurations by most recent launch
Adds a check-box toolbar action to the Launch Configurations dialog that toggles the tree sort order between alphabetical-by-type (the existing default) and most-recently-launched within each type group.The number of configurations considered "recent" is governed by the existing "Maximum number of launch history items" preference, so users who increase that limit will see a broader recency-based sort order.
1 parent 29df77f commit ddce6f4

9 files changed

Lines changed: 162 additions & 4 deletions

‎debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPreferenceInitializer.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public void initializeDefaultPreferences() {
6969
prefs.setDefault(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH, true);
7070
prefs.setDefault(IInternalDebugUIConstants.PREF_LAUNCH_PARENT_PROJECT, false);
7171
prefs.setDefault(IInternalDebugUIConstants.PREF_LAUNCH_LAST_IF_NOT_LAUNCHABLE, true);
72+
prefs.setDefault(IInternalDebugUIConstants.PREF_LAUNCHCONFIG_SORT_ON_RECENT, false);
7273

7374
prefs.setDefault(IInternalDebugUIConstants.PREF_TERMINATE_AND_RELAUNCH_LAUNCH_ACTION, false);
7475
prefs.setDefault(IInternalDebugUIConstants.PREF_BREAKPOINT_SORTING_ORDER,

‎debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/IInternalDebugUIConstants.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,4 +435,11 @@ public interface IInternalDebugUIConstants {
435435
*/
436436
String EXPRESSION_PASTE_AS_MULTI = "org.eclipse.debug.ui.expression.paste.multi"; //$NON-NLS-1$
437437

438+
/**
439+
* String indicating sorting order of launch configurations in
440+
* LaunchConfigurations View
441+
*
442+
*/
443+
String PREF_LAUNCHCONFIG_SORT_ON_RECENT = IDebugUIConstants.PLUGIN_ID + ".PREF_LAUNCHCONFIG_SORT_ON_RECENT"; //$NON-NLS-1$
444+
438445
}

‎debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationComparator.java‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2007, 2015 IBM Corporation and others.
2+
* Copyright (c) 2007, 2026 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
@@ -24,6 +24,8 @@
2424
import org.eclipse.debug.core.DebugPlugin;
2525
import org.eclipse.debug.core.ILaunchConfiguration;
2626
import org.eclipse.debug.core.ILaunchConfigurationType;
27+
import org.eclipse.debug.internal.ui.DebugUIPlugin;
28+
import org.eclipse.jface.viewers.Viewer;
2729
import org.eclipse.ui.model.WorkbenchViewerComparator;
2830

2931
/**
@@ -37,6 +39,20 @@ public class LaunchConfigurationComparator extends WorkbenchViewerComparator {
3739
* the map of categories of <code>ILaunchConfigurationType</code>s to <code>Integer</code>s entries
3840
*/
3941
private static Map<ILaunchConfigurationType, Integer> fgCategories;
42+
private Map<ILaunchConfiguration, Integer> recentLaunches = new HashMap<>();
43+
44+
public LaunchConfigurationComparator(String groupIdentifier) {
45+
LaunchHistory history = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchHistory(groupIdentifier);
46+
if (history != null) {
47+
ILaunchConfiguration[] launches = history.getCompleteLaunchHistory();
48+
for (int i = 0; i < launches.length; i++) {
49+
recentLaunches.put(launches[i], Integer.valueOf(i));
50+
}
51+
}
52+
}
53+
54+
public LaunchConfigurationComparator() {
55+
}
4056

4157
/**
4258
* @see org.eclipse.jface.viewers.ViewerComparator#category(java.lang.Object)
@@ -56,6 +72,32 @@ public int category(Object element) {
5672
return map.size();
5773
}
5874

75+
@Override
76+
public int compare(Viewer viewer, Object e1, Object e2) {
77+
if (e1 instanceof ILaunchConfiguration c1 && e2 instanceof ILaunchConfiguration c2) {
78+
int category1 = category(c1);
79+
int category2 = category(c2);
80+
if (category1 != category2) {
81+
return category1 - category2;
82+
}
83+
Integer recent1 = recentLaunches.get(c1);
84+
Integer recent2 = recentLaunches.get(c2);
85+
if (recent1 != null || recent2 != null) {
86+
if (recent1 == null) {
87+
return 1;
88+
}
89+
if (recent2 == null) {
90+
return -1;
91+
}
92+
int result = recent1.compareTo(recent2);
93+
if (result != 0) {
94+
return result;
95+
}
96+
}
97+
}
98+
return super.compare(viewer, e1, e2);
99+
}
100+
59101
/**
60102
* Returns the map of categories
61103
* @return the map of categories

‎debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationFilteredTree.java‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.eclipse.debug.internal.core.IInternalDebugCoreConstants;
2222
import org.eclipse.debug.internal.ui.DebugUIPlugin;
2323
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
24+
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
2425
import org.eclipse.debug.ui.DebugUITools;
2526
import org.eclipse.debug.ui.ILaunchGroup;
2627
import org.eclipse.help.HelpSystem;
@@ -76,8 +77,17 @@ public LaunchConfigurationFilteredTree(Composite parent, int treeStyle, PatternF
7677
@Override
7778
protected TreeViewer doCreateTreeViewer(Composite cparent, int style) {
7879
treeViewer = new LaunchConfigurationViewer(cparent, style);
79-
treeViewer.setLabelProvider(new DecoratingLabelProvider(DebugUITools.newDebugModelPresentation(), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()));
80-
treeViewer.setComparator(new WorkbenchViewerComparator());
80+
81+
treeViewer.setLabelProvider(new DecoratingLabelProvider(DebugUITools.newDebugModelPresentation(),
82+
PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()));
83+
boolean sortByRecent = DebugUIPlugin.getDefault().getPreferenceStore()
84+
.getBoolean(IInternalDebugUIConstants.PREF_LAUNCHCONFIG_SORT_ON_RECENT);
85+
86+
if (sortByRecent) {
87+
treeViewer.setComparator(new LaunchConfigurationComparator(fLaunchGroup.getIdentifier()));
88+
} else {
89+
treeViewer.setComparator(new WorkbenchViewerComparator());
90+
}
8191
treeViewer.setContentProvider(new LaunchConfigurationTreeContentProvider(fLaunchGroup.getMode(), cparent.getShell()));
8292
treeViewer.addFilter(new LaunchGroupFilter(fLaunchGroup));
8393
treeViewer.setUseHashlookup(true);
@@ -225,4 +235,8 @@ protected void updateToolbar(boolean visible) {
225235
getLaunchConfigurationViewer().filterChanged();
226236
}
227237

238+
public ILaunchGroup getLaunchGroup() {
239+
return fLaunchGroup;
240+
}
241+
228242
}

‎debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationView.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ public class LaunchConfigurationView extends AbstractDebugView implements ILaunc
9696
*/
9797
private FilterLaunchConfigurationAction fFilterAction;
9898

99+
private SortLaunchConfigurationAction sort;
100+
99101
/**
100102
* This label is used to notify users that items (possibly) have been filtered from the
101103
* launch configuration view
@@ -225,6 +227,9 @@ protected void createActions() {
225227
fFilterAction = new FilterLaunchConfigurationAction();
226228
setAction(FilterLaunchConfigurationAction.ID_FILTER_ACTION, fFilterAction);
227229

230+
sort = new SortLaunchConfigurationAction(fTree);
231+
setAction(SortLaunchConfigurationAction.ID_SORT_ACTION, sort);
232+
228233
fLinkPrototypeAction = new LinkPrototypeAction(getViewer(), getLaunchGroup().getMode());
229234
setAction(LinkPrototypeAction.ID_LINK_PROTOTYPE_ACTION, fLinkPrototypeAction);
230235

@@ -291,6 +296,7 @@ public void dispose() {
291296
fExportAction.dispose();
292297
fImportAction.dispose();
293298
fFilterAction = null;
299+
sort = null;
294300
fCollapseAllAction = null;
295301
fLinkPrototypeAction.dispose();
296302
fUnlinkPrototypeAction.dispose();

‎debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsDialog.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ protected void createToolbarActions(ToolBarManager tmanager) {
510510
tmanager.add(new Separator());
511511
tmanager.add(getCollapseAllAction());
512512
tmanager.add(getFilterAction());
513+
tmanager.add(getSortAction());
513514
tmanager.update(true);
514515
DebugUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);
515516
}
@@ -723,6 +724,10 @@ protected IAction getFilterAction() {
723724
return fLaunchConfigurationView.getAction(FilterLaunchConfigurationAction.ID_FILTER_ACTION);
724725
}
725726

727+
protected IAction getSortAction() {
728+
return fLaunchConfigurationView.getAction(SortLaunchConfigurationAction.ID_SORT_ACTION);
729+
}
730+
726731
/**
727732
* Gets the collapse all action
728733
* @return the collapse all action

‎debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,4 +319,8 @@ public class LaunchConfigurationsMessages extends NLS {
319319

320320
public static String QuickGroupLaunchActionToolTip;
321321

322+
public static String SortLaunchConfigurationAction;
323+
324+
public static String SortLaunchConfigurationActionDesc;
325+
322326
}

‎debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,4 +289,6 @@ SelectLaunchersDialog_2=This dialog allows you to specify which launcher to use
289289
SelectLaunchersDialog_4=<a href="ws">Change Workspace Settings...</a>
290290
SelectLaunchersDialog_5=Description
291291
SelectLaunchersDialog_launchers=Launc&hers:
292-
SelectFavTypeToFilter= Type to filter
292+
SelectFavTypeToFilter= Type to filter
293+
SortLaunchConfigurationAction=Sort Launch Configurations
294+
SortLaunchConfigurationActionDesc=Sort Launch Configurations by recent launch
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 IBM Corporation and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* IBM Corporation - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.debug.internal.ui.launchConfigurations;
15+
16+
import org.eclipse.debug.internal.ui.DebugUIPlugin;
17+
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
18+
import org.eclipse.debug.ui.DebugUITools;
19+
import org.eclipse.debug.ui.IDebugUIConstants;
20+
import org.eclipse.jface.action.Action;
21+
import org.eclipse.jface.action.IAction;
22+
import org.eclipse.jface.preference.IPreferenceStore;
23+
import org.eclipse.jface.resource.ImageDescriptor;
24+
import org.eclipse.jface.viewers.TreeViewer;
25+
import org.eclipse.ui.model.WorkbenchViewerComparator;
26+
27+
/**
28+
* provides the implementation for sorting the launch configurations within the
29+
* Launch Configuration Dialog
30+
*
31+
*/
32+
public class SortLaunchConfigurationAction extends Action {
33+
34+
/**
35+
* Action identifier for IDebugView#getAction(String)
36+
*/
37+
public static final String ID_SORT_ACTION = DebugUIPlugin.getUniqueIdentifier() + ".ID_SORT_ACTION"; //$NON-NLS-1$
38+
39+
LaunchConfigurationFilteredTree fTree;
40+
41+
public SortLaunchConfigurationAction(LaunchConfigurationFilteredTree tree) {
42+
super(LaunchConfigurationsMessages.SortLaunchConfigurationAction, IAction.AS_CHECK_BOX);
43+
fTree = tree;
44+
setChecked(DebugUIPlugin.getDefault().getPreferenceStore()
45+
.getBoolean(IInternalDebugUIConstants.PREF_LAUNCHCONFIG_SORT_ON_RECENT));
46+
}
47+
48+
@Override
49+
public void run() {
50+
TreeViewer viewer = fTree.getViewer();
51+
IPreferenceStore prefStore = DebugUIPlugin.getDefault().getPreferenceStore();
52+
boolean isSortByRecent = prefStore.getBoolean(IInternalDebugUIConstants.PREF_LAUNCHCONFIG_SORT_ON_RECENT);
53+
if (!isSortByRecent) {
54+
viewer.setComparator(new LaunchConfigurationComparator(fTree.getLaunchGroup().getIdentifier()));
55+
prefStore.setValue(IInternalDebugUIConstants.PREF_LAUNCHCONFIG_SORT_ON_RECENT, true);
56+
} else {
57+
viewer.setComparator(new WorkbenchViewerComparator());
58+
prefStore.setValue(IInternalDebugUIConstants.PREF_LAUNCHCONFIG_SORT_ON_RECENT, false);
59+
}
60+
viewer.refresh();
61+
}
62+
63+
@Override
64+
public String getDescription() {
65+
return LaunchConfigurationsMessages.SortLaunchConfigurationActionDesc;
66+
}
67+
68+
@Override
69+
public ImageDescriptor getImageDescriptor() {
70+
return DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_LCL_DETAIL_PANE_HIDE);
71+
}
72+
73+
@Override
74+
public String getToolTipText() {
75+
return LaunchConfigurationsMessages.SortLaunchConfigurationActionDesc;
76+
}
77+
}

0 commit comments

Comments
 (0)