1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

[258284] Reverse buttons only appear when reverse debugging is toggled AND when the Reverse Debugging ActionSet is enabled. There seems to be a bug when a non-debug view is selected and the Reverse Debugging is toggled.

This commit is contained in:
Marc Khouzam 2009-01-27 20:36:10 +00:00
parent 1c7af7c359
commit 198cacd1f6
4 changed files with 197 additions and 51 deletions

View file

@ -221,7 +221,7 @@
<visibleWhen
checkEnabled="false">
<reference
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingActionSetActive">
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingEnabled">
</reference>
</visibleWhen>
</command>
@ -236,7 +236,7 @@
<visibleWhen
checkEnabled="false">
<reference
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingActionSetActive">
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingEnabled">
</reference>
</visibleWhen>
</command>
@ -251,7 +251,7 @@
<visibleWhen
checkEnabled="false">
<reference
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingActionSetActive">
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingEnabled">
</reference>
</visibleWhen>
</command>
@ -263,6 +263,22 @@
icon="icons/full/obj16/uncall.gif"
label="%command.uncall.label"
style="push">
<visibleWhen
checkEnabled="false">
<reference
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingEnabled">
</reference>
</visibleWhen>
</command>
</menuContribution>
<menuContribution
locationURI="menu:org.eclipse.ui.run?before=stepGroup">
<command
commandId="org.eclipse.cdt.dsf.gdb.ui.commands.reverseToggle"
icon="icons/full/obj16/reversetoggle.gif"
id="org.eclipse.cdt.dsf.gdb.ui.button.reverseToggle"
label="%command.reverseToggle.label"
style="toggle">
<visibleWhen
checkEnabled="false">
<reference
@ -281,7 +297,7 @@
<visibleWhen
checkEnabled="false">
<reference
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingActionSetActive">
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingEnabled">
</reference>
</visibleWhen>
</command>
@ -296,7 +312,7 @@
<visibleWhen
checkEnabled="false">
<reference
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingActionSetActive">
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingEnabled">
</reference>
</visibleWhen>
</command>
@ -311,7 +327,7 @@
<visibleWhen
checkEnabled="false">
<reference
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingActionSetActive">
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingEnabled">
</reference>
</visibleWhen>
</command>
@ -326,7 +342,7 @@
<visibleWhen
checkEnabled="false">
<reference
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingActionSetActive">
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingEnabled">
</reference>
</visibleWhen>
</command>
@ -341,7 +357,7 @@
<visibleWhen
checkEnabled="false">
<reference
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingActionSetActive">
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingEnabled">
</reference>
</visibleWhen>
</command>
@ -356,7 +372,7 @@
<visibleWhen
checkEnabled="false">
<reference
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingActionSetActive">
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingEnabled">
</reference>
</visibleWhen>
</command>
@ -371,7 +387,7 @@
<visibleWhen
checkEnabled="false">
<reference
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingActionSetActive">
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingEnabled">
</reference>
</visibleWhen>
</command>
@ -386,7 +402,7 @@
<visibleWhen
checkEnabled="false">
<reference
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingActionSetActive">
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingEnabled">
</reference>
</visibleWhen>
</command>
@ -444,6 +460,32 @@
</test>
</with>
</definition>
<definition
id="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingEnabled">
<and>
<reference
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsGdbUIPluginActive">
</reference>
<reference
definitionId="org.eclipse.cdt.dsf.gdb.ui.testIsReverseDebuggingActionSetActive">
</reference>
<or>
<with
variable="activePart">
<test
property="org.eclipse.cdt.dsf.gdb.ui.isReverseDebuggingEnabled">
</test>
</with>
<with
variable="selection">
<test
property="org.eclipse.cdt.dsf.gdb.ui.isReverseDebuggingEnabled">
</test>
</with>
</or>
</and>
</definition>
</extension>
<extension
point="org.eclipse.ui.handlers">
@ -500,14 +542,14 @@
id="org.eclipse.cdt.dsf.gdb.ui.selectionReverseDebuggingTester"
namespace="org.eclipse.cdt.dsf.gdb.ui"
properties="isReverseDebuggingEnabled"
type="org.eclipse.jface.viewers.TreeSelection">
type="org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext">
</propertyTester>
<propertyTester
class="org.eclipse.cdt.dsf.gdb.internal.ui.actions.ReverseDebuggingPropertyTester"
id="org.eclipse.cdt.dsf.gdb.ui.partReverseDebuggingTester"
namespace="org.eclipse.cdt.dsf.gdb.ui"
properties="isReverseDebuggingEnabled"
type="org.eclipse.debug.ui.IDebugView">
type="org.eclipse.ui.IWorkbenchPart">
</propertyTester>
</extension>

