Skip to content

Commit

Permalink
Restrict Pin View and Open View to active CPP debug context.
Browse files Browse the repository at this point in the history
That is if any CPP application is under debug. Because Pin View is never
enabled other than CPP application debug session.

This also includes Action to Command migration.

see eclipse-cdt#1048
  • Loading branch information
raghucssit committed Jan 21, 2025
1 parent 9e04dc5 commit 8e73224
Show file tree
Hide file tree
Showing 6 changed files with 361 additions and 288 deletions.
183 changes: 113 additions & 70 deletions debug/org.eclipse.cdt.debug.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -718,76 +718,6 @@
helpContextId="add_line_breakpoint_action_context"
tooltip="%AddLineBreakpoint.tooltip"/>
</viewContribution>
<viewContribution
targetID="org.eclipse.debug.ui.RegisterView"
id="org.eclipse.debug.ui.registersView.toolbar">
<menu
label="%Dummy"
id="org.eclipse.cdt.debug.ui.refresh">
<separator name="refreshGroup"/>
<separator name="emptyRefreshGroup"/>
</menu>
</viewContribution>
<viewContribution
id="org.eclipse.cdt.debug.ui.expression.toolbar"
targetID="org.eclipse.debug.ui.ExpressionView">
<action
class="org.eclipse.cdt.debug.internal.ui.actions.PinDebugContextActionDelegate"
icon="icons/elcl16/toolbar_pinned.gif"
id="org.eclipse.pinclone.expression.pinDebugContext"
label="%PinView.name "
style="toggle"
toolbarPath="pinGroup">
</action>
<action
class="org.eclipse.cdt.debug.internal.ui.actions.OpenNewViewActionDelegate"
icon="icons/elcl16/open_new.gif"
id="org.eclipse.pinclone.expression.clone"
label="%OpenNewView.name"
style="push"
toolbarPath="pinGroup">
</action>
</viewContribution>
<viewContribution
id="org.eclipse.cdt.debug.ui.variable.toolbar"
targetID="org.eclipse.debug.ui.VariableView">
<action
class="org.eclipse.cdt.debug.internal.ui.actions.PinDebugContextActionDelegate"
icon="icons/elcl16/toolbar_pinned.gif"
id="org.eclipse.pinclone.variable.pinDebugContext"
label="%PinView.name "
style="toggle"
toolbarPath="pinGroup">
</action>
<action
class="org.eclipse.cdt.debug.internal.ui.actions.OpenNewViewActionDelegate"
icon="icons/elcl16/open_new.gif"
id="org.eclipse.pinclone.variable.clone"
label="%OpenNewView.name"
style="push"
toolbarPath="pinGroup">
</action>
</viewContribution>
<viewContribution
id="org.eclipse.cdt.debug.ui.register.toolbar"
targetID="org.eclipse.debug.ui.RegisterView">
<action
class="org.eclipse.cdt.debug.internal.ui.actions.PinDebugContextActionDelegate"
icon="icons/elcl16/toolbar_pinned.gif"
id="org.eclipse.pinclone.register.pinDebugContext"
label="%PinView.name "
style="toggle"
toolbarPath="pinGroup">
</action>
<action
class="org.eclipse.cdt.debug.internal.ui.actions.OpenNewViewActionDelegate"
icon="icons/elcl16/open_new.gif"
id="org.eclipse.pinclone.register.clone"
label="%OpenNewView.name"
style="push"
toolbarPath="pinGroup">
</action>
</viewContribution>
</extension>
<extension
point="org.eclipse.ui.editorActions">
Expand Down Expand Up @@ -1402,6 +1332,96 @@
</visibleWhen>
</command>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.debug.ui.VariableView?after=additions">
<command
commandId="org.eclipse.cdt.debug.ui.PinViewCommand"
icon="icons/elcl16/toolbar_pinned.gif"
label="%PinView.name "
style="toggle">
<visibleWhen
checkEnabled="false">
<test
args="Variables"
property="org.eclipse.cdt.debug.ui.canPinViewEnabled">
</test>
</visibleWhen>
</command>
<command
commandId="org.eclipse.cdt.debug.ui.OpenNewViewCommand"
icon="icons/elcl16/open_new.gif"
label="%OpenNewView.name"
style="push">
<visibleWhen
checkEnabled="false">
<test
args="Variables"
property="org.eclipse.cdt.debug.ui.canPinViewEnabled">
</test>
</visibleWhen>
</command>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.debug.ui.ExpressionView?after=additions">
<command
commandId="org.eclipse.cdt.debug.ui.PinViewCommand"
icon="icons/elcl16/toolbar_pinned.gif"
label="%PinView.name "
style="toggle">
<visibleWhen
checkEnabled="false">
<test
args="Expressions"
property="org.eclipse.cdt.debug.ui.canPinViewEnabled">
</test>
</visibleWhen>
</command>
<command
commandId="org.eclipse.cdt.debug.ui.OpenNewViewCommand"
icon="icons/elcl16/open_new.gif"
label="%OpenNewView.name"
style="push">
<visibleWhen
checkEnabled="false">
<test
args="Expressions"
property="org.eclipse.cdt.debug.ui.canPinViewEnabled">
</test>
</visibleWhen>
</command>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.debug.ui.RegisterView?after=additions">
<command
commandId="org.eclipse.cdt.debug.ui.PinViewCommand"
icon="icons/elcl16/toolbar_pinned.gif"
label="%PinView.name "
style="toggle">
<visibleWhen
checkEnabled="false">
<test
args="Registers"
property="org.eclipse.cdt.debug.ui.canPinViewEnabled">
</test>
</visibleWhen>
</command>
<command
commandId="org.eclipse.cdt.debug.ui.OpenNewViewCommand"
icon="icons/elcl16/open_new.gif"
label="%OpenNewView.name"
style="push">
<visibleWhen
checkEnabled="false">
<test
args="Registers"
property="org.eclipse.cdt.debug.ui.canPinViewEnabled">
</test>
</visibleWhen>
</command>
</menuContribution>

