Skip to content

Commit

Permalink
Migrate ToggleInstructionStepModeAction to
Browse files Browse the repository at this point in the history
ToggleInstructionStepModeCommand.

All the contributions of the the action has been replaced
ToggleInstructionStepModeCommand.
Enabled when introduced. Which enabled the command only when C/CPP
application is under debug in Debug View.

see #865
  • Loading branch information
raghucssit committed Aug 24, 2024
1 parent c4c11ad commit 0391f86
Show file tree
Hide file tree
Showing 7 changed files with 376 additions and 249 deletions.
2 changes: 1 addition & 1 deletion debug/org.eclipse.cdt.debug.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.debug.ui; singleton:=true
Bundle-Version: 8.5.500.qualifier
Bundle-Version: 8.5.600.qualifier
Bundle-Activator: org.eclipse.cdt.debug.ui.CDebugUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
157 changes: 99 additions & 58 deletions debug/org.eclipse.cdt.debug.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,17 +280,6 @@
helpContextId="move_to_line_action_context"
label="%GlobalMoveToLineAction.label"
menubarPath="org.eclipse.ui.run/stepGroup"/>
<action
class="org.eclipse.cdt.debug.internal.ui.actions.ToggleInstructionStepModeActionDelegate"
helpContextId="toggle_instruction_step_mode_action_context"
icon="icons/elcl16/instr_step.gif"
id="org.eclipse.cdt.debug.ui.actions.ToggleInstructionStepMode"
label="%ToggleInstructionStepModeAction.label"
menubarPath="org.eclipse.ui.run/stepGroup"
state="false"
style="toggle"
toolbarPath="org.eclipse.debug.ui.main.toolbar/renderGroup">
</action>
</actionSet>
</extension>
<extension
Expand Down Expand Up @@ -340,27 +329,6 @@

<extension
point="org.eclipse.ui.popupMenus">
<viewerContribution
targetID="org.eclipse.debug.ui.DebugView"
id="org.eclipse.cdt.debug.ui.debugview.popupMenu">
<action
state="false"
style="toggle"
id="org.eclipse.cdt.debug.internal.ui.actions.ToggleInstructionStepModeActionDelegate"
class="org.eclipse.cdt.debug.internal.ui.actions.ToggleInstructionStepModeActionDelegate"
icon="icons/elcl16/instr_step.gif"
helpContextId="toggle_instruction_step_mode_action_context"
label="%ToggleInstructionStepModeAction.label"
menubarPath="renderGroup"
tooltip="%ToggleInstructionStepModeAction.tooltip">
<enablement>
<pluginState
value="activated"
id="org.eclipse.cdt.debug.ui">
</pluginState>
</enablement>
</action>
</viewerContribution>
<viewerContribution
targetID="#CEditorRulerContext"
id="org.eclipse.cdt.debug.ui.CEditorRulerActions">
Expand Down Expand Up @@ -675,28 +643,6 @@
</extension>
<extension
point="org.eclipse.ui.viewActions">
<viewContribution
targetID="org.eclipse.debug.ui.DebugView"
id="org.eclipse.cdt.debug.ui.debugview.toolbar">
<action
state="false"
style="toggle"
id="org.eclipse.cdt.debug.internal.ui.actions.ToggleInstructionStepModeActionDelegate"
toolbarPath="renderGroup"
class="org.eclipse.cdt.debug.internal.ui.actions.ToggleInstructionStepModeActionDelegate"
disabledIcon="icons/dlcl16/instr_step.gif"
icon="icons/elcl16/instr_step.gif"
label="%ToggleInstructionStepModeAction.label"
helpContextId="toggle_instruction_step_mode_action_context"
tooltip="%ToggleInstructionStepModeAction.tooltip">
<enablement>
<pluginState
value="activated"
id="org.eclipse.cdt.debug.ui">
</pluginState>
</enablement>
</action>
</viewContribution>
<viewContribution
targetID="org.eclipse.debug.ui.DebugView"
id="org.eclipse.cdt.debug.ui.debugView.menu">
Expand Down Expand Up @@ -1379,9 +1325,85 @@
id="org.eclipse.debug.ui.actions.BreakpointTypesContribution"
class="org.eclipse.debug.ui.actions.BreakpointTypesContribution">
</dynamic>
</menu>
</menuContribution>

