1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 12:55:40 +02:00

[302273 ] Update CDT's copy of RetargetAction to match the latest platform code

This commit is contained in:
Marc Khouzam 2010-02-09 15:58:49 +00:00
parent 8b864e98a5
commit e3a4b6dcbe
4 changed files with 215 additions and 117 deletions

View file

@ -129,3 +129,7 @@ ToggleCBreakpointsTargetFactory.CBreakpointDescription=Standard C/C++ breakpoint
ToggleCBreakpointsTargetFactory.CBreakpointName=C/C++ Breakpoints ToggleCBreakpointsTargetFactory.CBreakpointName=C/C++ Breakpoints
ToggleCBreakpointsTargetFactory.CTracepointDescription=Standard C/C++ tracepoint type. ToggleCBreakpointsTargetFactory.CTracepointDescription=Standard C/C++ tracepoint type.
ToggleCBreakpointsTargetFactory.CTracepointName=C/C++ Tracepoints ToggleCBreakpointsTargetFactory.CTracepointName=C/C++ Tracepoints
RetargetAction.0=Error
RetargetAction.1=Operation failed
RetargetMoveToLineAction.0=The operation is unavailable on the current selection. Please place the cursor on valid line to run to.
RetargetResumeAtLineAction.0=The operation is unavailable on the current selection. Please place the cursor on valid line to run to.

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2000, 2007 IBM Corporation and others. * Copyright (c) 2000, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -8,6 +8,7 @@
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
* Anton Leherbauer (Wind River Systems) - bug 183291 * Anton Leherbauer (Wind River Systems) - bug 183291
* Ericsson - Updated to the latest platform version of this file
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions; package org.eclipse.cdt.debug.internal.ui.actions;
@ -15,26 +16,28 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IAdapterManager; import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.IActionDelegate2;
import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IPartListener; import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IPartService; import org.eclipse.ui.IPartService;
import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.texteditor.IUpdate;
/** /**
* Global retargettable debug action. * Global retargettable debug action.
*
* @since 3.0
*/ */
public abstract class RetargetAction implements IWorkbenchWindowActionDelegate, IPartListener, IUpdate { public abstract class RetargetAction implements IWorkbenchWindowActionDelegate, IPartListener, IActionDelegate2 {
protected IWorkbenchWindow fWindow = null; protected IWorkbenchWindow fWindow = null;
private IWorkbenchPart fActivePart = null; private IWorkbenchPart fActivePart = null;
@ -59,7 +62,7 @@ public abstract class RetargetAction implements IWorkbenchWindowActionDelegate,
* *
* @return the selection in the active part, possibly empty * @return the selection in the active part, possibly empty
*/ */
private ISelection getTargetSelection() { protected ISelection getTargetSelection() {
if (fActivePart != null) { if (fActivePart != null) {
ISelectionProvider selectionProvider = fActivePart.getSite().getSelectionProvider(); ISelectionProvider selectionProvider = fActivePart.getSite().getSelectionProvider();
if (selectionProvider != null) { if (selectionProvider != null) {
@ -69,6 +72,10 @@ public abstract class RetargetAction implements IWorkbenchWindowActionDelegate,
return EMPTY_SELECTION; return EMPTY_SELECTION;
} }
protected IWorkbenchPart getActivePart() {
return fActivePart;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
*/ */
@ -96,19 +103,34 @@ public abstract class RetargetAction implements IWorkbenchWindowActionDelegate,
public void run(IAction action) { public void run(IAction action) {
if (fTargetAdapter != null) { if (fTargetAdapter != null) {
try { try {
performAction(fTargetAdapter, getTargetSelection(), fActivePart); if (isTargetEnabled()) {
performAction(fTargetAdapter, getTargetSelection(), fActivePart);
} else {
String message = getOperationUnavailableMessage();
IStatus status = new Status(IStatus.INFO, DebugUIPlugin.getUniqueIdentifier(), message);
DebugUIPlugin.errorDialog(DebugUIPlugin.getShell(), DebugUIPlugin.removeAccelerators(action.getText()), message, status);
}
} catch (CoreException e) { } catch (CoreException e) {
ErrorDialog.openError(fWindow.getShell(), ActionMessages.getString("RetargetAction.2"), ActionMessages.getString("RetargetAction.3"), e.getStatus()); //$NON-NLS-1$ //$NON-NLS-2$ ErrorDialog.openError(fWindow.getShell(), ActionMessages.getString("RetargetAction.0"), ActionMessages.getString("RetargetAction.1"), e.getStatus()); //$NON-NLS-1$ //$NON-NLS-2$
} }
} }
} }
/**
* Returns a message to display when we find that the operation is not enabled
* when invoked in an editor (we check enabled state before running in this case,
* rather than updating on each selection change - see bug 180441).
*
* @return information message when unavailable
*/
protected abstract String getOperationUnavailableMessage();
/** /**
* Performs the specific breakpoint toggling. * Performs the specific breakpoint toggling.
* *
* @param selection selection in the active part * @param selection selection in the active part
* @param part active part * @param part active part
* @throws CoreException if an exception occurrs * @throws CoreException if an exception occurs
*/ */
protected abstract void performAction(Object target, ISelection selection, IWorkbenchPart part) throws CoreException; protected abstract void performAction(Object target, ISelection selection, IWorkbenchPart part) throws CoreException;
@ -116,8 +138,7 @@ public abstract class RetargetAction implements IWorkbenchWindowActionDelegate,
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
*/ */
public void selectionChanged(IAction action, ISelection selection) { public void selectionChanged(IAction action, ISelection selection) {
this.fAction = action; // if the active part did not provide an adapter, see if the selection does
// if the active part did not provide an adapter, see if the selectoin does
if (fTargetAdapter == null && selection instanceof IStructuredSelection) { if (fTargetAdapter == null && selection instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection) selection; IStructuredSelection ss = (IStructuredSelection) selection;
if (!ss.isEmpty()) { if (!ss.isEmpty()) {
@ -127,7 +148,11 @@ public abstract class RetargetAction implements IWorkbenchWindowActionDelegate,
} }
} }
} }
update(); boolean enabled = fTargetAdapter != null;
if (selection instanceof IStructuredSelection) {
enabled = isTargetEnabled();
}
action.setEnabled(enabled);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -145,7 +170,9 @@ public abstract class RetargetAction implements IWorkbenchWindowActionDelegate,
if (fTargetAdapter == null) { if (fTargetAdapter == null) {
fTargetAdapter = getAdapter(part); fTargetAdapter = getAdapter(part);
} }
update(); if (fAction != null) {
fAction.setEnabled(fTargetAdapter != null);
}
} }
protected Object getAdapter(IAdaptable adaptable) { protected Object getAdapter(IAdaptable adaptable) {
@ -180,9 +207,9 @@ public abstract class RetargetAction implements IWorkbenchWindowActionDelegate,
/** /**
* Clears reference to active part and adapter when a relevant part * Clears reference to active part and adapter when a relevant part
* is closed or deactivated. * is closed or no longer active.
* *
* @param part workbench part that has been closed or deactivated * @param part workbench part that has been closed or no longer active
*/ */
protected void clearPart(IWorkbenchPart part) { protected void clearPart(IWorkbenchPart part) {
if (part.equals(fActivePart)) { if (part.equals(fActivePart)) {
@ -201,18 +228,19 @@ public abstract class RetargetAction implements IWorkbenchWindowActionDelegate,
*/ */
public void partOpened(IWorkbenchPart part) { public void partOpened(IWorkbenchPart part) {
} }
/* (non-Javadoc)
* @see org.eclipse.ui.texteditor.IUpdate#update() /**
* Returns whether the target adapter is enabled
*
* @return whether target adapter is enabled
*/ */
public void update() { protected boolean isTargetEnabled() {
if (fAction == null) {
return;
}
if (fTargetAdapter != null) { if (fTargetAdapter != null) {
fAction.setEnabled(canPerformAction(fTargetAdapter, getTargetSelection(), fActivePart)); if (fActivePart != null) {
} else { return canPerformAction(fTargetAdapter, getTargetSelection(), fActivePart);
fAction.setEnabled(false); }
} }
return false;
} }
/** /**
@ -223,5 +251,37 @@ public abstract class RetargetAction implements IWorkbenchWindowActionDelegate,
* @param part the part the operation has been requested on * @param part the part the operation has been requested on
* @return whether the operation can be performed * @return whether the operation can be performed
*/ */
protected abstract boolean canPerformAction(Object target, ISelection selection, IWorkbenchPart part); protected abstract boolean canPerformAction(Object target, ISelection selection, IWorkbenchPart part);
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
*/
public void init(IAction action) {
fAction = action;
}
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
*/
public void runWithEvent(IAction action, Event event) {
run(action);
}
/**
* Returns the proxy to this action delegate or <code>null</code>
*
* @return action proxy or <code>null</code>
*/
protected IAction getAction() {
return fAction;
}
/**
* Returns whether there is currently a target adapter for this action.
*
* @return whether the action has a target adapter.
*/
protected boolean hasTargetAdapter() {
return fTargetAdapter != null;
}
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2008 Freescale Semiconductor and others. * Copyright (c) 2008, 2010 Freescale Semiconductor and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,15 +7,20 @@
* *
* Contributors: * Contributors:
* Freescale Semiconductor - Initial API and implementation * Freescale Semiconductor - Initial API and implementation
* Ericsson - Updated with the latest platform changes of RetargetAction (302273)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions; package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.ISuspendResume; import org.eclipse.debug.core.model.ISuspendResume;
import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.contexts.DebugContextEvent;
import org.eclipse.debug.ui.contexts.IDebugContextListener;
import org.eclipse.debug.ui.contexts.IDebugContextService;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindow;
@ -23,74 +28,86 @@ import org.eclipse.ui.IWorkbenchWindow;
* Global retargettable move to line action. * Global retargettable move to line action.
*/ */
public class RetargetMoveToLineAction extends RetargetAction { public class RetargetMoveToLineAction extends RetargetAction {
private ISelectionListener fSelectionListener = new DebugSelectionListener(); private DebugContextListener fContextListener = new DebugContextListener();
private ISuspendResume fTargetElement = null; private ISuspendResume fTargetElement = null;
class DebugContextListener implements IDebugContextListener {
class DebugSelectionListener implements ISelectionListener { protected void contextActivated(ISelection selection) {
fTargetElement = null;
/* (non-Javadoc) if (selection instanceof IStructuredSelection) {
* @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) IStructuredSelection ss = (IStructuredSelection) selection;
*/ if (ss.size() == 1) {
public void selectionChanged( IWorkbenchPart part, ISelection selection ) { fTargetElement = (ISuspendResume)
setTargetElement( null ); DebugPlugin.getAdapter(ss.getFirstElement(), ISuspendResume.class);
if ( selection instanceof IStructuredSelection ) {
IStructuredSelection ss = (IStructuredSelection)selection;
if ( ss.size() == 1 ) {
Object object = ss.getFirstElement();
if ( object instanceof ISuspendResume ) {
setTargetElement( (ISuspendResume)object );
}
} }
} }
update(); IAction action = getAction();
if (action != null) {
action.setEnabled(fTargetElement != null && hasTargetAdapter());
}
}
public void debugContextChanged(DebugContextEvent event) {
contextActivated(event.getContext());
} }
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
*/ */
public void dispose() { public void dispose() {
fWindow.getSelectionService().removeSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, fSelectionListener ); DebugUITools.getDebugContextManager().getContextService(fWindow).removeDebugContextListener(fContextListener);
super.dispose(); super.dispose();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
*/ */
public void init( IWorkbenchWindow window ) { public void init(IWorkbenchWindow window) {
super.init( window ); super.init(window);
window.getSelectionService().addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, fSelectionListener ); IDebugContextService service = DebugUITools.getDebugContextManager().getContextService(window);
service.addDebugContextListener(fContextListener);
ISelection activeContext = service.getActiveContext();
fContextListener.contextActivated(activeContext);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.internal.ui.actions.RetargetAction#performAction(java.lang.Object, org.eclipse.jface.viewers.ISelection, org.eclipse.ui.IWorkbenchPart) * @see org.eclipse.debug.internal.ui.actions.RetargetAction#canPerformAction(java.lang.Object, org.eclipse.jface.viewers.ISelection, org.eclipse.ui.IWorkbenchPart)
*/ */
protected void performAction( Object target, ISelection selection, IWorkbenchPart part ) throws CoreException { protected boolean canPerformAction(Object target, ISelection selection, IWorkbenchPart part) {
((IMoveToLineTarget)target).moveToLine( part, selection, getTargetElement() ); return fTargetElement != null &&
((IMoveToLineTarget)target).canMoveToLine(part, selection, fTargetElement);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.internal.ui.actions.RetargetAction#getAdapterClass() * @see org.eclipse.debug.internal.ui.actions.RetargetAction#getAdapterClass()
*/ */
protected Class<?> getAdapterClass() { protected Class getAdapterClass() {
return IMoveToLineTarget.class; return IMoveToLineTarget.class;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.internal.ui.actions.RetargetAction#canPerformAction(java.lang.Object, org.eclipse.jface.viewers.ISelection, org.eclipse.ui.IWorkbenchPart) * @see org.eclipse.debug.internal.ui.actions.RetargetAction#performAction(java.lang.Object, org.eclipse.jface.viewers.ISelection, org.eclipse.ui.IWorkbenchPart)
*/ */
protected boolean canPerformAction( Object target, ISelection selection, IWorkbenchPart part ) { protected void performAction(Object target, ISelection selection, IWorkbenchPart part) throws CoreException {
return getTargetElement() != null && ((IMoveToLineTarget)target).canMoveToLine( part, selection, getTargetElement() ); ((IMoveToLineTarget)target).moveToLine(part, selection, fTargetElement);
} }
protected ISuspendResume getTargetElement() { /* (non-Javadoc)
return fTargetElement; * @see org.eclipse.debug.internal.ui.actions.RetargetAction#getOperationUnavailableMessage()
} */
protected String getOperationUnavailableMessage() {
protected void setTargetElement( ISuspendResume targetElement ) { return ActionMessages.getString("RetargetMoveToLineAction.0"); //$NON-NLS-1$
fTargetElement = targetElement; }
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
*/
public void selectionChanged(IAction action, ISelection selection) {
if (fTargetElement == null) {
action.setEnabled(false);
} else {
super.selectionChanged(action, selection);
}
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2005 QNX Software Systems and others. * Copyright (c) 2004, 2010 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,15 +7,20 @@
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
* Ericsson - Updated with the latest platform changes of RetargetAction (302273)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions; package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.ISuspendResume; import org.eclipse.debug.core.model.ISuspendResume;
import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.contexts.DebugContextEvent;
import org.eclipse.debug.ui.contexts.IDebugContextListener;
import org.eclipse.debug.ui.contexts.IDebugContextService;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindow;
@ -23,74 +28,86 @@ import org.eclipse.ui.IWorkbenchWindow;
* Global retargettable resume at line action. * Global retargettable resume at line action.
*/ */
public class RetargetResumeAtLineAction extends RetargetAction { public class RetargetResumeAtLineAction extends RetargetAction {
private ISelectionListener fSelectionListener = new DebugSelectionListener(); private DebugContextListener fContextListener = new DebugContextListener();
private ISuspendResume fTargetElement = null; private ISuspendResume fTargetElement = null;
class DebugContextListener implements IDebugContextListener {
class DebugSelectionListener implements ISelectionListener { protected void contextActivated(ISelection selection) {
fTargetElement = null;
/* (non-Javadoc) if (selection instanceof IStructuredSelection) {
* @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) IStructuredSelection ss = (IStructuredSelection) selection;
*/ if (ss.size() == 1) {
public void selectionChanged( IWorkbenchPart part, ISelection selection ) { fTargetElement = (ISuspendResume)
setTargetElement( null ); DebugPlugin.getAdapter(ss.getFirstElement(), ISuspendResume.class);
if ( selection instanceof IStructuredSelection ) {
IStructuredSelection ss = (IStructuredSelection)selection;
if ( ss.size() == 1 ) {
Object object = ss.getFirstElement();
if ( object instanceof ISuspendResume ) {
setTargetElement( (ISuspendResume)object );
}
} }
} }
update(); IAction action = getAction();
if (action != null) {
action.setEnabled(fTargetElement != null && hasTargetAdapter());
}
}
public void debugContextChanged(DebugContextEvent event) {
contextActivated(event.getContext());
} }
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
*/ */
public void dispose() { public void dispose() {
fWindow.getSelectionService().removeSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, fSelectionListener ); DebugUITools.getDebugContextManager().getContextService(fWindow).removeDebugContextListener(fContextListener);
super.dispose(); super.dispose();
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
*/ */
public void init( IWorkbenchWindow window ) { public void init(IWorkbenchWindow window) {
super.init( window ); super.init(window);
window.getSelectionService().addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, fSelectionListener ); IDebugContextService service = DebugUITools.getDebugContextManager().getContextService(window);
service.addDebugContextListener(fContextListener);
ISelection activeContext = service.getActiveContext();
fContextListener.contextActivated(activeContext);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.internal.ui.actions.RetargetAction#performAction(java.lang.Object, org.eclipse.jface.viewers.ISelection, org.eclipse.ui.IWorkbenchPart) * @see org.eclipse.debug.internal.ui.actions.RetargetAction#canPerformAction(java.lang.Object, org.eclipse.jface.viewers.ISelection, org.eclipse.ui.IWorkbenchPart)
*/ */
protected void performAction( Object target, ISelection selection, IWorkbenchPart part ) throws CoreException { protected boolean canPerformAction(Object target, ISelection selection, IWorkbenchPart part) {
((IResumeAtLineTarget)target).resumeAtLine( part, selection, getTargetElement() ); return fTargetElement != null &&
((IResumeAtLineTarget)target).canResumeAtLine(part, selection, fTargetElement);
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.internal.ui.actions.RetargetAction#getAdapterClass() * @see org.eclipse.debug.internal.ui.actions.RetargetAction#getAdapterClass()
*/ */
protected Class<?> getAdapterClass() { protected Class getAdapterClass() {
return IResumeAtLineTarget.class; return IResumeAtLineTarget.class;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.debug.internal.ui.actions.RetargetAction#canPerformAction(java.lang.Object, org.eclipse.jface.viewers.ISelection, org.eclipse.ui.IWorkbenchPart) * @see org.eclipse.debug.internal.ui.actions.RetargetAction#performAction(java.lang.Object, org.eclipse.jface.viewers.ISelection, org.eclipse.ui.IWorkbenchPart)
*/ */
protected boolean canPerformAction( Object target, ISelection selection, IWorkbenchPart part ) { protected void performAction(Object target, ISelection selection, IWorkbenchPart part) throws CoreException {
return getTargetElement() != null && ((IResumeAtLineTarget)target).canResumeAtLine( part, selection, getTargetElement() ); ((IResumeAtLineTarget)target).resumeAtLine(part, selection, fTargetElement);
} }
protected ISuspendResume getTargetElement() { /* (non-Javadoc)
return fTargetElement; * @see org.eclipse.debug.internal.ui.actions.RetargetAction#getOperationUnavailableMessage()
} */
protected String getOperationUnavailableMessage() {
protected void setTargetElement( ISuspendResume targetElement ) { return ActionMessages.getString("RetargetResumeAtLineAction.0"); //$NON-NLS-1$
fTargetElement = targetElement; }
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
*/
public void selectionChanged(IAction action, ISelection selection) {
if (fTargetElement == null) {
action.setEnabled(false);
} else {
super.selectionChanged(action, selection);
}
} }
} }