diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml index bed9b43c6db..245224b5e92 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.xml +++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml @@ -420,9 +420,9 @@ + id="org.eclipse.debug.ui.actions.RulerToggleBreakpointAction"> + id="org.eclipse.debug.ui.actions.RulerToggleBreakpointAction"> + id="org.eclipse.cdt.debug.ui.actions.function.ToggleMethodBreakpointAction"> + id="org.eclipse.cdt.debug.ui.actions.method.ToggleMethodBreakpointAction"> + id="org.eclipse.cdt.debug.ui.actions.ToggleWatchpointAction"/> + id="org.eclipse.cdt.debug.ui.CEditor.RulerTobbleBreakpointAction"> + id="org.eclipse.cdt.debug.ui.CEditor.RulerTobbleBreakpointAction"> @@ -1410,9 +1410,6 @@ - - @@ -1422,9 +1419,6 @@ - - @@ -1434,22 +1428,12 @@ - - - - - - @@ -1904,4 +1888,29 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties index 9f490b25f28..750de55963f 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties @@ -125,3 +125,5 @@ AddRegisterGroupActionDelegate.1=Error(s) occurred adding register group. EditRegisterGroupActionDelegate.0=Unable to edit register group. AddEventBreakpointActionDelegate.0=Error adding Event Breakpoint AddEventBreakpointActionDelegate.2=Action is not supported by installed debuggers +ToggleCBreakpointsTargetFactory.CBreakpointDescription=Standard C/C++ breakpoint type. +ToggleCBreakpointsTargetFactory.CBreakpointName=C/C++ Breakpoints diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ManageBreakpointRulerActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ManageBreakpointRulerActionDelegate.java deleted file mode 100644 index ed8c400afa7..00000000000 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ManageBreakpointRulerActionDelegate.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2006 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 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.ui.actions; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.text.source.IVerticalRulerInfo; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.texteditor.AbstractRulerActionDelegate; -import org.eclipse.ui.texteditor.ITextEditor; - -public class ManageBreakpointRulerActionDelegate extends AbstractRulerActionDelegate { - - private ToggleBreakpointRulerAction fTargetAction; - private IEditorPart fActiveEditor; - - /* (non-Javadoc) - * @see org.eclipse.ui.texteditor.AbstractRulerActionDelegate#createAction(ITextEditor, IVerticalRulerInfo) - */ - public IAction createAction( ITextEditor editor, IVerticalRulerInfo rulerInfo ) { - fTargetAction = new ToggleBreakpointRulerAction( editor, rulerInfo ); - return fTargetAction; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart) - */ - public void setActiveEditor( IAction callerAction, IEditorPart targetEditor ) { - if ( fActiveEditor != null ) { - if ( fTargetAction != null ) { - fTargetAction.dispose(); - fTargetAction = null; - } - } - fActiveEditor = targetEditor; - super.setActiveEditor( callerAction, targetEditor ); - } -} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ManageFunctionBreakpointActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ManageFunctionBreakpointActionDelegate.java deleted file mode 100644 index fc6c868edb9..00000000000 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ManageFunctionBreakpointActionDelegate.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2008 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 - * Anton Leherbauer (Wind River Systems) - bug 183291 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.ui.actions; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.actions.ActionDelegate; -import org.eclipse.ui.part.IContributedContentsView; - -/** - * The delegate of the "Toggle Function Breakpoint" action. - */ -public class ManageFunctionBreakpointActionDelegate extends ActionDelegate implements IObjectActionDelegate { - - private ToggleBreakpointAdapter fBreakpointAdapter; - - private IWorkbenchPart fTargetPart; - - private ISelection fSelection; - - public ManageFunctionBreakpointActionDelegate() { - fBreakpointAdapter = new ToggleBreakpointAdapter(); - } - - /*(non-Javadoc) - * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart) - */ - public void setActivePart( IAction action, IWorkbenchPart targetPart ) { - fTargetPart = targetPart; - } - - /*(non-Javadoc) - * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) - */ - public void run( IAction action ) { - try { - getBreakpointAdapter().toggleMethodBreakpoints( getTargetPart(), getSelection() ); - } - catch( CoreException e ) { - ErrorDialog.openError( getTargetPart().getSite().getShell(), - ActionMessages.getString( "ManageFunctionBreakpointActionDelegate.Error_1" ), //$NON-NLS-1$ - ActionMessages.getString( "ManageFunctionBreakpointActionDelegate.Operation_failed_1" ), //$NON-NLS-1$ - e.getStatus() ); - } - } - - /*(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 ) { - setSelection( selection ); - action.setEnabled( getBreakpointAdapter().canToggleMethodBreakpoints( getTargetPart(), getSelection() ) ); - } - - private IWorkbenchPart getTargetPart() { - return fTargetPart; - } - - private ISelection getSelection() { - return fSelection; - } - - private IToggleBreakpointsTarget getBreakpointAdapter() { - IToggleBreakpointsTarget targetAdapter = null; - if (fTargetPart != null) { - IResource resource = (IResource) fTargetPart.getAdapter(IResource.class); - if (resource == null && fTargetPart instanceof IEditorPart) { - resource = (IResource) ((IEditorPart)fTargetPart).getEditorInput().getAdapter(IResource.class); - } - if (resource == null) { - // in case of outline view - IContributedContentsView contentsView = (IContributedContentsView) fTargetPart.getAdapter(IContributedContentsView.class); - if (contentsView != null) { - IWorkbenchPart contributingPart = contentsView.getContributingPart(); - if (contributingPart != null) { - resource = (IResource) contributingPart.getAdapter(IResource.class); - if (resource == null && contributingPart instanceof IEditorPart) { - resource = (IResource) ((IEditorPart)contributingPart).getEditorInput().getAdapter(IResource.class); - } - } - } - } - if (resource != null) { - targetAdapter = (IToggleBreakpointsTarget)resource.getAdapter(IToggleBreakpointsTarget.class); - } - if (targetAdapter == null) { - targetAdapter = (IToggleBreakpointsTarget)fTargetPart.getAdapter(IToggleBreakpointsTarget.class); - } - } - if (targetAdapter == null) { - targetAdapter = fBreakpointAdapter; - } - return targetAdapter; - } - - private void setSelection( ISelection selection ) { - fSelection = selection; - } -} 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 e120bcae8a8..ba6763faa85 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 @@ -12,7 +12,6 @@ package org.eclipse.cdt.debug.internal.ui.actions; import org.eclipse.core.runtime.IAdapterFactory; import org.eclipse.debug.ui.actions.IRunToLineTarget; -import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget; /** * Creates adapters for retargettable actions in debug platform. @@ -25,9 +24,6 @@ public class RetargettableActionAdapterFactory implements IAdapterFactory { * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class) */ public Object getAdapter( Object adaptableObject, Class adapterType ) { - if ( adapterType == IToggleBreakpointsTarget.class ) { - return new ToggleBreakpointAdapter(); - } if ( adapterType == IRunToLineTarget.class ) { return new RunToLineAdapter(); } @@ -44,6 +40,6 @@ public class RetargettableActionAdapterFactory implements IAdapterFactory { * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() */ public Class[] getAdapterList() { - return new Class[]{ IRunToLineTarget.class, IToggleBreakpointsTarget.class, IResumeAtLineTarget.class, IMoveToLineTarget.class }; + return new Class[]{ IRunToLineTarget.class, IResumeAtLineTarget.class, IMoveToLineTarget.class }; } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointRulerAction.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointRulerAction.java deleted file mode 100644 index 7f6f584c69a..00000000000 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointRulerAction.java +++ /dev/null @@ -1,168 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 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 - * Anton Leherbauer (Wind River Systems) - bug 183291 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.ui.actions; - -import org.eclipse.cdt.debug.internal.ui.ICDebugHelpContextIds; -import org.eclipse.cdt.debug.internal.ui.IInternalCDebugUIConstants; -import org.eclipse.cdt.debug.internal.ui.views.disassembly.DisassemblyView; -import org.eclipse.core.resources.IResource; -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.core.DebugPlugin; -import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.TextSelection; -import org.eclipse.jface.text.source.IVerticalRulerInfo; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.texteditor.IDocumentProvider; -import org.eclipse.ui.texteditor.ITextEditor; - -public class ToggleBreakpointRulerAction extends Action { - - static class EmptySelection implements ISelection { - - public boolean isEmpty() { - return true; - } - } - - private IVerticalRulerInfo fRuler; - private IWorkbenchPart fTargetPart; - private IToggleBreakpointsTarget fTargetAdapter; - private static final ISelection EMPTY_SELECTION = new EmptySelection(); - - /** - * Constructor for ToggleBreakpointRulerAction. - * - * @param ruler - * @param editor - */ - public ToggleBreakpointRulerAction( IWorkbenchPart part, IVerticalRulerInfo ruler ) { - super( ActionMessages.getString( "ToggleBreakpointRulerAction.Toggle_Breakpoint_1" ) ); //$NON-NLS-1$ - fRuler = ruler; - setTargetPart( part ); - part.getSite().getWorkbenchWindow().getWorkbench().getHelpSystem().setHelp( this, ICDebugHelpContextIds.TOGGLE_BREAKPOINT_ACTION ); - setId( IInternalCDebugUIConstants.ACTION_TOGGLE_BREAKPOINT ); - } - - /** - * Disposes this action - */ - public void dispose() { - setTargetPart( null ); - fRuler = null; - } - - /** - * @see Action#run() - */ - public void run() { - try { - fTargetAdapter.toggleLineBreakpoints( getTargetPart(), getTargetSelection() ); - } - catch( CoreException e ) { - ErrorDialog.openError( getTargetPart().getSite().getShell(), - ActionMessages.getString( "ToggleBreakpointRulerAction.Error_1" ), //$NON-NLS-1$ - ActionMessages.getString( "ToggleBreakpointRulerAction.Operation_failed_1" ), //$NON-NLS-1$ - e.getStatus() ); - } - } - - /** - * Returns this action's vertical ruler info. - * - * @return this action's vertical ruler - */ - protected IVerticalRulerInfo getVerticalRulerInfo() { - return fRuler; - } - - private IWorkbenchPart getTargetPart() { - return this.fTargetPart; - } - - private void setTargetPart( IWorkbenchPart targetPart ) { - this.fTargetPart = targetPart; - if (fTargetPart != null) { - IResource resource = (IResource) fTargetPart.getAdapter(IResource.class); - if (resource == null && fTargetPart instanceof IEditorPart) { - resource = (IResource) ((IEditorPart)fTargetPart).getEditorInput().getAdapter(IResource.class); - } - if (resource != null) { - fTargetAdapter = getAdapter(resource); - } - if (fTargetAdapter == null) { - fTargetAdapter = getAdapter(fTargetPart); - } - } - if (fTargetAdapter == null) { - fTargetAdapter = new ToggleBreakpointAdapter(); - } - } - - private IToggleBreakpointsTarget getAdapter(IAdaptable adaptable) { - IToggleBreakpointsTarget adapter= (IToggleBreakpointsTarget)adaptable.getAdapter(IToggleBreakpointsTarget.class); - if (adapter == null) { - IAdapterManager adapterManager= Platform.getAdapterManager(); - if (adapterManager.hasAdapter(adaptable, IToggleBreakpointsTarget.class.getName())) { - adapter= (IToggleBreakpointsTarget)adapterManager.loadAdapter(adaptable, IToggleBreakpointsTarget.class.getName()); - } - } - return adapter; - } - - /** - * 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() { - IDocument doc = getDocument(); - if ( doc != null ) { - int line = getVerticalRulerInfo().getLineOfLastMouseButtonActivity(); - try { - IRegion region = doc.getLineInformation( line ); - return new TextSelection( doc, region.getOffset(), region.getLength() ); - } - catch( BadLocationException e ) { - DebugPlugin.log( e ); - } - } - return EMPTY_SELECTION; - } - - private IDocument getDocument() { - IWorkbenchPart targetPart = getTargetPart(); - if ( targetPart instanceof ITextEditor ) { - ITextEditor textEditor = (ITextEditor)targetPart; - IDocumentProvider provider = textEditor.getDocumentProvider(); - if ( provider != null ) - return provider.getDocument( textEditor.getEditorInput() ); - } - else if ( targetPart instanceof DisassemblyView ) { - DisassemblyView dv = (DisassemblyView)targetPart; - IDocumentProvider provider = dv.getDocumentProvider(); - if ( provider != null ) - return provider.getDocument( dv.getInput() ); - } - return null; - } -} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleCBreakpointsTargetFactory.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleCBreakpointsTargetFactory.java new file mode 100644 index 00000000000..ab6c490f0bd --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleCBreakpointsTargetFactory.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2007 Wind River 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.debug.internal.ui.actions; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.cdt.debug.core.CDIDebugModel; +import org.eclipse.cdt.debug.ui.CDebugUIPlugin; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.debug.core.model.IDebugModelProvider; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget; +import org.eclipse.debug.ui.actions.IToggleBreakpointsTargetFactory; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.ui.IWorkbenchPart; + +/** + * + */ +public class ToggleCBreakpointsTargetFactory implements IToggleBreakpointsTargetFactory { + + public static String TOGGLE_C_BREAKPOINT_TARGET_ID = CDebugUIPlugin.getUniqueIdentifier() + ".toggleCBreakpointTarget"; //$NON-NLS-1$ + + private static Set TOGGLE_TARGET_IDS = new HashSet(1); + static { + TOGGLE_TARGET_IDS.add(TOGGLE_C_BREAKPOINT_TARGET_ID); + } + + private ToggleBreakpointAdapter fCToggleBreakpointTarget = new ToggleBreakpointAdapter(); + + public IToggleBreakpointsTarget createToggleTarget(String targetID) { + if (TOGGLE_C_BREAKPOINT_TARGET_ID.equals(targetID)) { + return fCToggleBreakpointTarget; + } + return null; + } + + public String getDefaultToggleTarget(IWorkbenchPart part, ISelection selection) { + // Return the debug context as a default if the currently selected context + // is a CDT element. Otherwise return null. + Object element = getDebugContext(part).getFirstElement(); + if (element instanceof IAdaptable) { + IDebugModelProvider modelProvider = + (IDebugModelProvider)((IAdaptable)element).getAdapter(IDebugModelProvider.class); + if (modelProvider != null) { + String[] models = modelProvider.getModelIdentifiers(); + if (Arrays.asList(models).contains(CDIDebugModel.getPluginIdentifier())) { + return TOGGLE_C_BREAKPOINT_TARGET_ID; + } + } + } + return null; + } + + public String getToggleTargetDescription(String targetID) { + return ActionMessages.getString("ToggleCBreakpointsTargetFactory.CBreakpointDescription"); //$NON-NLS-1$ + } + + public String getToggleTargetName(String targetID) { + return ActionMessages.getString("ToggleCBreakpointsTargetFactory.CBreakpointName"); //$NON-NLS-1$ + } + + @SuppressWarnings("unchecked") + public Set getToggleTargets(IWorkbenchPart part, ISelection selection) { + return TOGGLE_TARGET_IDS; + } + + private IStructuredSelection getDebugContext(IWorkbenchPart part) { + ISelection selection = DebugUITools.getDebugContextManager(). + getContextService(part.getSite().getWorkbenchWindow()).getActiveContext(); + if (selection instanceof IStructuredSelection) { + return (IStructuredSelection)selection; + } + return StructuredSelection.EMPTY; + } + +} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleWatchpointActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleWatchpointActionDelegate.java deleted file mode 100644 index 4b7ad2b04d9..00000000000 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleWatchpointActionDelegate.java +++ /dev/null @@ -1,130 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 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 - * Anton Leherbauer (Wind River Systems) - bug 183291 - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.ui.actions; - -import org.eclipse.core.resources.IResource; -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.ui.actions.IToggleBreakpointsTarget; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.actions.ActionDelegate; -import org.eclipse.ui.part.IContributedContentsView; - -/** - * The delegate of the "Toggle Watchpoint" action. - */ -public class ToggleWatchpointActionDelegate extends ActionDelegate implements IObjectActionDelegate { - - private ToggleBreakpointAdapter fBreakpointAdapter; - - private IWorkbenchPart fTargetPart; - - private ISelection fSelection; - - /** - * Constructor for ToggleWatchpointActionDelegate. - */ - public ToggleWatchpointActionDelegate() { - fBreakpointAdapter = new ToggleBreakpointAdapter(); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart) - */ - public void setActivePart( IAction action, IWorkbenchPart targetPart ) { - fTargetPart = targetPart; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) - */ - public void run( IAction action ) { - try { - getBreakpointAdapter().toggleWatchpoints( getTargetPart(), getSelection() ); - } - catch( CoreException e ) { - ErrorDialog.openError( getTargetPart().getSite().getShell(), - ActionMessages.getString( "ToggleWatchpointActionDelegate.Error_1" ), //$NON-NLS-1$ - ActionMessages.getString( "ToggleWatchpointActionDelegate.Operation_failed_1" ), //$NON-NLS-1$ - e.getStatus() ); - } - } - - /* (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 ) { - setSelection( selection ); - action.setEnabled( getBreakpointAdapter().canToggleWatchpoints( getTargetPart(), getSelection() ) ); - } - - private IWorkbenchPart getTargetPart() { - return fTargetPart; - } - - private ISelection getSelection() { - return fSelection; - } - - private IToggleBreakpointsTarget getBreakpointAdapter() { - IToggleBreakpointsTarget targetAdapter = null; - if (fTargetPart != null) { - IResource resource = (IResource) fTargetPart.getAdapter(IResource.class); - if (resource == null && fTargetPart instanceof IEditorPart) { - resource = (IResource) ((IEditorPart)fTargetPart).getEditorInput().getAdapter(IResource.class); - } - if (resource == null) { - // in case of outline view - IContributedContentsView contentsView = (IContributedContentsView) fTargetPart.getAdapter(IContributedContentsView.class); - if (contentsView != null) { - IWorkbenchPart contributingPart = contentsView.getContributingPart(); - resource = (IResource) contributingPart.getAdapter(IResource.class); - if (resource == null && contributingPart instanceof IEditorPart) { - resource = (IResource) ((IEditorPart)contributingPart).getEditorInput().getAdapter(IResource.class); - } - } - } - if (resource != null) { - targetAdapter = getAdapter(resource); - } - if (targetAdapter == null) { - targetAdapter = getAdapter(fTargetPart); - } - } - if (targetAdapter == null) { - targetAdapter = fBreakpointAdapter; - } - return targetAdapter; - } - - private IToggleBreakpointsTarget getAdapter(IAdaptable adaptable) { - IToggleBreakpointsTarget adapter= (IToggleBreakpointsTarget)adaptable.getAdapter(IToggleBreakpointsTarget.class); - if (adapter == null) { - IAdapterManager adapterManager= Platform.getAdapterManager(); - if (adapterManager.hasAdapter(adaptable, IToggleBreakpointsTarget.class.getName())) { - adapter= (IToggleBreakpointsTarget)adapterManager.loadAdapter(adaptable, IToggleBreakpointsTarget.class.getName()); - } - } - return adapter; - } - - private void setSelection( ISelection selection ) { - fSelection = selection; - } -} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/disassembly/editor/DisassemblyEditor.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/disassembly/editor/DisassemblyEditor.java index fc7d99c582b..3ce7f9074a2 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/disassembly/editor/DisassemblyEditor.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/disassembly/editor/DisassemblyEditor.java @@ -15,7 +15,6 @@ import org.eclipse.cdt.debug.core.disassembly.IDisassemblyContextProvider; import org.eclipse.cdt.debug.internal.ui.IInternalCDebugUIConstants; import org.eclipse.cdt.debug.internal.ui.actions.CBreakpointPropertiesRulerAction; import org.eclipse.cdt.debug.internal.ui.actions.EnableDisableBreakpointRulerAction; -import org.eclipse.cdt.debug.internal.ui.actions.ToggleBreakpointRulerAction; import org.eclipse.cdt.debug.internal.ui.disassembly.viewer.DisassemblyDocumentProvider; import org.eclipse.cdt.debug.internal.ui.disassembly.viewer.DisassemblyPane; import org.eclipse.cdt.debug.internal.ui.disassembly.viewer.DocumentContentProvider; @@ -26,9 +25,11 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.actions.ToggleBreakpointAction; import org.eclipse.debug.ui.contexts.DebugContextEvent; import org.eclipse.debug.ui.contexts.IDebugContextListener; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.source.IAnnotationModel; import org.eclipse.jface.text.source.IVerticalRuler; @@ -338,7 +339,7 @@ public class DisassemblyEditor extends EditorPart implements ITextEditor, IReusa protected void createActions() { IVerticalRuler ruler = fDisassemblyPane.getVerticalRuler(); - IAction action= new ToggleBreakpointRulerAction( this, ruler ); + IAction action= new ToggleBreakpointAction( this, null, ruler ); setAction( IInternalCDebugUIConstants.ACTION_TOGGLE_BREAKPOINT, action ); action= new EnableDisableBreakpointRulerAction( this, ruler ); setAction( IInternalCDebugUIConstants.ACTION_ENABLE_DISABLE_BREAKPOINT, action ); @@ -352,4 +353,12 @@ public class DisassemblyEditor extends EditorPart implements ITextEditor, IReusa public void propertyChange( PropertyChangeEvent event ) { getViewer().refresh(); } + + @Override + public Object getAdapter(Class adapter) { + if (IDocument.class.equals(adapter)) { + return getDocumentProvider().getDocument(getEditorInput()); + } + return super.getAdapter(adapter); + } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyView.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyView.java index 5f73fc25e69..583da105698 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyView.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyView.java @@ -23,7 +23,6 @@ import org.eclipse.cdt.debug.internal.ui.ICDebugHelpContextIds; import org.eclipse.cdt.debug.internal.ui.IInternalCDebugUIConstants; import org.eclipse.cdt.debug.internal.ui.actions.CBreakpointPropertiesRulerAction; import org.eclipse.cdt.debug.internal.ui.actions.EnableDisableBreakpointRulerAction; -import org.eclipse.cdt.debug.internal.ui.actions.ToggleBreakpointRulerAction; import org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandler; import org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandlerView; import org.eclipse.cdt.debug.internal.ui.views.IDebugExceptionHandler; @@ -37,6 +36,7 @@ import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.model.IThread; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.debug.ui.actions.ToggleBreakpointAction; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; @@ -46,6 +46,7 @@ import org.eclipse.jface.action.Separator; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.TextPresentation; @@ -304,7 +305,7 @@ public class DisassemblyView extends AbstractDebugEventHandlerView protected void createActions() { IAction action; IVerticalRuler ruler = getVerticalRuler(); - action= new ToggleBreakpointRulerAction( this, ruler ); + action= new ToggleBreakpointAction( this, null, ruler ); setAction( IInternalCDebugUIConstants.ACTION_TOGGLE_BREAKPOINT, action ); action= new EnableDisableBreakpointRulerAction( this, ruler ); setAction( IInternalCDebugUIConstants.ACTION_ENABLE_DISABLE_BREAKPOINT, action ); @@ -962,4 +963,12 @@ public class DisassemblyView extends AbstractDebugEventHandlerView } super.partDeactivated( part ); } + + @Override + public Object getAdapter(Class adapter) { + if (IDocument.class.equals(adapter)) { + return getDocumentProvider().getDocument(getInput()); + } + return super.getAdapter(adapter); + } }