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
Expand Up @@ -69,6 +69,7 @@ public void initializeDefaultPreferences() {
prefs.setDefault(IInternalDebugUIConstants.PREF_USE_CONTEXTUAL_LAUNCH, true);
prefs.setDefault(IInternalDebugUIConstants.PREF_LAUNCH_PARENT_PROJECT, false);
prefs.setDefault(IInternalDebugUIConstants.PREF_LAUNCH_LAST_IF_NOT_LAUNCHABLE, true);
prefs.setDefault(IInternalDebugUIConstants.PREF_LAUNCHCONFIG_SORT_ON_RECENT, false);

prefs.setDefault(IInternalDebugUIConstants.PREF_TERMINATE_AND_RELAUNCH_LAUNCH_ACTION, false);
prefs.setDefault(IInternalDebugUIConstants.PREF_BREAKPOINT_SORTING_ORDER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,11 @@ public interface IInternalDebugUIConstants {
*/
String EXPRESSION_PASTE_AS_MULTI = "org.eclipse.debug.ui.expression.paste.multi"; //$NON-NLS-1$

/**
* String indicating sorting order of launch configurations in
* LaunchConfigurations View
*
*/
String PREF_LAUNCHCONFIG_SORT_ON_RECENT = IDebugUIConstants.PLUGIN_ID + ".PREF_LAUNCHCONFIG_SORT_ON_RECENT"; //$NON-NLS-1$

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2015 IBM Corporation and others.
* Copyright (c) 2007, 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 @@ -24,6 +24,8 @@
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.ui.model.WorkbenchViewerComparator;

/**
Expand All @@ -37,6 +39,20 @@ public class LaunchConfigurationComparator extends WorkbenchViewerComparator {
* the map of categories of <code>ILaunchConfigurationType</code>s to <code>Integer</code>s entries
*/
private static Map<ILaunchConfigurationType, Integer> fgCategories;
private Map<ILaunchConfiguration, Integer> recentLaunches = new HashMap<>();

public LaunchConfigurationComparator(String groupIdentifier) {
LaunchHistory history = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchHistory(groupIdentifier);
if (history != null) {
ILaunchConfiguration[] launches = history.getCompleteLaunchHistory();
for (int i = 0; i < launches.length; i++) {
recentLaunches.put(launches[i], Integer.valueOf(i));
}
}
}

public LaunchConfigurationComparator() {
}

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

@Override
public int compare(Viewer viewer, Object e1, Object e2) {
if (e1 instanceof ILaunchConfiguration c1 && e2 instanceof ILaunchConfiguration c2) {
int category1 = category(c1);
int category2 = category(c2);
if (category1 != category2) {
return category1 - category2;
}
Integer recent1 = recentLaunches.get(c1);
Integer recent2 = recentLaunches.get(c2);
if (recent1 != null || recent2 != null) {
if (recent1 == null) {
return 1;
}
if (recent2 == null) {
return -1;
}
int result = recent1.compareTo(recent2);
if (result != 0) {
return result;
}
}
}
return super.compare(viewer, e1, e2);
}

/**
* Returns the map of categories
* @return the map of categories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.debug.internal.core.IInternalDebugCoreConstants;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.ILaunchGroup;
import org.eclipse.help.HelpSystem;
Expand Down Expand Up @@ -76,8 +77,17 @@ public LaunchConfigurationFilteredTree(Composite parent, int treeStyle, PatternF
@Override
protected TreeViewer doCreateTreeViewer(Composite cparent, int style) {
treeViewer = new LaunchConfigurationViewer(cparent, style);
treeViewer.setLabelProvider(new DecoratingLabelProvider(DebugUITools.newDebugModelPresentation(), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()));
treeViewer.setComparator(new WorkbenchViewerComparator());

treeViewer.setLabelProvider(new DecoratingLabelProvider(DebugUITools.newDebugModelPresentation(),
PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()));
boolean sortByRecent = DebugUIPlugin.getDefault().getPreferenceStore()
.getBoolean(IInternalDebugUIConstants.PREF_LAUNCHCONFIG_SORT_ON_RECENT);

if (sortByRecent) {
treeViewer.setComparator(new LaunchConfigurationComparator(fLaunchGroup.getIdentifier()));
} else {
treeViewer.setComparator(new WorkbenchViewerComparator());
}
treeViewer.setContentProvider(new LaunchConfigurationTreeContentProvider(fLaunchGroup.getMode(), cparent.getShell()));
treeViewer.addFilter(new LaunchGroupFilter(fLaunchGroup));
treeViewer.setUseHashlookup(true);
Expand Down Expand Up @@ -225,4 +235,8 @@ protected void updateToolbar(boolean visible) {
getLaunchConfigurationViewer().filterChanged();
}

public ILaunchGroup getLaunchGroup() {
return fLaunchGroup;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public class LaunchConfigurationView extends AbstractDebugView implements ILaunc
*/
private FilterLaunchConfigurationAction fFilterAction;

private SortLaunchConfigurationAction sort;

/**
* This label is used to notify users that items (possibly) have been filtered from the
* launch configuration view
Expand Down Expand Up @@ -225,6 +227,9 @@ protected void createActions() {
fFilterAction = new FilterLaunchConfigurationAction();
setAction(FilterLaunchConfigurationAction.ID_FILTER_ACTION, fFilterAction);

sort = new SortLaunchConfigurationAction(fTree);
setAction(SortLaunchConfigurationAction.ID_SORT_ACTION, sort);

fLinkPrototypeAction = new LinkPrototypeAction(getViewer(), getLaunchGroup().getMode());
setAction(LinkPrototypeAction.ID_LINK_PROTOTYPE_ACTION, fLinkPrototypeAction);

Expand Down Expand Up @@ -291,6 +296,7 @@ public void dispose() {
fExportAction.dispose();
fImportAction.dispose();
fFilterAction = null;
sort = null;
fCollapseAllAction = null;
fLinkPrototypeAction.dispose();
fUnlinkPrototypeAction.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ protected void createToolbarActions(ToolBarManager tmanager) {
tmanager.add(new Separator());
tmanager.add(getCollapseAllAction());
tmanager.add(getFilterAction());
tmanager.add(getSortAction());
tmanager.update(true);
DebugUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);
}
Expand Down Expand Up @@ -723,6 +724,10 @@ protected IAction getFilterAction() {
return fLaunchConfigurationView.getAction(FilterLaunchConfigurationAction.ID_FILTER_ACTION);
}

protected IAction getSortAction() {
return fLaunchConfigurationView.getAction(SortLaunchConfigurationAction.ID_SORT_ACTION);
}

/**
* Gets the collapse all action
* @return the collapse all action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,8 @@ public class LaunchConfigurationsMessages extends NLS {

public static String QuickGroupLaunchActionToolTip;

public static String SortLaunchConfigurationAction;

public static String SortLaunchConfigurationActionDesc;

}
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,6 @@ SelectLaunchersDialog_2=This dialog allows you to specify which launcher to use
SelectLaunchersDialog_4=<a href="ws">Change Workspace Settings...</a>
SelectLaunchersDialog_5=Description
SelectLaunchersDialog_launchers=Launc&hers:
SelectFavTypeToFilter= Type to filter
SelectFavTypeToFilter= Type to filter
SortLaunchConfigurationAction=Sort Launch Configurations
SortLaunchConfigurationActionDesc=Sort Launch Configurations by recent launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*******************************************************************************
* Copyright (c) 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.debug.internal.ui.launchConfigurations;

import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.ui.model.WorkbenchViewerComparator;

/**
* provides the implementation for sorting the launch configurations within the
* Launch Configuration Dialog
*
*/
public class SortLaunchConfigurationAction extends Action {

/**
* Action identifier for IDebugView#getAction(String)
*/
public static final String ID_SORT_ACTION = DebugUIPlugin.getUniqueIdentifier() + ".ID_SORT_ACTION"; //$NON-NLS-1$

LaunchConfigurationFilteredTree fTree;

public SortLaunchConfigurationAction(LaunchConfigurationFilteredTree tree) {
super(LaunchConfigurationsMessages.SortLaunchConfigurationAction, IAction.AS_CHECK_BOX);
fTree = tree;
setChecked(DebugUIPlugin.getDefault().getPreferenceStore()
.getBoolean(IInternalDebugUIConstants.PREF_LAUNCHCONFIG_SORT_ON_RECENT));
}

@Override
public void run() {
TreeViewer viewer = fTree.getViewer();
IPreferenceStore prefStore = DebugUIPlugin.getDefault().getPreferenceStore();
boolean isSortByRecent = prefStore.getBoolean(IInternalDebugUIConstants.PREF_LAUNCHCONFIG_SORT_ON_RECENT);
if (!isSortByRecent) {
viewer.setComparator(new LaunchConfigurationComparator(fTree.getLaunchGroup().getIdentifier()));
prefStore.setValue(IInternalDebugUIConstants.PREF_LAUNCHCONFIG_SORT_ON_RECENT, true);
} else {
viewer.setComparator(new WorkbenchViewerComparator());
prefStore.setValue(IInternalDebugUIConstants.PREF_LAUNCHCONFIG_SORT_ON_RECENT, false);
}
viewer.refresh();
}

@Override
public String getDescription() {
return LaunchConfigurationsMessages.SortLaunchConfigurationActionDesc;
}

@Override
public ImageDescriptor getImageDescriptor() {
return DebugUITools.getImageDescriptor(IDebugUIConstants.IMG_LCL_DETAIL_PANE_HIDE);
}

@Override
public String getToolTipText() {
return LaunchConfigurationsMessages.SortLaunchConfigurationActionDesc;
}
}
Loading