View file

@ -0,0 +1,92 @@
/*******************************************************************************
* Copyright (c) 2009 Ericsson and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Ericsson - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.dsf.gdb.internal.ui.actions;
import org.eclipse.cdt.dsf.datamodel.DMContexts;
import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService.ICommandControlDMContext;
import org.eclipse.cdt.dsf.gdb.actions.IReverseToggleHandler;
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.contexts.IDebugContextService;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.IWorkbenchPart;
/**
* Property tester for reverse debugging information available through the given
* object. The object being tested could either be a {@link IWorkbenchPart} or
* a {@link IDMVMContext}.
* <p>
* One property is supported:
* <ul>
* <li> "isReverseDebuggingEnabled" - Checks whether reverse debugging is currently
* enabled given the receiver.</li>
* </ul>
* </p>
*/
public class ReverseDebuggingPropertyTester extends PropertyTester {
private static final String ENABLED = "isReverseDebuggingEnabled"; //$NON-NLS-1$
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (ENABLED.equals(property)) {
if (receiver instanceof IWorkbenchPart) {
Object selection = getContextSelectionForPart((IWorkbenchPart)receiver);
if (selection instanceof IDMVMContext) {
return test((IDMVMContext)selection);
}
} else if (receiver instanceof IDMVMContext) {
return test((IDMVMContext)receiver);
}
}
return false;
}
private boolean test(IDMVMContext context) {
ICommandControlDMContext controlDmc = DMContexts.getAncestorOfType(context.getDMContext(), ICommandControlDMContext.class);
if (controlDmc != null) {
IReverseToggleHandler toggle = (IReverseToggleHandler)(controlDmc.getAdapter(IReverseToggleHandler.class));
if (toggle != null) {
boolean t= toggle.isReverseToggled(controlDmc);
return t;
}
}
return false;
}
private static Object getContextSelectionForPart(IWorkbenchPart part) {
IDebugContextService contextService =
DebugUITools.getDebugContextManager().getContextService(part.getSite().getWorkbenchWindow());
ISelection debugContext = contextService.getActiveContext(getPartId(part));
if (debugContext == null) {
debugContext = contextService.getActiveContext();
}
if (debugContext instanceof IStructuredSelection) {
return ((IStructuredSelection)debugContext).getFirstElement();
}
return null;
}
private static String getPartId(IWorkbenchPart part) {
if (part instanceof IViewPart) {
IViewSite site = (IViewSite)part.getSite();
return site.getId() + (site.getSecondaryId() != null ? (":" + site.getSecondaryId()) : ""); //$NON-NLS-1$ //$NON-NLS-2$
} else {
return part.getSite().getId();
}
}
}

View file

