|
16 | 16 | package org.eclipse.cdt.debug.ui; |
17 | 17 |
|
18 | 18 | import java.util.HashMap; |
| 19 | +import java.util.HashSet; |
19 | 20 | import java.util.Map; |
| 21 | +import java.util.Set; |
20 | 22 |
|
21 | 23 | import org.eclipse.cdt.debug.core.CDebugCorePlugin; |
22 | 24 | import org.eclipse.cdt.debug.internal.ui.CDebugImageDescriptorRegistry; |
|
61 | 63 | import org.eclipse.ui.ISharedImages; |
62 | 64 | import org.eclipse.ui.IViewPart; |
63 | 65 | import org.eclipse.ui.IViewReference; |
| 66 | +import org.eclipse.ui.IWorkbench; |
| 67 | +import org.eclipse.ui.IWorkbenchListener; |
64 | 68 | import org.eclipse.ui.IWorkbenchPage; |
65 | 69 | import org.eclipse.ui.IWorkbenchWindow; |
66 | 70 | import org.eclipse.ui.PlatformUI; |
| 71 | +import org.eclipse.ui.activities.IWorkbenchActivitySupport; |
67 | 72 | import org.eclipse.ui.editors.text.EditorsUI; |
68 | 73 | import org.eclipse.ui.plugin.AbstractUIPlugin; |
69 | 74 | import org.eclipse.ui.progress.WorkbenchJob; |
@@ -94,6 +99,10 @@ public class CDebugUIPlugin extends AbstractUIPlugin { |
94 | 99 |
|
95 | 100 | private static IDebuggerConsoleManager fDebuggerConsoleManager; |
96 | 101 |
|
| 102 | + private IWorkbenchListener workbenchListener; |
| 103 | + |
| 104 | + private static final String TISM_ACTIVITY_ID = "org.eclipse.cdt.debug.ui.activity.toggleInstructionStepMode"; //$NON-NLS-1$ |
| 105 | + |
97 | 106 | /** |
98 | 107 | * At least one listener must be registered on the DebugPlugin in order |
99 | 108 | * for certain actions, like RunToLine, to work. See bug 573696. |
@@ -319,10 +328,29 @@ public void start(BundleContext context) throws Exception { |
319 | 328 | @Override |
320 | 329 | public IStatus runInUIThread(IProgressMonitor monitor) { |
321 | 330 | startupInUIThread(); |
| 331 | + // We need to enable Toggle Instruction Step Mode only if Debug UI plug-in is loaded. |
| 332 | + setActivityEnabled(TISM_ACTIVITY_ID, true); |
322 | 333 | return Status.OK_STATUS; |
323 | 334 | } |
324 | 335 | }; |
325 | 336 | 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); |
326 | 354 | } |
327 | 355 |
|
328 | 356 | private void startupInUIThread() { |
@@ -361,6 +389,9 @@ public void stop(BundleContext context) throws Exception { |
361 | 389 | if (fImageDescriptorRegistry != null) { |
362 | 390 | fImageDescriptorRegistry.dispose(); |
363 | 391 | } |
| 392 | + |
| 393 | + PlatformUI.getWorkbench().removeWorkbenchListener(workbenchListener); |
| 394 | + |
364 | 395 | super.stop(context); |
365 | 396 | } |
366 | 397 |
|
@@ -436,4 +467,26 @@ public static <T> T getService(Class<T> service) { |
436 | 467 | return ref != null ? context.getService(ref) : null; |
437 | 468 | } |
438 | 469 |
|
| 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 | + |
439 | 492 | } |
0 commit comments