mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Bug 289526 - [debug view] Migrate the Restart feature to the new one, as supported by the platform
This commit is contained in:
parent
5691d8b306
commit
0c30d752e0
11 changed files with 170 additions and 183 deletions
|
@ -18,7 +18,9 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.debug.core.breakpointactions.BreakpointActionManager;
|
||||
import org.eclipse.cdt.debug.core.command.CCommandAdapterFactory;
|
||||
import org.eclipse.cdt.debug.core.disassembly.IDisassemblyContextService;
|
||||
import org.eclipse.cdt.debug.core.model.IRestart;
|
||||
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation;
|
||||
import org.eclipse.cdt.debug.internal.core.DebugConfiguration;
|
||||
import org.eclipse.cdt.debug.internal.core.ICDebugInternalConstants;
|
||||
|
@ -31,6 +33,7 @@ import org.eclipse.cdt.debug.internal.core.sourcelookup.SourceUtils;
|
|||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IAdapterManager;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
import org.eclipse.core.runtime.IExtensionPoint;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
|
@ -331,6 +334,7 @@ public class CDebugCorePlugin extends Plugin {
|
|||
public void start( BundleContext context ) throws Exception {
|
||||
super.start( context );
|
||||
initializeCommonSourceLookupDirector();
|
||||
createCommandAdapterFactory();
|
||||
createBreakpointListenersList();
|
||||
createDisassemblyContextService();
|
||||
setSessionManager( new SessionManager() );
|
||||
|
@ -349,6 +353,12 @@ public class CDebugCorePlugin extends Plugin {
|
|||
super.stop( context );
|
||||
}
|
||||
|
||||
private void createCommandAdapterFactory() {
|
||||
IAdapterManager manager= Platform.getAdapterManager();
|
||||
CCommandAdapterFactory actionFactory = new CCommandAdapterFactory();
|
||||
manager.registerAdapters(actionFactory, IRestart.class);
|
||||
}
|
||||
|
||||
private void initializeCommonSourceLookupDirector() {
|
||||
if ( fCommonSourceLookupDirector == null ) {
|
||||
fCommonSourceLookupDirector = new CommonSourceLookupDirector();
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2010 IBM Corporation 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:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Wind River Systems - copied to use in CDT
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.core.command;
|
||||
|
||||
import org.eclipse.cdt.debug.core.model.IRestart;
|
||||
import org.eclipse.core.runtime.IAdapterFactory;
|
||||
import org.eclipse.debug.core.commands.IRestartHandler;
|
||||
|
||||
/**
|
||||
* Adapter factory for debug commands.
|
||||
*
|
||||
* @see org.eclipse.debug.core.command
|
||||
*
|
||||
* @since 7.0
|
||||
*
|
||||
*/
|
||||
public class CCommandAdapterFactory implements IAdapterFactory {
|
||||
private static IRestartHandler fgRestartCommand = new RestartCommand();
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
|
||||
*/
|
||||
public Object getAdapter(Object adaptableObject, Class adapterType) {
|
||||
if (IRestartHandler.class.equals(adapterType)) {
|
||||
if (adaptableObject instanceof IRestart) {
|
||||
return fgRestartCommand;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
|
||||
*/
|
||||
public Class[] getAdapterList() {
|
||||
return new Class[] {
|
||||
IRestartHandler.class
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2010 IBM Corporation 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:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Wind River Systems - copied to use in CDT
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.core.command;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.debug.core.IRequest;
|
||||
import org.eclipse.debug.core.commands.AbstractDebugCommand;
|
||||
import org.eclipse.debug.core.commands.IEnabledStateRequest;
|
||||
|
||||
/**
|
||||
* A command that operates on each element individually.
|
||||
* <p>
|
||||
* Note: copied from org.eclipse.debug.core.command.ForEachCommand.
|
||||
* </p>
|
||||
* @since 7.0
|
||||
*/
|
||||
public abstract class CForEachCommand extends AbstractDebugCommand {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.debug.internal.core.commands.DebugCommand#doExecute(java.lang.Object[], org.eclipse.core.runtime.IProgressMonitor, org.eclipse.debug.core.IRequest)
|
||||
*/
|
||||
protected void doExecute(Object[] targets, IProgressMonitor monitor, IRequest request) throws CoreException {
|
||||
for (int i = 0; i < targets.length; i++) {
|
||||
execute(targets[i]);
|
||||
monitor.worked(1);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void execute(Object target) throws CoreException;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.debug.internal.core.commands.DebugCommand#isExecutable(java.lang.Object[], org.eclipse.core.runtime.IProgressMonitor, org.eclipse.debug.core.commands.IEnabledStateRequest)
|
||||
*/
|
||||
protected boolean isExecutable(Object[] targets, IProgressMonitor monitor, IEnabledStateRequest request) throws CoreException {
|
||||
for (int i = 0; i < targets.length; i++) {
|
||||
if (!isExecutable(targets[i])) {
|
||||
return false;
|
||||
}
|
||||
monitor.worked(1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract boolean isExecutable(Object target);
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2010 IBM Corporation 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:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Wind River Systems - adopted to use for restart command
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.core.command;
|
||||
|
||||
import org.eclipse.cdt.debug.core.model.IRestart;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.debug.core.commands.IDebugCommandRequest;
|
||||
import org.eclipse.debug.core.commands.IRestartHandler;
|
||||
|
||||
/**
|
||||
* Default restart command for CDI
|
||||
*
|
||||
* @since 7.0
|
||||
*/
|
||||
public class RestartCommand extends CForEachCommand implements IRestartHandler {
|
||||
|
||||
protected Object getTarget(Object element) {
|
||||
return getAdapter(element, IRestart.class);
|
||||
}
|
||||
|
||||
protected void execute(Object target) throws CoreException {
|
||||
((IRestart)target).restart();
|
||||
}
|
||||
|
||||
protected boolean isExecutable(Object target) {
|
||||
return ((IRestart)target).canRestart();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.debug.core.commands.AbstractDebugCommand#getEnabledStateJobFamily(org.eclipse.debug.core.commands.IDebugCommandRequest)
|
||||
*/
|
||||
protected Object getEnabledStateJobFamily(IDebugCommandRequest request) {
|
||||
return IRestart.class;
|
||||
}
|
||||
}
|
|
@ -14,10 +14,17 @@ package org.eclipse.cdt.debug.core.model;
|
|||
|
||||
import org.eclipse.debug.core.DebugException;
|
||||
/**
|
||||
* Provides the ability to restart a debug target.
|
||||
* Provides the ability to restart a debug target.
|
||||
* <p>
|
||||
* Note: Debug elements which support restart should implement this interface.
|
||||
* Adopting to this interface is not enough.
|
||||
* </p>
|
||||
* <p>
|
||||
* Note 2: Debugger can also implement the asynchronous
|
||||
* {@link org.eclipse.debug.core.commands.IRestartHandler}.
|
||||
* </p>
|
||||
*
|
||||
* @deprecated Use org.eclipse.debug.core.commands.IRestartHandler instead. IRestartHandler
|
||||
* handles the call in an asynchronous fashion.
|
||||
* @see org.eclipse.debug.core.commands.IRestartHandler
|
||||
*/
|
||||
public interface IRestart
|
||||
{
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 344 B |
Binary file not shown.
Before Width: | Height: | Size: 353 B |
|
@ -27,9 +27,6 @@ BreakpointActionPage.name=Breakpoint Action UI Page
|
|||
RunMenu.label=&Run
|
||||
DebugActionSet.label=C/C++ Debug
|
||||
|
||||
RestartAction.label=Restart
|
||||
RestartAction.tooltip=Restart
|
||||
|
||||
DisassemblyViewAction.label=Go to address...
|
||||
DisassemblyViewAction.tooltip=Enter memory address for the assembly code
|
||||
|
||||
|
|
|
@ -247,15 +247,6 @@
|
|||
helpContextId="move_to_line_action_context"
|
||||
label="%GlobalMoveToLineAction.label"
|
||||
menubarPath="org.eclipse.ui.run/stepGroup"/>
|
||||
<action
|
||||
id="org.eclipse.cdt.debug.ui.internal.actions.RestartActionDelegate"
|
||||
class="org.eclipse.cdt.debug.internal.ui.actions.RestartActionDelegate"
|
||||
disabledIcon="icons/dlcl16/restart.gif"
|
||||
icon="icons/elcl16/restart.gif"
|
||||
helpContextId="restart_action_context"
|
||||
label="%RestartAction.label"
|
||||
menubarPath="org.eclipse.ui.run/stepGroup">
|
||||
</action>
|
||||
</actionSet>
|
||||
</extension>
|
||||
<extension
|
||||
|
@ -372,32 +363,6 @@
|
|||
</propertyTester>
|
||||
</extension>
|
||||
|
||||
<!-- Bug 289526 [debug view] Migrate the Restart feature to the new one, as supported by the platform
|
||||
Don't contribute this action to context menu if selection isn't an IRestart. Debug platform
|
||||
already contributes it. -->
|
||||
<extension
|
||||
point="org.eclipse.ui.popupMenus">
|
||||
<viewerContribution
|
||||
targetID="org.eclipse.debug.ui.DebugView"
|
||||
id="org.eclipse.cdt.debug.ui.debugview.popupMenu2">
|
||||
<action
|
||||
label="%RestartAction.label"
|
||||
icon="icons/elcl16/restart.gif"
|
||||
helpContextId="restart_action_context"
|
||||
class="org.eclipse.cdt.debug.internal.ui.actions.RestartActionDelegate"
|
||||
menubarPath="stepGroup"
|
||||
enablesFor="1"
|
||||
id="org.eclipse.cdt.debug.internal.ui.actions.RestartActionDelegate">
|
||||
<selection class="org.eclipse.cdt.debug.core.model.IRestart"/>
|
||||
|
||||
</action>
|
||||
<visibility>
|
||||
<objectClass name="org.eclipse.cdt.debug.core.model.IRestart"/>
|
||||
</visibility>
|
||||
</viewerContribution>
|
||||
</extension>
|
||||
|
||||
|
||||
<extension
|
||||
point="org.eclipse.ui.popupMenus">
|
||||
<viewerContribution
|
||||
|
|
|
@ -65,9 +65,6 @@ ManageFunctionBreakpointActionDelegate.Error_1=Error
|
|||
ManageFunctionBreakpointActionDelegate.Operation_failed_1=Operation failed.
|
||||
SignalActionDelegate.0=Unable to deliver the signal to the target.
|
||||
SignalActionDelegate.1=Operation failed.
|
||||
RestartActionDelegate.0=Exception(s) occurred attempting to restart.
|
||||
RestartActionDelegate.1=Restart failed.
|
||||
RestartActionDelegate.2=Restart
|
||||
AddGlobalsActionDelegate.0=Select Variables:
|
||||
AddGlobalsActionDelegate.1=Add global variables failed.
|
||||
VariableFormatActionDelegate.0=Unable to set format.
|
||||
|
|
|
@ -1,139 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2010 QNX Software Systems 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:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* Navid Mehregani (TI) - Bug 289526 - Migrate the Restart feature to the new one, as supported by the platform
|
||||
* Wind River Systems - Bug 289526 - Additional fixes
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.internal.ui.actions;
|
||||
|
||||
import org.eclipse.cdt.debug.core.model.IRestart;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.debug.core.DebugException;
|
||||
import org.eclipse.debug.core.commands.IRestartHandler;
|
||||
import org.eclipse.debug.core.model.IDebugElement;
|
||||
import org.eclipse.debug.core.model.IDebugTarget;
|
||||
import org.eclipse.debug.internal.ui.commands.actions.RestartCommandAction;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.ui.IViewPart;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
|
||||
/**
|
||||
* The delegate of the "Restart" action.
|
||||
*/
|
||||
public class RestartActionDelegate extends AbstractListenerActionDelegate {
|
||||
|
||||
private RestartCommandAction fRestartCommandAction;
|
||||
|
||||
@Override
|
||||
public void init(IAction action) {
|
||||
setAction(action);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.debug.internal.ui.actions.AbstractDebugActionDelegate#doAction(java.lang.Object)
|
||||
*/
|
||||
protected void doAction( Object element ) throws DebugException {
|
||||
IRestartHandler asynchronousRestartHandler = getAsynchronousRestartHandler( element );
|
||||
if (asynchronousRestartHandler!=null && fRestartCommandAction!=null ) {
|
||||
fRestartCommandAction.run();
|
||||
} else {
|
||||
IRestart restartTarget = getRestartTarget( element );
|
||||
if ( restartTarget != null ) {
|
||||
restartTarget.restart();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(IViewPart view) {
|
||||
super.init(view);
|
||||
fRestartCommandAction = new RestartCommandAction();
|
||||
fRestartCommandAction.setActionProxy(getAction());
|
||||
fRestartCommandAction.init(getView());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(IWorkbenchWindow window) {
|
||||
super.init(window);
|
||||
fRestartCommandAction = new RestartCommandAction();
|
||||
fRestartCommandAction.setActionProxy(getAction());
|
||||
fRestartCommandAction.init(getWindow());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.debug.internal.ui.actions.AbstractDebugActionDelegate#isEnabledFor(java.lang.Object)
|
||||
*/
|
||||
protected boolean isEnabledFor( Object element ) {
|
||||
IRestartHandler asynchronousRestartHandler = getAsynchronousRestartHandler( element );
|
||||
if (asynchronousRestartHandler!=null && fRestartCommandAction!=null) {
|
||||
return fRestartCommandAction.isEnabled();
|
||||
} else {
|
||||
IRestart restartTarget = getRestartTarget( element );
|
||||
if ( restartTarget != null ) {
|
||||
return checkCapability( restartTarget );
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean checkCapability( IRestart element ) {
|
||||
return element.canRestart();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.debug.internal.ui.actions.AbstractDebugActionDelegate#getStatusMessage()
|
||||
*/
|
||||
protected String getStatusMessage() {
|
||||
return ActionMessages.getString( "RestartActionDelegate.0" ); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.debug.internal.ui.actions.AbstractDebugActionDelegate#getErrorDialogMessage()
|
||||
*/
|
||||
protected String getErrorDialogMessage() {
|
||||
return ActionMessages.getString( "RestartActionDelegate.1" ); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.debug.internal.ui.actions.AbstractDebugActionDelegate#getErrorDialogTitle()
|
||||
*/
|
||||
protected String getErrorDialogTitle() {
|
||||
return ActionMessages.getString( "RestartActionDelegate.2" ); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.debug.internal.ui.actions.AbstractDebugActionDelegate#isRunInBackground()
|
||||
*/
|
||||
protected boolean isRunInBackground() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected IRestart getRestartTarget( Object element ) {
|
||||
if ( element instanceof IAdaptable )
|
||||
return (IRestart)((IAdaptable)element).getAdapter( IRestart.class );
|
||||
return getDefaultRestartTarget( element );
|
||||
}
|
||||
|
||||
protected IRestartHandler getAsynchronousRestartHandler( Object element ) {
|
||||
if ( element instanceof IAdaptable )
|
||||
return (IRestartHandler)((IAdaptable)element).getAdapter( IRestartHandler.class );
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private IRestart getDefaultRestartTarget( Object element ) {
|
||||
if ( element instanceof IDebugElement ) {
|
||||
IDebugTarget target = ((IDebugElement)element).getDebugTarget();
|
||||
if ( target instanceof IRestart )
|
||||
return (IRestart)target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue