Skip to content

Commit d36dad4

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 d36dad4

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-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: 54 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.
@@ -323,6 +332,26 @@ public IStatus runInUIThread(IProgressMonitor monitor) {
323332
}
324333
};
325334
wjob.schedule();
335+
336+
// We need to enable Toggle Instruction Step Mode only if Debug UI plug-in is loaded.
337+
setActivityEnabled(TISM_ACTIVITY_ID, true);
338+
339+
// Disable the activity when the platform shuts down.
340+
IWorkbench workbench = PlatformUI.getWorkbench();
341+
workbenchListener = new IWorkbenchListener() {
342+
343+
@Override
344+
public boolean preShutdown(IWorkbench workbench, boolean forced) {
345+
// Workbench is still alive here – safe to disable activity
346+
setActivityEnabled(TISM_ACTIVITY_ID, false);
347+
return true;
348+
}
349+
350+
@Override
351+
public void postShutdown(IWorkbench workbench) {
352+
}
353+
};
354+
workbench.addWorkbenchListener(workbenchListener);
326355
}
327356

328357
private void startupInUIThread() {
@@ -361,6 +390,9 @@ public void stop(BundleContext context) throws Exception {
361390
if (fImageDescriptorRegistry != null) {
362391
fImageDescriptorRegistry.dispose();
363392
}
393+
394+
PlatformUI.getWorkbench().removeWorkbenchListener(workbenchListener);
395+
364396
super.stop(context);
365397
}
366398

@@ -436,4 +468,26 @@ public static <T> T getService(Class<T> service) {
436468
return ref != null ? context.getService(ref) : null;
437469
}
438470

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

0 commit comments

Comments
 (0)