Skip to content

Commit 1975708

Browse files
committed
Add active launch indicator to launch history menu
Adds a visual indicator to launch configurations that are currently active in the launch history menu.
1 parent 77bec00 commit 1975708

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchHistoryAction.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
import org.eclipse.core.resources.IResource;
2424
import org.eclipse.core.runtime.CoreException;
2525
import org.eclipse.debug.core.DebugPlugin;
26+
import org.eclipse.debug.core.ILaunch;
2627
import org.eclipse.debug.core.ILaunchConfiguration;
2728
import org.eclipse.debug.core.ILaunchConfigurationType;
2829
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
2930
import org.eclipse.debug.core.ILaunchManager;
3031
import org.eclipse.debug.internal.core.IInternalDebugCoreConstants;
32+
import org.eclipse.debug.internal.ui.DebugPluginImages;
3133
import org.eclipse.debug.internal.ui.DebugUIPlugin;
3234
import org.eclipse.debug.internal.ui.ILaunchHistoryChangedListener;
3335
import org.eclipse.debug.internal.ui.ILaunchLabelChangedListener;
@@ -40,18 +42,23 @@
4042
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension;
4143
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutSelectionDialog;
4244
import org.eclipse.debug.internal.ui.stringsubstitution.SelectedResourceManager;
45+
import org.eclipse.debug.ui.IDebugUIConstants;
4346
import org.eclipse.debug.ui.ILaunchGroup;
4447
import org.eclipse.debug.ui.ILaunchShortcut;
4548
import org.eclipse.jface.action.Action;
4649
import org.eclipse.jface.action.ActionContributionItem;
4750
import org.eclipse.jface.action.IAction;
4851
import org.eclipse.jface.dialogs.IDialogConstants;
52+
import org.eclipse.jface.resource.ImageDescriptor;
53+
import org.eclipse.jface.viewers.DecorationOverlayIcon;
54+
import org.eclipse.jface.viewers.IDecoration;
4955
import org.eclipse.jface.viewers.ISelection;
5056
import org.eclipse.jface.viewers.IStructuredSelection;
5157
import org.eclipse.jface.viewers.StructuredSelection;
5258
import org.eclipse.swt.SWT;
5359
import org.eclipse.swt.events.MenuAdapter;
5460
import org.eclipse.swt.events.MenuEvent;
61+
import org.eclipse.swt.graphics.Image;
5562
import org.eclipse.swt.widgets.Control;
5663
import org.eclipse.swt.widgets.Display;
5764
import org.eclipse.swt.widgets.Event;
@@ -347,8 +354,28 @@ protected void fillMenu(Menu menu) {
347354

348355
// Add favorites
349356
int accelerator = 1;
357+
ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches();
350358
for (ILaunchConfiguration launch : favoriteList) {
351359
LaunchAction action= new LaunchAction(launch, getMode());
360+
if (checkIfLaunchActive(launch, launches)) {
361+
action.setText(action.getText() + " (Running)"); //$NON-NLS-1$
362+
363+
ImageDescriptor base = action.getImageDescriptor();
364+
365+
if (base != null) {
366+
// Overlay icon (small running indicator)
367+
ImageDescriptor overlay = DebugPluginImages
368+
.getImageDescriptor(IDebugUIConstants.IMG_OBJS_INSTRUCTION_POINTER_TOP);
369+
370+
Image baseImage = base.createImage();
371+
372+
DecorationOverlayIcon decorated = new DecorationOverlayIcon(baseImage, overlay,
373+
IDecoration.TOP_LEFT);
374+
375+
action.setImageDescriptor(ImageDescriptor.createFromImage(decorated.createImage()));
376+
}
377+
378+
}
352379
addToMenu(menu, action, accelerator);
353380
accelerator++;
354381
}
@@ -361,6 +388,24 @@ protected void fillMenu(Menu menu) {
361388
// Add history launches next
362389
for (ILaunchConfiguration launch : historyList) {
363390
LaunchAction action= new LaunchAction(launch, getMode());
391+
if (checkIfLaunchActive(launch, launches)) {
392+
action.setText(action.getText() + " (Running)"); //$NON-NLS-1$
393+
394+
ImageDescriptor base = action.getImageDescriptor();
395+
396+
if (base != null) {
397+
// Overlay icon (small running indicator)
398+
ImageDescriptor overlay = DebugPluginImages
399+
.getImageDescriptor(IDebugUIConstants.IMG_OBJS_INSTRUCTION_POINTER_TOP);
400+
401+
Image baseImage = base.createImage();
402+
403+
DecorationOverlayIcon decorated = new DecorationOverlayIcon(baseImage, overlay,
404+
IDecoration.TOP_LEFT);
405+
406+
action.setImageDescriptor(ImageDescriptor.createFromImage(decorated.createImage()));
407+
}
408+
}
364409
addToMenu(menu, action, accelerator);
365410
accelerator++;
366411
}
@@ -373,6 +418,24 @@ protected void fillMenu(Menu menu) {
373418
}
374419
}
375420

421+
/**
422+
* Returns whether the given launch configuration has been launched and active
423+
* now.
424+
*
425+
* @param launchConfiguration the launch configuration
426+
* @param launches the current active launches
427+
* @return {@code true} if a matching launch exists, {@code false} otherwise
428+
*/
429+
private boolean checkIfLaunchActive(ILaunchConfiguration launchConfiguration, ILaunch[] launches) {
430+
for (ILaunch launch : launches) {
431+
ILaunchConfiguration activeLaunch = launch.getLaunchConfiguration();
432+
if (activeLaunch != null && activeLaunch.equals(launchConfiguration) && !launch.isTerminated()) {
433+
return true;
434+
}
435+
}
436+
return false;
437+
}
438+
376439
/**
377440
* Adds a separator to the given menu
378441
*

0 commit comments

Comments
 (0)