</extension>
<extension
Expand Down Expand Up @@ -1689,6 +1709,14 @@
id="org.eclipse.ui.commands.toggleState">
</state>
</command>
<command
id="org.eclipse.cdt.debug.ui.PinViewCommand"
name="%PinView.name ">
</command>
<command
id="org.eclipse.cdt.debug.ui.OpenNewViewCommand"
name="%OpenNewView.name">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
Expand Down Expand Up @@ -1771,6 +1799,14 @@
class="org.eclipse.cdt.debug.internal.ui.commands.ToggleInstructionStepModeHandler"
commandId="org.eclipse.cdt.debug.internal.ui.actions.ToggleInstructionStepModeCommand">
</handler>
<handler
class="org.eclipse.cdt.debug.internal.ui.actions.PinViewHandler"
commandId="org.eclipse.cdt.debug.ui.PinViewCommand">
</handler>
<handler
class="org.eclipse.cdt.debug.internal.ui.actions.OpenNewViewHandler"
commandId="org.eclipse.cdt.debug.ui.OpenNewViewCommand">
</handler>
</extension>
<extension
point="org.eclipse.core.expressions.definitions">
Expand Down Expand Up @@ -2604,6 +2640,13 @@
properties="isCDTDebugging"
type="java.lang.Object">
</propertyTester>
<propertyTester
class="org.eclipse.cdt.debug.internal.ui.actions.PinCommandEnablementTester"
id="org.eclipse.cdt.debug.ui.PinViewPropertyTester"
namespace="org.eclipse.cdt.debug.ui"
properties="canPinViewEnabled"
type="java.lang.Object">
</propertyTester>
</extension>
<extension
point="org.eclipse.launchbar.ui.launchBarUIContributions">
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*******************************************************************************
* Copyright (c) 2010, 2014 Texas Instruments 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:
* Patrick Chuong (Texas Instruments) - Initial implementation of run()
* Marc Dumais (Ericsson) - Bug 437692
* Raghunandana Murthappa(Advantest Europe GmbH) - Issue 1048
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.handlers.HandlerUtil;

/**
* Handler that opens the new View of the view type selected. This is used by
* the OpenNewViewCommand which is contributed to debug related views.
*/
public class OpenNewViewHandler extends AbstractHandler {
private OpenNewViewAction fOpenNewViewAction = new OpenNewViewAction();

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IViewPart viewPart = (IViewPart) HandlerUtil.getActivePart(event);
fOpenNewViewAction.init(viewPart);
fOpenNewViewAction.run();

return IStatus.OK;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2025 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 java.util.Set;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.part.WorkbenchPart;

/**
* Tests if Pin View Command can be enabled. This is tested in 2 steps.
* <p>
* 1. If a view is already pinned(which will be passes as argument) then command
* must be enabled until it is unpinned. 2. A valid CDT Debug Launch is active
* within Debug Launch Manager.
* </p>
*
* @author Raghunandana Murthappa
*/
public class PinCommandEnablementTester extends PropertyTester {

private static final String GDB_LAUNCH_TYPE = "org.eclipse.cdt.dsf.gdb.launching.GdbLaunch"; //$NON-NLS-1$
private static final String PIN_VIEW_COMMAND_PROP_TEST_NAME = "canPinViewEnabled"; //$NON-NLS-1$

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (PIN_VIEW_COMMAND_PROP_TEST_NAME.equals(property)) {
// Check if the View was pinned, then button must be there to Unpin.
Set<IViewPart> pinnedViews = PinViewHandler.getPinnedViews();
if (pinnedViews.size() > 0 && args.length == 1) {
for (IViewPart viewPart : pinnedViews) {
WorkbenchPart vPart = (WorkbenchPart) viewPart;
if (args[0].equals(vPart.getPartName())) {
return true;
}
}
}
// Check if any CDT launch is active.
ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches();
for (ILaunch launch : launches) {
if (launch.getClass().getName().equals(GDB_LAUNCH_TYPE) && !launch.isTerminated()) {
return true;
}

}

}
return false;
}

}
Loading

0 comments on commit 8e73224

Please sign in to comment.