-
Notifications
You must be signed in to change notification settings - Fork 170
Add Toggle to Sort LaunchConfigurations by most recent launch #2839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
@@ -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; | ||
|
|
||
| /** | ||
|
|
@@ -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) | ||
|
|
@@ -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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a copy from the super method class? |
||
| 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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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())); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could use a conditional expression for the setComparator argument. |
||
| treeViewer.addFilter(new LaunchGroupFilter(fLaunchGroup)); | ||
| treeViewer.setUseHashlookup(true); | ||
|
|
@@ -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 |
|---|---|---|
|
|
@@ -96,6 +96,8 @@ public class LaunchConfigurationView extends AbstractDebugView implements ILaunc | |
| */ | ||
| private FilterLaunchConfigurationAction fFilterAction; | ||
|
|
||
| private SortLaunchConfigurationAction sort; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Others use an |
||
|
|
||
| /** | ||
| * This label is used to notify users that items (possibly) have been filtered from the | ||
| * launch configuration view | ||
|
|
@@ -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); | ||
|
|
||
|
|
@@ -291,6 +296,7 @@ public void dispose() { | |
| fExportAction.dispose(); | ||
| fImportAction.dispose(); | ||
| fFilterAction = null; | ||
| sort = null; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder why some need dispose and some don't? |
||
| fCollapseAllAction = null; | ||
| fLinkPrototypeAction.dispose(); | ||
| fUnlinkPrototypeAction.dispose(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -318,11 +318,14 @@ public class LaunchConfigurationsMessages extends NLS { | |
| public static String QuickGroupLaunchActionLabel; | ||
|
|
||
| public static String QuickGroupLaunchActionToolTip; | ||
|
|
||
| public static String FavoritesDialogPromptOnClose; | ||
|
|
||
| public static String FavoritesDialogPromptOnCloseTitle; | ||
|
|
||
| public static String FavoritesDialogPromptOnCloseSaveButton; | ||
| public static String SortLaunchConfigurationAction; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other declarations are all separated by a blank line but not this one. |
||
|
|
||
| public static String SortLaunchConfigurationActionDesc; | ||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -292,4 +292,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 | ||
|
Comment on lines
+296
to
+297
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other properties use |
||
| 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why package protected? |
||
|
|
||
| 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); | ||
| } | ||
|
Comment on lines
+53
to
+59
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be done using a conditional expression as the argument to setComparator so avoid even having an if-then-else block. |
||
| 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; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This blank line is pointless.