</menu>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.debug.ui.DebugView?after=additions">
<command
commandId="org.eclipse.cdt.debug.internal.ui.actions.ToggleInstructionStepModeCommand"
disabledIcon="icons/dlcl16/instr_step.gif"
helpContextId="toggle_instruction_step_mode_action_context"
icon="icons/elcl16/instr_step.gif"
label="%ToggleInstructionStepModeAction.label"
style="toggle"
tooltip="%ToggleInstructionStepModeAction.tooltip">
<visibleWhen
checkEnabled="false">
<test
property="org.eclipse.cdt.debug.ui.isCDTDebugging">
</test>
</visibleWhen>
</command>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.debug.ui.DebugView?after=renderGroup">
<command
commandId="org.eclipse.cdt.debug.internal.ui.actions.ToggleInstructionStepModeCommand"
disabledIcon="icons/dlcl16/instr_step.gif"
helpContextId="toggle_instruction_step_mode_action_context"
icon="icons/elcl16/instr_step.gif"
label="%ToggleInstructionStepModeAction.label"
style="toggle"
tooltip="%ToggleInstructionStepModeAction.tooltip">
<visibleWhen
checkEnabled="false">
<test
property="org.eclipse.cdt.debug.ui.isCDTDebugging">
</test>
</visibleWhen>
</command>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="menu:org.eclipse.ui.run?endof=stepGroup">
<command
commandId="org.eclipse.cdt.debug.internal.ui.actions.ToggleInstructionStepModeCommand"
disabledIcon="icons/dlcl16/instr_step.gif"
helpContextId="toggle_instruction_step_mode_action_context"
icon="icons/elcl16/instr_step.gif"
label="%ToggleInstructionStepModeAction.label"
style="toggle"
tooltip="%ToggleInstructionStepModeAction.tooltip">
<visibleWhen
checkEnabled="false">
<test
property="org.eclipse.cdt.debug.ui.isCDTDebugging">
</test>
</visibleWhen>
</command>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.debug.ui.main.toolbar?after=renderGroup">
<command
commandId="org.eclipse.cdt.debug.internal.ui.actions.ToggleInstructionStepModeCommand"
disabledIcon="icons/dlcl16/instr_step.gif"
helpContextId="toggle_instruction_step_mode_action_context"
icon="icons/elcl16/instr_step.gif"
label="%ToggleInstructionStepModeAction.label"
style="toggle"
tooltip="%ToggleInstructionStepModeAction.tooltip">
<visibleWhen
checkEnabled="false">
<test
property="org.eclipse.cdt.debug.ui.isCDTDebugging">
</test>
</visibleWhen>
</command>
</menuContribution>

</extension>
<extension
point="org.eclipse.core.runtime.adapters">
Expand Down Expand Up @@ -1660,6 +1682,14 @@
id="org.eclipse.cdt.debug.ui.command.loadAllSymbols"
name="%LoadSymbolsForAllAction.label">
</command>
<command
id="org.eclipse.cdt.debug.internal.ui.actions.ToggleInstructionStepModeCommand"
name="%ToggleInstructionStepModeAction.label">
<state
class="org.eclipse.ui.handlers.RegistryToggleState:false"
id="org.eclipse.ui.commands.toggleState">
</state>
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
Expand Down Expand Up @@ -1737,7 +1767,11 @@
</with>
</and>
</enabledWhen>
</handler>
</handler>
<handler
class="org.eclipse.cdt.debug.internal.ui.commands.ToggleInstructionStepModeHandler"
commandId="org.eclipse.cdt.debug.internal.ui.actions.ToggleInstructionStepModeCommand">
</handler>
</extension>
<extension
point="org.eclipse.core.expressions.definitions">
Expand Down Expand Up @@ -2564,6 +2598,13 @@
properties="createBreakpointAdapt"
type="org.eclipse.cdt.debug.ui.breakpoints.ICBreakpointContext">
</propertyTester>
<propertyTester
class="org.eclipse.cdt.debug.internal.ui.actions.CDTDebugPropertyTester"
id="org.eclipse.cdt.debug.CDTDebugPropertyTester"
namespace="org.eclipse.cdt.debug.ui"
properties="isCDTDebugging"
type="java.lang.Object">
</propertyTester>
</extension>
<extension
point="org.eclipse.launchbar.ui.launchBarUIContributions">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*******************************************************************************
* Copyright (c) 2024 Advantest Europe GmbH 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:
* Raghunandana Murthappa
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;

import org.eclipse.cdt.debug.core.model.ISteppingModeTarget;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.debug.ui.IDebugView;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;

/**
* Tests whether an active C/C++ application is debugging. And selection inside Debug View is present on it.
*
* @author Raghunandana Murthappa
*/
public class CDTDebugPropertyTester extends PropertyTester {

private static final String IS_CDT_DEBUGGING = "isCDTDebugging"; //$NON-NLS-1$

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (IS_CDT_DEBUGGING.equals(property)) {
return isCdtLaunchConfigDebugMode();
}
return false;
}

private boolean isCdtLaunchConfigDebugMode() {
ISteppingModeTarget gdbTarget = getSteppingModeTarget();
return gdbTarget != null && gdbTarget.supportsInstructionStepping();
}

/**
* Debug View can contain many targets at given point of time. This will check if {@code ISteppingModeTarget} present and it is selected. If yes returns it.
*
* @return Instruction stepping mode target.
*/
public static ISteppingModeTarget getSteppingModeTarget() {
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (workbenchWindow == null) {
return null;
}

IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
if (workbenchPage == null) {
return null;
}

IViewPart debugView = workbenchPage.findView(IDebugUIConstants.ID_DEBUG_VIEW);
if (debugView == null) {
return null;
}

IDebugView debugViewClazz = debugView.getAdapter(IDebugView.class);
ISelection selection = debugViewClazz.getViewer().getSelection();
if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
return null;
}

Object element = ((IStructuredSelection) selection).getFirstElement();

return getTargetFromSelection(element);
}

public static ISteppingModeTarget getTargetFromSelection(Object element) {
ISteppingModeTarget target = null;
if (element instanceof IDebugElement) {
IDebugTarget debugTarget = ((IDebugElement) element).getDebugTarget();
if (debugTarget instanceof ISteppingModeTarget) {
target = (ISteppingModeTarget) debugTarget;
}
}
if (target == null) {
if (element instanceof IAdaptable) {
target = ((IAdaptable) element).getAdapter(ISteppingModeTarget.class);
}
}
return target;
}
}
Loading

0 comments on commit 0391f86

Please sign in to comment.