Skip to content

Commit

Permalink
Improve property tester to check the selection on Debug View and decide
Browse files Browse the repository at this point in the history
the visibility of commands.

Basically we need to have Debug View for an application under debug. So
asking the selection from Debug View and checking it against an active
DSF session should give the most accurate visibility condition.

Along with this we plan to show the commands in all views if any of the
view is pinned.
  • Loading branch information
raghucssit committed Jan 24, 2025
1 parent cc045d1 commit d502e84
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 105 deletions.
37 changes: 18 additions & 19 deletions debug/org.eclipse.cdt.debug.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,10 @@
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.debug.ui.VariableView?after=additions">
<separator
name="org.eclipse.cdt.debug.ui.pinGroup"
visible="true">
</separator>
<command
commandId="org.eclipse.cdt.debug.ui.PinViewCommand"
icon="icons/elcl16/toolbar_pinned.gif"
Expand All @@ -1343,8 +1347,7 @@
<visibleWhen
checkEnabled="false">
<test
args="Variables"
property="org.eclipse.cdt.debug.ui.canPinViewEnabled">
property="org.eclipse.cdt.dsf.ui.canPinViewEnabled">
</test>
</visibleWhen>
</command>
Expand All @@ -1356,15 +1359,18 @@
<visibleWhen
checkEnabled="false">
<test
args="Variables"
property="org.eclipse.cdt.debug.ui.canPinViewEnabled">
property="org.eclipse.cdt.dsf.ui.canPinViewEnabled">
</test>
</visibleWhen>
</command>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.debug.ui.ExpressionView?after=additions">
<separator
name="org.eclipse.cdt.debug.ui.pinGroup"
visible="true">
</separator>
<command
commandId="org.eclipse.cdt.debug.ui.PinViewCommand"
icon="icons/elcl16/toolbar_pinned.gif"
Expand All @@ -1373,8 +1379,7 @@
<visibleWhen
checkEnabled="false">
<test
args="Expressions"
property="org.eclipse.cdt.debug.ui.canPinViewEnabled">
property="org.eclipse.cdt.dsf.ui.canPinViewEnabled">
</test>
</visibleWhen>
</command>
Expand All @@ -1386,15 +1391,18 @@
<visibleWhen
checkEnabled="false">
<test
args="Expressions"
property="org.eclipse.cdt.debug.ui.canPinViewEnabled">
property="org.eclipse.cdt.dsf.ui.canPinViewEnabled">
</test>
</visibleWhen>
</command>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.debug.ui.RegisterView?after=additions">
<separator
name="org.eclipse.cdt.debug.ui.pinGroup"
visible="true">
</separator>
<command
commandId="org.eclipse.cdt.debug.ui.PinViewCommand"
icon="icons/elcl16/toolbar_pinned.gif"
Expand All @@ -1403,8 +1411,7 @@
<visibleWhen
checkEnabled="false">
<test
args="Registers"
property="org.eclipse.cdt.debug.ui.canPinViewEnabled">
property="org.eclipse.cdt.dsf.ui.canPinViewEnabled">
</test>
</visibleWhen>
</command>
Expand All @@ -1416,8 +1423,7 @@
<visibleWhen
checkEnabled="false">
<test
args="Registers"
property="org.eclipse.cdt.debug.ui.canPinViewEnabled">
property="org.eclipse.cdt.dsf.ui.canPinViewEnabled">
</test>
</visibleWhen>
</command>
Expand Down Expand Up @@ -2640,13 +2646,6 @@
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.

13 changes: 9 additions & 4 deletions dsf/org.eclipse.cdt.dsf.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,7 @@
<visibleWhen
checkEnabled="false">
<test
args="Disassembly"
property="org.eclipse.cdt.debug.ui.canPinViewEnabled">
property="org.eclipse.cdt.dsf.ui.canPinViewEnabled">
</test>
</visibleWhen>
</command>
Expand All @@ -359,8 +358,7 @@
<visibleWhen
checkEnabled="false">
<test
args="Disassembly"
property="org.eclipse.cdt.debug.ui.canPinViewEnabled">
property="org.eclipse.cdt.dsf.ui.canPinViewEnabled">
</test>
</visibleWhen>
</command>
Expand Down Expand Up @@ -582,6 +580,13 @@
properties="isDisassemblyViewSupportsCBreakpoint"
type="org.eclipse.cdt.dsf.debug.internal.ui.disassembly.DisassemblyPart">
</propertyTester>
<propertyTester
class="org.eclipse.cdt.dsf.debug.internal.ui.debugview.layout.PinCommandEnablementTester"
id="org.eclipse.cdt.dsf.ui.pinViewPropertyTester"
namespace="org.eclipse.cdt.dsf.ui"
properties="canPinViewEnabled"
type="java.lang.Object">
</propertyTester>
</extension>
<extension
point="org.eclipse.debug.ui.detailPaneFactories">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.eclipse.cdt.dsf.debug.internal.ui.debugview.layout;

import org.eclipse.cdt.debug.internal.ui.actions.PinViewHandler;
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.IDebugUIConstants;
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 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 DebugViewLayoutTester {

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)) {

// We enable Pin Command on all views if it is pinned in any View.
if (!PinViewHandler.getPinnedViews().isEmpty()) {
return true;
}

//Check if 'Debug View' is present and there is a valid selection.
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IViewPart debugPart = page.findView(IDebugUIConstants.ID_DEBUG_VIEW);
if (debugPart != null) {
ISelection debugContext = DebugUITools.getDebugContextForPart(debugPart);
if (debugContext instanceof IStructuredSelection structSel) {
Object firstEle = structSel.getFirstElement();
if (firstEle instanceof IDMVMContext) {
return super.test(firstEle, IS_GROUP_VISIBLE, args, expectedValue);
}
}
}
}
}
}
return false;
}

}

0 comments on commit d502e84

Please sign in to comment.