Skip to content

Commit 98f6b48

Browse files
committed
Disable Toggle Instruction Step Mode command using activity support.
TISM command is always visible if the CDT Debug UI plug-in is not loaded yet. This happened due to platform limitation.So handle visibility using activity support. see #1220
1 parent 591e99e commit 98f6b48

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

debug/org.eclipse.cdt.debug.ui/plugin.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,5 +2675,31 @@
26752675
name="%GenericTarget.name">
26762676
</wizard2>
26772677
</extension>
2678+
2679+
<!-- Activity definition that controls the visibility of Toggle Instruction Step Mode command-->
2680+
<extension point="org.eclipse.ui.activities">
2681+
<category
2682+
id="org.eclipse.cdt.debug.ui.category"
2683+
name="CDT Debug UI"
2684+
description="Controls visibility of CDT Debug UI contributions">
2685+
</category>
2686+
2687+
<activity
2688+
id="org.eclipse.cdt.debug.ui.activity.toggleInstructionStepMode"
2689+
name="Toggle Instruction Step Mode Command"
2690+
description="Activity to control visibility of Toggle Instruction Step Mode command">
2691+
</activity>
2692+
2693+
<activityPatternBinding
2694+
activityId="org.eclipse.cdt.debug.ui.activity.toggleInstructionStepMode"
2695+
pattern="org\.eclipse\.cdt\.debug\.ui/org\.eclipse\.cdt\.debug\.internal\.ui\.actions\.ToggleInstructionStepModeCommand">
2696+
</activityPatternBinding>
2697+
2698+
<categoryActivityBinding
2699+
activityId="org.eclipse.cdt.debug.ui.activity.toggleInstructionStepMode"
2700+
categoryId="org.eclipse.cdt.debug.ui.category">
2701+
</categoryActivityBinding>
2702+
</extension>
2703+
26782704

26792705
</plugin>

debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/CDebugUIPlugin.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
package org.eclipse.cdt.debug.ui;
1717

1818
import java.util.HashMap;
19+
import java.util.HashSet;
1920
import java.util.Map;
21+
import java.util.Set;
2022

2123
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
2224
import org.eclipse.cdt.debug.internal.ui.CDebugImageDescriptorRegistry;
@@ -61,9 +63,12 @@
6163
import org.eclipse.ui.ISharedImages;
6264
import org.eclipse.ui.IViewPart;
6365
import org.eclipse.ui.IViewReference;
66+
import org.eclipse.ui.IWorkbench;
67+
import org.eclipse.ui.IWorkbenchListener;
6468
import org.eclipse.ui.IWorkbenchPage;
6569
import org.eclipse.ui.IWorkbenchWindow;
6670
import org.eclipse.ui.PlatformUI;
71+
import org.eclipse.ui.activities.IWorkbenchActivitySupport;
6772
import org.eclipse.ui.editors.text.EditorsUI;
6873
import org.eclipse.ui.plugin.AbstractUIPlugin;
6974
import org.eclipse.ui.progress.WorkbenchJob;
@@ -94,6 +99,10 @@ public class CDebugUIPlugin extends AbstractUIPlugin {
9499

95100
private static IDebuggerConsoleManager fDebuggerConsoleManager;
96101

102+
private IWorkbenchListener workbenchListener;
103+
104+
private static final String TISM_ACTIVITY_ID = "org.eclipse.cdt.debug.ui.activity.toggleInstructionStepMode"; //$NON-NLS-1$
105+
97106
/**
98107
* At least one listener must be registered on the DebugPlugin in order
99108
* for certain actions, like RunToLine, to work. See bug 573696.
@@ -319,10 +328,29 @@ public void start(BundleContext context) throws Exception {
319328
@Override
320329
public IStatus runInUIThread(IProgressMonitor monitor) {
321330
startupInUIThread();
331+
// We need to enable Toggle Instruction Step Mode only if Debug UI plug-in is loaded.
332+
setActivityEnabled(TISM_ACTIVITY_ID, true);
322333
return Status.OK_STATUS;
323334
}
324335
};
325336
wjob.schedule();
337+
338+
// Disable the activity when the platform shuts down.
339+
IWorkbench workbench = PlatformUI.getWorkbench();
340+
workbenchListener = new IWorkbenchListener() {
341+
342+
@Override
343+
public boolean preShutdown(IWorkbench workbench, boolean forced) {
344+
// Workbench is still alive here – safe to disable activity
345+
setActivityEnabled(TISM_ACTIVITY_ID, false);
346+
return true;
347+
}
348+
349+
@Override
350+
public void postShutdown(IWorkbench workbench) {
351+
}
352+
};
353+
workbench.addWorkbenchListener(workbenchListener);
326354
}
327355

328356
private void startupInUIThread() {
@@ -361,6 +389,9 @@ public void stop(BundleContext context) throws Exception {
361389
if (fImageDescriptorRegistry != null) {
362390
fImageDescriptorRegistry.dispose();
363391
}
392+
393+
PlatformUI.getWorkbench().removeWorkbenchListener(workbenchListener);
394+
364395
super.stop(context);
365396
}
366397

@@ -436,4 +467,26 @@ public static <T> T getService(Class<T> service) {
436467
return ref != null ? context.getService(ref) : null;
437468
}
438469

470+
private void setActivityEnabled(String activityId, boolean enabled) {
471+
IWorkbench workbench = PlatformUI.getWorkbench();
472+
if (workbench == null) {
473+
return;
474+
}
475+
IWorkbenchActivitySupport activitySupport = workbench.getActivitySupport();
476+
477+
if (activitySupport == null) {
478+
return;
479+
}
480+
481+
Set<String> enabledActivities = new HashSet<>(activitySupport.getActivityManager().getEnabledActivityIds());
482+
483+
if (enabled) {
484+
enabledActivities.add(activityId);
485+
} else {
486+
enabledActivities.remove(activityId);
487+
}
488+
489+
activitySupport.setEnabledActivityIds(enabledActivities);
490+
}
491+
439492
}

0 commit comments

Comments
 (0)