diff --git a/debug/org.eclipse.cdt.debug.ui/ChangeLog b/debug/org.eclipse.cdt.debug.ui/ChangeLog index e9fa9fefc60..1234dcff4ad 100644 --- a/debug/org.eclipse.cdt.debug.ui/ChangeLog +++ b/debug/org.eclipse.cdt.debug.ui/ChangeLog @@ -1,3 +1,19 @@ +2005-01-18 Mikhail Khodjaiants + Fix for bug 82800: Make "Resume At Line" action retargettable. + * plugin.xml + * CDebugImages.java + * EvaluationContextManager.java: new + * ActionMessages.properties + * IResumeAtLineTarget.java: new + * ResumeAtLineActionDelegate.java + * ResumeAtLineAdapter.java: new + * RetargetAction.java: new + * RetargetResumeAtLineAction.java: new + * RetargettableActionAdapterFactory.java + * CDebugUIPlugin.java + * JumpToLineActionDelegate.java: removed + * RunToLineActionDelegate.java: removed + 2005-01-12 Mikhail Khodjaiants Bug 73168: Use memory view provided by Eclipse platform in CDT. Removed the old memory view. diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml index e738120b450..811bdcdc3ac 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.xml +++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml @@ -130,9 +130,9 @@ id="org.eclipse.ui.run"> + + + + + + - - - - - - - - + id="org.eclipse.cdt.debug.ui.actions.popup.RunToLine"> + + + + + + - - - - - - - - + id="org.eclipse.cdt.debug.ui.actions.popup.RunToLine"> + + + IResumeAtLineTarget adapter. */ -public class ResumeAtLineActionDelegate implements IWorkbenchWindowActionDelegate, IPartListener, IUpdate { +public class ResumeAtLineActionDelegate implements IEditorActionDelegate, IActionDelegate2 { + + private IEditorPart fActivePart = null; + + private IResumeAtLineTarget fPartTarget = null; - protected IWorkbenchWindow fWindow = null; - private IWorkbenchPart fActivePart = null; private IAction fAction = null; - private IDebugElement fTargetElement = null; - - private static final ISelection EMPTY_SELECTION = new EmptySelection(); - - static class EmptySelection implements ISelection { - public boolean isEmpty() { - return true; - } - } private ISelectionListener fSelectionListener = new DebugSelectionListener(); + protected ISuspendResume fTargetElement = null; + class DebugSelectionListener implements ISelectionListener { + /* (non-Javadoc) * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) */ public void selectionChanged( IWorkbenchPart part, ISelection selection ) { - setTargetElement( null ); + fTargetElement = null; if ( selection instanceof IStructuredSelection ) { IStructuredSelection ss = (IStructuredSelection)selection; if ( ss.size() == 1 ) { Object object = ss.getFirstElement(); - if ( object instanceof IDebugElement ) { - setTargetElement( (IDebugElement)object ); + if ( object instanceof ISuspendResume ) { + fTargetElement = (ISuspendResume)object; } } } @@ -84,98 +67,68 @@ public class ResumeAtLineActionDelegate implements IWorkbenchWindowActionDelegat } } - /** - * Returns the current selection in the active part, possibly - * and empty selection, but never null. - * - * @return the selection in the active part, possibly empty + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart) */ - private ISelection getTargetSelection() { - if ( fActivePart != null ) { - ISelectionProvider selectionProvider = fActivePart.getSite().getSelectionProvider(); - if ( selectionProvider != null ) { - return selectionProvider.getSelection(); + public void setActiveEditor( IAction action, IEditorPart targetEditor ) { + init( action ); + if ( fActivePart != null && !fActivePart.equals( targetEditor ) ) { + fActivePart.getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, fSelectionListener ); + } + fPartTarget = null; + fActivePart = targetEditor; + if ( targetEditor != null ) { + targetEditor.getSite().getWorkbenchWindow().getSelectionService().addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, fSelectionListener ); + fPartTarget = (IResumeAtLineTarget)targetEditor.getAdapter( IResumeAtLineTarget.class ); + if ( fPartTarget == null ) { + IAdapterManager adapterManager = Platform.getAdapterManager(); + // TODO: we could restrict loading to cases when the debugging context is on + if ( adapterManager.hasAdapter( targetEditor, IRunToLineTarget.class.getName() ) ) { + fPartTarget = (IResumeAtLineTarget)adapterManager.loadAdapter( targetEditor, IResumeAtLineTarget.class.getName() ); + } } } - return EMPTY_SELECTION; + update(); } /* (non-Javadoc) - * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() + * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction) + */ + public void init( IAction action ) { + this.fAction = action; + if ( action != null ) { + action.setText( ActionMessages.getString( "ResumeAtLineActionDelegate.0" ) ); //$NON-NLS-1$ + action.setImageDescriptor( CDebugImages.DESC_LCL_RESUME_AT_LINE ); + action.setDisabledImageDescriptor( CDebugImages.DESC_LCL_RESUME_AT_LINE_DISABLED ); + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate2#dispose() */ public void dispose() { - fWindow.getSelectionService().removeSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, fSelectionListener ); - fWindow.getPartService().removePartListener( this ); + fActivePart.getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, fSelectionListener ); fActivePart = null; + fPartTarget = null; } /* (non-Javadoc) - * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) + * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event) */ - public void init( IWorkbenchWindow window ) { - this.fWindow = window; - IPartService partService = window.getPartService(); - partService.addPartListener( this ); - fWindow.getSelectionService().addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, fSelectionListener ); - IWorkbenchPart part = partService.getActivePart(); - if ( part != null ) { - partActivated( part ); - } - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IPartListener#partActivated(org.eclipse.ui.IWorkbenchPart) - */ - public void partActivated( IWorkbenchPart part ) { - fActivePart = part; - update(); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IPartListener#partBroughtToTop(org.eclipse.ui.IWorkbenchPart) - */ - public void partBroughtToTop( IWorkbenchPart part ) { - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart) - */ - public void partClosed( IWorkbenchPart part ) { - clearPart(part); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IPartListener#partDeactivated(org.eclipse.ui.IWorkbenchPart) - */ - public void partDeactivated( IWorkbenchPart part ) { - clearPart(part); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart) - */ - public void partOpened( IWorkbenchPart part ) { - } - - /* (non-Javadoc) - * @see org.eclipse.ui.texteditor.IUpdate#update() - */ - public void update() { - if ( fAction == null ) { - return; - } - fAction.setEnabled( canPerformAction( getTargetSelection() ) ); + public void runWithEvent( IAction action, Event event ) { + run( action ); } /* (non-Javadoc) * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */ public void run( IAction action ) { - if ( fTargetElement != null ) { + if ( fPartTarget != null && fTargetElement != null ) { try { - performAction( getTargetSelection() ); - } catch( CoreException e ) { - DebugUIPlugin.errorDialog( fWindow.getShell(), ActionMessages.getString( "ResumeAtLineActionDelegate.Error_1" ), ActionMessages.getString( "ResumeAtLineActionDelegate.Operation_failed_1" ), e.getStatus() ); //$NON-NLS-1$ //$NON-NLS-2$ + fPartTarget.resumeAtLine( fActivePart, fActivePart.getSite().getSelectionProvider().getSelection(), fTargetElement ); + } + catch( CoreException e ) { + DebugUIPlugin.errorDialog( fActivePart.getSite().getWorkbenchWindow().getShell(), ActionMessages.getString( "ResumeAtLineActionDelegate.1" ), ActionMessages.getString( "ResumeAtLineActionDelegate.2" ), e.getStatus() ); //$NON-NLS-1$ //$NON-NLS-2$ } } } @@ -188,129 +141,21 @@ public class ResumeAtLineActionDelegate implements IWorkbenchWindowActionDelegat update(); } - /** - * Clears reference to active part and adapter when a relevant part - * is closed or deactivated. - * - * @param part workbench part that has been closed or deactivated - */ - protected void clearPart( IWorkbenchPart part ) { - if ( part.equals( fActivePart ) ) { - fActivePart = null; + protected void update() { + if ( fAction == null ) { + return; } - } - - protected IDebugElement getTargetElement() { - return this.fTargetElement; - } - - protected void setTargetElement( IDebugElement targetElement ) { - this.fTargetElement = targetElement; - } - - private boolean canPerformAction( ISelection selection ) { - if ( fTargetElement == null || - !fTargetElement.getModelIdentifier().equals( CDIDebugModel.getPluginIdentifier() ) ) - return false; - IDebugTarget debugTarget = fTargetElement.getDebugTarget(); - if ( fActivePart instanceof IEditorPart ) { - IJumpToLine jumpToLine = (IJumpToLine)debugTarget.getAdapter( IJumpToLine.class ); - if ( jumpToLine == null ) - return false; - IEditorPart editorPart = (IEditorPart)fActivePart; - IEditorInput input = editorPart.getEditorInput(); - if ( input == null ) { - return false; - } - if ( !(editorPart instanceof ITextEditor) ) { - return false; - } - ITextEditor textEditor = (ITextEditor)editorPart; - IDocument document = textEditor.getDocumentProvider().getDocument( input ); - if ( document == null ) { - return false; - } - String fileName; - try { - fileName = getFileName( input ); - } - catch( CoreException e ) { - return false; - } - ITextSelection textSelection = (ITextSelection)selection; - int lineNumber = textSelection.getStartLine() + 1; - return jumpToLine.canJumpToLine( fileName, lineNumber ); - } - if ( fActivePart instanceof DisassemblyView ) { - IJumpToAddress jumpToAddress = (IJumpToAddress)debugTarget.getAdapter( IJumpToAddress.class ); - if ( jumpToAddress == null ) - return false; - IEditorInput input = ((DisassemblyView)fActivePart).getInput(); - if ( !(input instanceof DisassemblyEditorInput) ) { - return false; - } - ITextSelection textSelection = (ITextSelection)selection; - int lineNumber = textSelection.getStartLine() + 1; - IAddress address = ((DisassemblyEditorInput)input).getAddress( lineNumber ); - return jumpToAddress.canJumpToAddress( address ); - } - return false; - } - - private void performAction( ISelection selection ) throws CoreException { - IDebugTarget debugTarget = fTargetElement.getDebugTarget(); - String errorMessage = null; - if ( fActivePart instanceof IEditorPart ) { - IEditorPart editorPart = (IEditorPart)fActivePart; - IEditorInput input = editorPart.getEditorInput(); - if ( input == null ) { - errorMessage = ActionMessages.getString( "ResumeAtLineActionDelegate.Empty_editor_1" ); //$NON-NLS-1$ - } - else { - ITextEditor textEditor = (ITextEditor)editorPart; - IDocument document = textEditor.getDocumentProvider().getDocument( input ); - if ( document == null ) { - errorMessage = ActionMessages.getString( "ResumeAtLineActionDelegate.Missing_document" ); //$NON-NLS-1$ - } - else { - String fileName = getFileName( input ); - ITextSelection textSelection = (ITextSelection)selection; - int lineNumber = textSelection.getStartLine() + 1; - IJumpToLine jumpToLine = (IJumpToLine)((IAdaptable)debugTarget).getAdapter( IJumpToLine.class ); - if ( jumpToLine != null ) - jumpToLine.jumpToLine( fileName, lineNumber ); - return; + boolean enabled = false; + if ( fPartTarget != null && fTargetElement != null ) { + IWorkbenchPartSite site = fActivePart.getSite(); + if ( site != null ) { + ISelectionProvider selectionProvider = site.getSelectionProvider(); + if ( selectionProvider != null ) { + ISelection selection = selectionProvider.getSelection(); + enabled = fTargetElement.isSuspended() && fPartTarget.canResumeAtLine( fActivePart, selection, fTargetElement ); } } } - else if ( fActivePart instanceof DisassemblyView ) { - IEditorInput input = ((DisassemblyView)fActivePart).getInput(); - if ( !(input instanceof DisassemblyEditorInput) ) { - errorMessage = ActionMessages.getString( "ResumeAtLineActionDelegate.Empty_editor_1" ); //$NON-NLS-1$ - } - else { - ITextSelection textSelection = (ITextSelection)selection; - int lineNumber = textSelection.getStartLine() + 1; - IAddress address = ((DisassemblyEditorInput)input).getAddress( lineNumber ); - IJumpToAddress jumpToAddress = (IJumpToAddress)((IAdaptable)debugTarget).getAdapter( IJumpToAddress.class ); - if ( jumpToAddress != null ) - jumpToAddress.jumpToAddress( address ); - return; - } - } - else { - errorMessage = ActionMessages.getString( "ResumeAtLineActionDelegate.Operation_is_not_supported_1" ); //$NON-NLS-1$ - } - throw new CoreException( new Status( IStatus.ERROR, CDebugUIPlugin.getUniqueIdentifier(), ICDebugUIConstants.INTERNAL_ERROR, errorMessage, null ) ); - } - - private String getFileName( IEditorInput input ) throws CoreException { - if ( input instanceof IFileEditorInput ) { - return ((IFileEditorInput)input).getFile().getName(); - } - if ( input instanceof IStorageEditorInput ) { - return ((IStorageEditorInput)input).getStorage().getName(); - } - return null; + fAction.setEnabled( enabled ); } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ResumeAtLineAdapter.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ResumeAtLineAdapter.java new file mode 100644 index 00000000000..5cdd6643aff --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ResumeAtLineAdapter.java @@ -0,0 +1,153 @@ +/********************************************************************** + * Copyright (c) 2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ +package org.eclipse.cdt.debug.internal.ui.actions; + +import org.eclipse.cdt.core.IAddress; +import org.eclipse.cdt.debug.core.model.IJumpToAddress; +import org.eclipse.cdt.debug.core.model.IJumpToLine; +import org.eclipse.cdt.debug.internal.ui.views.disassembly.DisassemblyEditorInput; +import org.eclipse.cdt.debug.internal.ui.views.disassembly.DisassemblyView; +import org.eclipse.cdt.debug.ui.CDebugUIPlugin; +import org.eclipse.cdt.debug.ui.ICDebugUIConstants; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.debug.core.model.ISuspendResume; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.IStorageEditorInput; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.texteditor.ITextEditor; + +/** + * Resume at line target adapter for the CDI debugger + */ +public class ResumeAtLineAdapter implements IResumeAtLineTarget { + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.internal.ui.actions.IResumeAtLineTarget#resumeAtLine(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection, org.eclipse.debug.core.model.ISuspendResume) + */ + public void resumeAtLine( IWorkbenchPart part, ISelection selection, ISuspendResume target ) throws CoreException { + String errorMessage = null; + if ( part instanceof ITextEditor ) { + ITextEditor textEditor = (ITextEditor)part; + IEditorInput input = textEditor.getEditorInput(); + if ( input == null ) { + errorMessage = ActionMessages.getString( "ResumeAtLineAdapter.0" ); //$NON-NLS-1$ + } + else { + IDocument document = textEditor.getDocumentProvider().getDocument( input ); + if ( document == null ) { + errorMessage = ActionMessages.getString( "ResumeAtLineAdapter.1" ); //$NON-NLS-1$ + } + else { + String fileName = getFileName( input ); + ITextSelection textSelection = (ITextSelection)selection; + int lineNumber = textSelection.getStartLine() + 1; + if ( target instanceof IAdaptable ) { + IJumpToLine jumpToLine = (IJumpToLine)((IAdaptable)target).getAdapter( IJumpToLine.class ); + if ( jumpToLine != null && jumpToLine.canJumpToLine( fileName, lineNumber ) ) { + jumpToLine.jumpToLine( fileName, lineNumber ); + } + } + return; + } + } + } + else if ( part instanceof DisassemblyView ) { + IEditorInput input = ((DisassemblyView)part).getInput(); + if ( !(input instanceof DisassemblyEditorInput) ) { + errorMessage = ActionMessages.getString( "ResumeAtLineAdapter.2" ); //$NON-NLS-1$ + } + else { + ITextSelection textSelection = (ITextSelection)selection; + int lineNumber = textSelection.getStartLine() + 1; + IAddress address = ((DisassemblyEditorInput)input).getAddress( lineNumber ); + if ( target instanceof IAdaptable ) { + IJumpToAddress jumpToAddress = (IJumpToAddress)((IAdaptable)target).getAdapter( IJumpToAddress.class ); + if ( jumpToAddress != null && jumpToAddress.canJumpToAddress( address ) ) { + jumpToAddress.jumpToAddress( address ); + } + } + return; + } + } + else { + errorMessage = ActionMessages.getString( "ResumeAtLineAdapter.3" ); //$NON-NLS-1$ + } + throw new CoreException( new Status( IStatus.ERROR, CDebugUIPlugin.getUniqueIdentifier(), ICDebugUIConstants.INTERNAL_ERROR, errorMessage, null ) ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.internal.ui.actions.IResumeAtLineTarget#canResumeAtLine(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection, org.eclipse.debug.core.model.ISuspendResume) + */ + public boolean canResumeAtLine( IWorkbenchPart part, ISelection selection, ISuspendResume target ) { + if ( target instanceof IAdaptable ) { + if ( part instanceof IEditorPart ) { + IJumpToLine jumpToLine = (IJumpToLine)((IAdaptable)target).getAdapter( IJumpToLine.class ); + if ( jumpToLine == null ) + return false; + IEditorPart editorPart = (IEditorPart)part; + IEditorInput input = editorPart.getEditorInput(); + if ( input == null ) { + return false; + } + if ( !(editorPart instanceof ITextEditor) ) { + return false; + } + ITextEditor textEditor = (ITextEditor)editorPart; + IDocument document = textEditor.getDocumentProvider().getDocument( input ); + if ( document == null ) { + return false; + } + String fileName; + try { + fileName = getFileName( input ); + } + catch( CoreException e ) { + return false; + } + ITextSelection textSelection = (ITextSelection)selection; + int lineNumber = textSelection.getStartLine() + 1; + return jumpToLine.canJumpToLine( fileName, lineNumber ); + } + if ( part instanceof DisassemblyView ) { + IJumpToAddress jumpToAddress = (IJumpToAddress)((IAdaptable)target).getAdapter( IJumpToAddress.class ); + if ( jumpToAddress == null ) + return false; + IEditorInput input = ((DisassemblyView)part).getInput(); + if ( !(input instanceof DisassemblyEditorInput) ) { + return false; + } + ITextSelection textSelection = (ITextSelection)selection; + int lineNumber = textSelection.getStartLine() + 1; + IAddress address = ((DisassemblyEditorInput)input).getAddress( lineNumber ); + return jumpToAddress.canJumpToAddress( address ); + } + } + return false; + } + + private String getFileName( IEditorInput input ) throws CoreException { + if ( input instanceof IFileEditorInput ) { + return ((IFileEditorInput)input).getFile().getName(); + } + if ( input instanceof IStorageEditorInput ) { + return ((IStorageEditorInput)input).getStorage().getName(); + } + return null; + } +} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RetargetAction.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RetargetAction.java new file mode 100644 index 00000000000..24d37355f7e --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RetargetAction.java @@ -0,0 +1,215 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.debug.internal.ui.actions; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IAdapterManager; +import org.eclipse.core.runtime.Platform; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IPartListener; +import org.eclipse.ui.IPartService; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; +import org.eclipse.ui.texteditor.IUpdate; + +/** + * Global retargettable debug action. + * + * @since 3.0 + */ +public abstract class RetargetAction implements IWorkbenchWindowActionDelegate, IPartListener, IUpdate { + + protected IWorkbenchWindow fWindow = null; + private IWorkbenchPart fActivePart = null; + private Object fTargetAdapter = null; + private IAction fAction = null; + private static final ISelection EMPTY_SELECTION = new EmptySelection(); + + static class EmptySelection implements ISelection { + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ISelection#isEmpty() + */ + public boolean isEmpty() { + return true; + } + + } + + /** + * Returns the current selection in the active part, possibly + * and empty selection, but never null. + * + * @return the selection in the active part, possibly empty + */ + private ISelection getTargetSelection() { + if (fActivePart != null) { + ISelectionProvider selectionProvider = fActivePart.getSite().getSelectionProvider(); + if (selectionProvider != null) { + return selectionProvider.getSelection(); + } + } + return EMPTY_SELECTION; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() + */ + public void dispose() { + fWindow.getPartService().removePartListener(this); + fActivePart = null; + fTargetAdapter = null; + + } + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) + */ + public void init(IWorkbenchWindow window) { + this.fWindow = window; + IPartService partService = window.getPartService(); + partService.addPartListener(this); + IWorkbenchPart part = partService.getActivePart(); + if (part != null) { + partActivated(part); + } + } + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) + */ + public void run(IAction action) { + if (fTargetAdapter != null) { + try { + performAction(fTargetAdapter, getTargetSelection(), fActivePart); + } catch (CoreException e) { + DebugUIPlugin.errorDialog(fWindow.getShell(), ActionMessages.getString("RetargetAction.2"), ActionMessages.getString("RetargetAction.3"), e.getStatus()); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + } + + /** + * Performs the specific breakpoint toggling. + * + * @param selection selection in the active part + * @param part active part + * @throws CoreException if an exception occurrs + */ + protected abstract void performAction(Object target, ISelection selection, IWorkbenchPart part) throws CoreException; + + /* (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) { + this.fAction = action; + // if the active part did not provide an adapter, see if the selectoin does + if (fTargetAdapter == null && selection instanceof IStructuredSelection) { + IStructuredSelection ss = (IStructuredSelection) selection; + if (!ss.isEmpty()) { + Object object = ss.getFirstElement(); + if (object instanceof IAdaptable) { + fTargetAdapter = getAdapter((IAdaptable) object); + } + } + } + update(); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener#partActivated(org.eclipse.ui.IWorkbenchPart) + */ + public void partActivated(IWorkbenchPart part) { + fActivePart = part; + fTargetAdapter = getAdapter(part); + update(); + } + + protected Object getAdapter(IAdaptable adaptable) { + Object adapter = adaptable.getAdapter(getAdapterClass()); + if (adapter == null) { + IAdapterManager adapterManager = Platform.getAdapterManager(); + if (adapterManager.hasAdapter(adaptable, getAdapterClass().getName())) { //$NON-NLS-1$ + fTargetAdapter = adapterManager.loadAdapter(adaptable, getAdapterClass().getName()); //$NON-NLS-1$ + } + } + return adapter; + } + + /** + * Returns the type of adapter (target) this action works on. + * + * @return the type of adapter this action works on + */ + protected abstract Class getAdapterClass(); + + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener#partBroughtToTop(org.eclipse.ui.IWorkbenchPart) + */ + public void partBroughtToTop(IWorkbenchPart part) { + } + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart) + */ + public void partClosed(IWorkbenchPart part) { + clearPart(part); + } + + /** + * Clears reference to active part and adapter when a relevant part + * is closed or deactivated. + * + * @param part workbench part that has been closed or deactivated + */ + protected void clearPart(IWorkbenchPart part) { + if (part.equals(fActivePart)) { + fActivePart = null; + fTargetAdapter = null; + } + } + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener#partDeactivated(org.eclipse.ui.IWorkbenchPart) + */ + public void partDeactivated(IWorkbenchPart part) { + clearPart(part); + } + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart) + */ + public void partOpened(IWorkbenchPart part) { + } + /* (non-Javadoc) + * @see org.eclipse.ui.texteditor.IUpdate#update() + */ + public void update() { + if (fAction == null) { + return; + } + if (fTargetAdapter != null) { + fAction.setEnabled(canPerformAction(fTargetAdapter, getTargetSelection(), fActivePart)); + } else { + fAction.setEnabled(false); + } + } + + /** + * Returns whether the specific operation is supported. + * + * @param target the target adapter + * @param selection the selection to verify the operation on + * @param part the part the operation has been requested on + * @return whether the operation can be performed + */ + protected abstract boolean canPerformAction(Object target, ISelection selection, IWorkbenchPart part); +} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RetargetResumeAtLineAction.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RetargetResumeAtLineAction.java new file mode 100644 index 00000000000..785dcb1c3d5 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RetargetResumeAtLineAction.java @@ -0,0 +1,96 @@ +/********************************************************************** + * Copyright (c) 2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ +package org.eclipse.cdt.debug.internal.ui.actions; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.model.ISuspendResume; +import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; + +/** + * Global retargettable resume at line action. + */ +public class RetargetResumeAtLineAction extends RetargetAction { + + private ISelectionListener fSelectionListener = new DebugSelectionListener(); + + private ISuspendResume fTargetElement = null; + + class DebugSelectionListener implements ISelectionListener { + + /* (non-Javadoc) + * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) + */ + public void selectionChanged( IWorkbenchPart part, ISelection selection ) { + setTargetElement( null ); + if ( selection instanceof IStructuredSelection ) { + IStructuredSelection ss = (IStructuredSelection)selection; + if ( ss.size() == 1 ) { + Object object = ss.getFirstElement(); + if ( object instanceof ISuspendResume ) { + setTargetElement( (ISuspendResume)object ); + } + } + } + update(); + } + } + + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() + */ + public void dispose() { + fWindow.getSelectionService().removeSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, fSelectionListener ); + super.dispose(); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) + */ + public void init( IWorkbenchWindow window ) { + super.init( window ); + window.getSelectionService().addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, fSelectionListener ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.internal.ui.actions.RetargetAction#performAction(java.lang.Object, org.eclipse.jface.viewers.ISelection, org.eclipse.ui.IWorkbenchPart) + */ + protected void performAction( Object target, ISelection selection, IWorkbenchPart part ) throws CoreException { + ((IResumeAtLineTarget)target).resumeAtLine( part, selection, getTargetElement() ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.internal.ui.actions.RetargetAction#getAdapterClass() + */ + protected Class getAdapterClass() { + return IResumeAtLineTarget.class; + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.internal.ui.actions.RetargetAction#canPerformAction(java.lang.Object, org.eclipse.jface.viewers.ISelection, org.eclipse.ui.IWorkbenchPart) + */ + protected boolean canPerformAction( Object target, ISelection selection, IWorkbenchPart part ) { + return getTargetElement() != null && ((IResumeAtLineTarget)target).canResumeAtLine( part, selection, getTargetElement() ); + } + + protected ISuspendResume getTargetElement() { + return fTargetElement; + } + + protected void setTargetElement( ISuspendResume targetElement ) { + fTargetElement = targetElement; + } +} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RetargettableActionAdapterFactory.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RetargettableActionAdapterFactory.java index d331d6471fb..d0b4454bb11 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RetargettableActionAdapterFactory.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RetargettableActionAdapterFactory.java @@ -31,6 +31,9 @@ public class RetargettableActionAdapterFactory implements IAdapterFactory { if ( adapterType == IRunToLineTarget.class ) { return new RunToLineAdapter(); } + if ( adapterType == IResumeAtLineTarget.class ) { + return new ResumeAtLineAdapter(); + } return null; } @@ -38,6 +41,6 @@ public class RetargettableActionAdapterFactory implements IAdapterFactory { * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() */ public Class[] getAdapterList() { - return new Class[]{ IRunToLineTarget.class, IToggleBreakpointsTarget.class }; + return new Class[]{ IRunToLineTarget.class, IToggleBreakpointsTarget.class, IResumeAtLineTarget.class }; } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineActionDelegate.java deleted file mode 100644 index 7b55fe63ff9..00000000000 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineActionDelegate.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.ui.actions; - -import org.eclipse.cdt.debug.core.model.IRunToAddress; -import org.eclipse.cdt.debug.core.model.IRunToLine; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.debug.core.model.IDebugElement; -import org.eclipse.debug.core.model.IDebugTarget; -import org.eclipse.debug.internal.ui.DebugUIPlugin; -import org.eclipse.debug.ui.DebugUITools; -import org.eclipse.debug.ui.IDebugUIConstants; -import org.eclipse.debug.ui.actions.IRunToLineTarget; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.texteditor.ITextEditor; - -/** - * Run to line action of C editor popup menu. - */ -public class RunToLineActionDelegate extends AbstractEditorActionDelegate { - - IRunToLineTarget fRunToLineTarget; - - /** - * Constructor for RunToLineActionDelegate. - */ - public RunToLineActionDelegate() { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.IActionDelegate#run(IAction) - */ - public void run( IAction action ) { - if ( getTargetPart() instanceof ITextEditor ) { - ITextSelection selection = (ITextSelection)((ITextEditor)getTargetPart()).getSelectionProvider().getSelection(); - if ( getRunToLineTarget() != null ) { - try { - getRunToLineTarget().runToLine( getTargetPart(), selection, getDebugTarget() ); - } - catch( CoreException e ) { - DebugUIPlugin.errorDialog( getTargetPart().getSite().getShell(), ActionMessages.getString( "RunToLineActionDelegate.Error_1" ), ActionMessages.getString( "RunToLineActionDelegate.Operation_failed_1" ), e.getStatus() ); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.debug.internal.ui.actions.AbstractEditorActionDelegate#initializeDebugTarget() - */ - protected void initializeDebugTarget() { - setDebugTarget( null ); - IAdaptable context = DebugUITools.getDebugContext(); - if ( context != null && context instanceof IDebugElement ) { - IDebugTarget target = ((IDebugElement)context).getDebugTarget(); - if ( target != null && (target instanceof IRunToLine || target instanceof IRunToAddress) ) { - setDebugTarget( target ); - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.ISelectionListener#selectionChanged(IWorkbenchPart, - * ISelection) - */ - public void selectionChanged( IWorkbenchPart part, ISelection selection ) { - IDebugTarget target = null; - if ( part != null && part.getSite().getId().equals( IDebugUIConstants.ID_DEBUG_VIEW ) ) { - if ( selection instanceof IStructuredSelection ) { - Object element = ((IStructuredSelection)selection).getFirstElement(); - if ( element != null && element instanceof IDebugElement ) { - IDebugTarget target1 = ((IDebugElement)element).getDebugTarget(); - if ( target1 != null && (target1 instanceof IRunToLine || target1 instanceof IRunToAddress) ) { - target = target1; - } - } - } - setDebugTarget( target ); - update(); - } - } - - private IRunToLineTarget getRunToLineTarget() { - if ( fRunToLineTarget == null ) { - fRunToLineTarget = new RunToLineAdapter(); - } - return fRunToLineTarget; - } -} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/CDebugUIPlugin.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/CDebugUIPlugin.java index f7a02518f21..907993e704a 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/CDebugUIPlugin.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/CDebugUIPlugin.java @@ -17,6 +17,7 @@ import org.eclipse.cdt.debug.internal.ui.CBreakpointUpdater; import org.eclipse.cdt.debug.internal.ui.CDTDebugModelPresentation; import org.eclipse.cdt.debug.internal.ui.CDebugImageDescriptorRegistry; import org.eclipse.cdt.debug.internal.ui.ColorManager; +import org.eclipse.cdt.debug.internal.ui.EvaluationContextManager; import org.eclipse.cdt.debug.ui.sourcelookup.DefaultSourceLocator; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; @@ -245,6 +246,7 @@ public class CDebugUIPlugin extends AbstractUIPlugin { */ public void start( BundleContext context ) throws Exception { super.start( context ); + EvaluationContextManager.startup(); CDebugCorePlugin.getDefault().addCBreakpointListener( CBreakpointUpdater.getInstance() ); }