@ -10,18 +10,21 @@
*******************************************************************************/
package org.eclipse.cdt.dsf.gdb.internal.ui.actions;
import java.util.Map;
import org.eclipse.cdt.dsf.gdb.actions.IReverseToggleHandler;
import org.eclipse.cdt.dsf.gdb.internal.ui.viewmodel.commands.RetargetDebugContextCommand;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.debug.ui.contexts.DebugContextEvent;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.menus.UIElement;
/**
* Command handler to toggle reverse debugging mode
*
* @since 2.0
*/
public class ReverseToggleCommandHandler extends RetargetDebugContextCommand {
public class ReverseToggleCommandHandler extends RetargetDebugContextCommand implements IElementUpdater {
@Override
protected boolean canPerformCommand(Object target, ISelection debugContext) {
@ -37,17 +40,16 @@ public class ReverseToggleCommandHandler extends RetargetDebugContextCommand {
protected void performCommand(Object target, ISelection debugContext) throws ExecutionException {
((IReverseToggleHandler)target).toggleReverse(debugContext);
}
@Override
public void debugContextChanged(DebugContextEvent event) {
super.debugContextChanged(event);
public void updateElement(UIElement element, Map parameters) {
// Make sure the toggle state reflects the actual state
// We must check this, in case we have multiple launches
// or if we re-launch
if (fTargetAdapter != null && fToolItem != null) {
boolean toggled = ((IReverseToggleHandler)fTargetAdapter).isReverseToggled(event.getContext());
fToolItem.setSelection(toggled);
}
}
if (getTargetAdapter() == null) {
element.setChecked(false);
} else {
boolean toggled = ((IReverseToggleHandler)getTargetAdapter()).isReverseToggled(getDebugContext());
element.setChecked(toggled);
}
}
}

View file

@ -26,10 +26,11 @@ import org.eclipse.debug.ui.contexts.IDebugContextService;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.HandlerUtil;
/**
* Base class for actions which delegate functionality to an adapter retrieved
@ -39,41 +40,39 @@ import org.eclipse.ui.PlatformUI;
*/
abstract public class RetargetDebugContextCommand extends AbstractHandler implements IDebugContextListener {
private IWorkbenchWindow fWindow = null;
private ISelection fDebugContext;
protected Object fTargetAdapter = null;
// The button representing the command
protected ToolItem fToolItem = null;
private Object fTargetAdapter = null;
private IDebugContextService fContextService = null;
private String fCommandId = null;
protected Object getTargetAdapter() { return fTargetAdapter; }
protected ISelection getDebugContext() { return fDebugContext; }
/* (non-Javadoc)
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
*/
public RetargetDebugContextCommand() {
fWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IDebugContextService debugContextService = DebugUITools.getDebugContextManager().getContextService(fWindow);
debugContextService.addPostDebugContextListener(this);
fDebugContext = debugContextService.getActiveContext();
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
fContextService = DebugUITools.getDebugContextManager().getContextService(window);
fContextService.addPostDebugContextListener(this);
fDebugContext = fContextService.getActiveContext();
update();
}
public Object execute(ExecutionEvent event) throws ExecutionException {
// Store the toolItem in case we need to act on it.
fToolItem = null;
if (event.getTrigger() instanceof Event) {
Event swtEvent = (Event)event.getTrigger();
if (swtEvent.widget instanceof ToolItem) {
fToolItem = (ToolItem)swtEvent.widget;
}
}
fCommandId = event.getCommand().getId();
if (fTargetAdapter != null) {
try {
performCommand(fTargetAdapter, fDebugContext);
} catch (ExecutionException e) {
ErrorDialog.openError(fWindow.getShell(), MessagesForVMActions.RetargetDebugContextAction_ErrorDialog_title, MessagesForVMActions.RetargetDebugContextAction_ErrorDialog_message, null);
Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell();
ErrorDialog.openError(shell, MessagesForVMActions.RetargetDebugContextAction_ErrorDialog_title, MessagesForVMActions.RetargetDebugContextAction_ErrorDialog_message, null);
}
}
update();
return null;
}
@ -103,6 +102,8 @@ abstract public class RetargetDebugContextCommand extends AbstractHandler implem
protected abstract Class<?> getAdapterClass();
public void update() {
boolean enabled = false;
fTargetAdapter = null;
if (fDebugContext instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection) fDebugContext;
@ -111,19 +112,28 @@ abstract public class RetargetDebugContextCommand extends AbstractHandler implem
if (object instanceof IAdaptable) {
fTargetAdapter = getAdapter((IAdaptable) object);
if (fTargetAdapter != null) {
setBaseEnabled(canPerformCommand(fTargetAdapter, fDebugContext));
return;
}
enabled = canPerformCommand(fTargetAdapter, fDebugContext);
}
}
}
}
setBaseEnabled(false);
setBaseEnabled(enabled);
if (fCommandId != null) {
ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
if (commandService != null) {
commandService.refreshElements(fCommandId, null);
}
}
}
@Override
public void dispose() {
DebugUITools.getDebugContextManager().getContextService(fWindow).removePostDebugContextListener(this);
// Must use the stored service. If we try to fetch the service
// again with the workbenchWindow, it may fail if the window is
// already closed.
fContextService.removePostDebugContextListener(this);
fTargetAdapter = null;
}