From 987b06a53ee738a8b75b0bf2c89f6d38dfde4a9f Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Thu, 26 Apr 2007 09:06:33 +0000 Subject: [PATCH] Fix for 183396: Open up breakpoint ruler actions for other debug models --- .../AbstractBreakpointRulerAction.java | 153 ++++++++---------- .../CBreakpointPropertiesRulerAction.java | 24 ++- .../EnableDisableBreakpointRulerAction.java | 31 ++-- 3 files changed, 95 insertions(+), 113 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AbstractBreakpointRulerAction.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AbstractBreakpointRulerAction.java index 47e1d7c69b9..25c7dde2d4a 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AbstractBreakpointRulerAction.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AbstractBreakpointRulerAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 QNX Software Systems and others. + * 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 @@ -7,123 +7,106 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * Anton Leherbauer (Wind River Systems) - bug 183397 *******************************************************************************/ package org.eclipse.cdt.debug.internal.ui.actions; import java.util.Iterator; -import org.eclipse.cdt.debug.core.CDebugCorePlugin; + import org.eclipse.cdt.debug.internal.ui.views.disassembly.DisassemblyView; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.model.IBreakpoint; -import org.eclipse.debug.core.model.ILineBreakpoint; import org.eclipse.jface.action.Action; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.source.Annotation; import org.eclipse.jface.text.source.IAnnotationModel; import org.eclipse.jface.text.source.IVerticalRulerInfo; -import org.eclipse.ui.ISaveablePart; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.IUpdate; -import org.eclipse.ui.texteditor.MarkerAnnotation; +import org.eclipse.ui.texteditor.SimpleMarkerAnnotation; /** * Abstract base implementation of the breakpoint ruler actions. + * + * @see {@link RulerBreakpointAction} */ public abstract class AbstractBreakpointRulerAction extends Action implements IUpdate { - - private IVerticalRulerInfo fInfo; - - private IWorkbenchPart fTargetPart; - - private IBreakpoint fBreakpoint; - - protected IBreakpoint determineBreakpoint() { - IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints( CDebugCorePlugin.getUniqueIdentifier() ); - for( int i = 0; i < breakpoints.length; i++ ) { - IBreakpoint breakpoint = breakpoints[i]; - if ( breakpoint instanceof ILineBreakpoint ) { - ILineBreakpoint lineBreakpoint = (ILineBreakpoint)breakpoint; - if ( breakpointAtRulerLine( lineBreakpoint ) ) { - return lineBreakpoint; - } - } - } - return null; - } - - protected IVerticalRulerInfo getInfo() { - return fInfo; - } - - protected void setInfo( IVerticalRulerInfo info ) { - fInfo = info; - } - - protected IWorkbenchPart getTargetPart() { - return this.fTargetPart; - } - protected void setTargetPart( IWorkbenchPart targetPart ) { - this.fTargetPart = targetPart; + + private final IWorkbenchPart fTargetPart; + private final IVerticalRulerInfo fRulerInfo; + + /** + * Constructs an action to work on breakpoints in the specified + * part with the specified vertical ruler information. + * + * @param part a text editor or DisassemblyView + * @param info vertical ruler information + */ + public AbstractBreakpointRulerAction(IWorkbenchPart part, IVerticalRulerInfo info) { + Assert.isTrue(part instanceof ITextEditor || part instanceof DisassemblyView); + fTargetPart = part; + fRulerInfo = info; } + /** + * Returns the breakpoint at the last line of mouse activity in the ruler + * or null if none. + * + * @return breakpoint associated with activity in the ruler or null + */ protected IBreakpoint getBreakpoint() { - return fBreakpoint; - } - - protected void setBreakpoint( IBreakpoint breakpoint ) { - fBreakpoint = breakpoint; - } - - protected boolean breakpointAtRulerLine( ILineBreakpoint cBreakpoint ) { - int lineNumber = getBreakpointLine( cBreakpoint ); - int rulerLine = getInfo().getLineOfLastMouseButtonActivity(); - return ( rulerLine == lineNumber ); - } - - private int getBreakpointLine( ILineBreakpoint breakpoint ) { - if ( getTargetPart() instanceof ISaveablePart && ((ISaveablePart)getTargetPart()).isDirty() ) { - try { - return breakpoint.getLineNumber(); - } - catch( CoreException e ) { - DebugPlugin.log( e ); - } - } - else { - Position position = getBreakpointPosition( breakpoint ); - if ( position != null ) { - IDocument doc = getDocument(); - if ( doc != null ) { + IAnnotationModel annotationModel = getAnnotationModel(); + IDocument document = getDocument(); + if (annotationModel != null) { + Iterator iterator = annotationModel.getAnnotationIterator(); + while (iterator.hasNext()) { + Object object = iterator.next(); + if (object instanceof SimpleMarkerAnnotation) { + SimpleMarkerAnnotation markerAnnotation = (SimpleMarkerAnnotation) object; + IMarker marker = markerAnnotation.getMarker(); try { - return doc.getLineOfOffset( position.getOffset() ); + if (marker.isSubtypeOf(IBreakpoint.BREAKPOINT_MARKER)) { + Position position = annotationModel.getPosition(markerAnnotation); + int line = document.getLineOfOffset(position.getOffset()); + if (line == fRulerInfo.getLineOfLastMouseButtonActivity()) { + IBreakpoint breakpoint = DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(marker); + if (breakpoint != null) { + return breakpoint; + } + } + } + } catch (CoreException e) { + } catch (BadLocationException e) { } - catch ( BadLocationException x ) { - DebugPlugin.log( x ); - } - } - } - } - return -1; - } - - private Position getBreakpointPosition( ILineBreakpoint breakpoint ) { - IAnnotationModel model = getAnnotationModel(); - if ( model != null ) { - Iterator it = model.getAnnotationIterator(); - while( it.hasNext() ) { - Annotation ann = (Annotation)it.next(); - if ( ann instanceof MarkerAnnotation && ((MarkerAnnotation)ann).getMarker().equals( breakpoint.getMarker() ) ) { - return model.getPosition( ann ); } } } return null; } + + /** + * Returns the workbench part this action was created for. + * + * @return workbench part, a text editor or a DisassemblyView + */ + protected IWorkbenchPart getTargetPart() { + return fTargetPart; + } + + /** + * Returns the vertical ruler information this action was created for. + * + * @return vertical ruler information + */ + protected IVerticalRulerInfo getVerticalRulerInfo() { + return fRulerInfo; + } private IDocument getDocument() { IWorkbenchPart targetPart = getTargetPart(); diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CBreakpointPropertiesRulerAction.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CBreakpointPropertiesRulerAction.java index 44e53879c41..fe82e41341e 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CBreakpointPropertiesRulerAction.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CBreakpointPropertiesRulerAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 QNX Software Systems and others. + * 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 @@ -7,12 +7,13 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * Anton Leherbauer (Wind River Systems) - bug 183397 *******************************************************************************/ package org.eclipse.cdt.debug.internal.ui.actions; -import org.eclipse.cdt.debug.core.model.ICBreakpoint; import org.eclipse.cdt.debug.internal.ui.ICDebugHelpContextIds; import org.eclipse.cdt.debug.internal.ui.IInternalCDebugUIConstants; +import org.eclipse.debug.core.model.IBreakpoint; import org.eclipse.jface.text.source.IVerticalRulerInfo; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; @@ -27,12 +28,13 @@ import org.eclipse.ui.dialogs.PropertyDialogAction; */ public class CBreakpointPropertiesRulerAction extends AbstractBreakpointRulerAction { + private IBreakpoint fBreakpoint; + /** * Creates the action to modify the breakpoint properties. */ public CBreakpointPropertiesRulerAction( IWorkbenchPart part, IVerticalRulerInfo info ) { - setInfo( info ); - setTargetPart( part ); + super( part, info ); setText( ActionMessages.getString( "CBreakpointPropertiesRulerAction.Breakpoint_Properties" ) ); //$NON-NLS-1$ part.getSite().getWorkbenchWindow().getWorkbench().getHelpSystem().setHelp( this, ICDebugHelpContextIds.BREAKPOINT_PROPERTIES_ACTION ); setId( IInternalCDebugUIConstants.ACTION_BREAKPOINT_PROPERTIES ); @@ -42,14 +44,14 @@ public class CBreakpointPropertiesRulerAction extends AbstractBreakpointRulerAct * @see Action#run() */ public void run() { - if ( getBreakpoint() != null ) { + if ( fBreakpoint != null ) { PropertyDialogAction action = new PropertyDialogAction( getTargetPart().getSite(), new ISelectionProvider() { public void addSelectionChangedListener( ISelectionChangedListener listener ) { } public ISelection getSelection() { - return new StructuredSelection( getBreakpoint() ); + return new StructuredSelection( fBreakpoint ); } public void removeSelectionChangedListener( ISelectionChangedListener listener ) { @@ -59,6 +61,7 @@ public class CBreakpointPropertiesRulerAction extends AbstractBreakpointRulerAct } } ); action.run(); + action.dispose(); } } @@ -66,12 +69,7 @@ public class CBreakpointPropertiesRulerAction extends AbstractBreakpointRulerAct * @see IUpdate#update() */ public void update() { - setBreakpoint( determineBreakpoint() ); - if ( getBreakpoint() == null || !(getBreakpoint() instanceof ICBreakpoint) ) { - setBreakpoint( null ); - setEnabled( false ); - return; - } - setEnabled( true ); + fBreakpoint = getBreakpoint(); + setEnabled( fBreakpoint != null ); } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/EnableDisableBreakpointRulerAction.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/EnableDisableBreakpointRulerAction.java index 1ec744dd740..0cc32eb9755 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/EnableDisableBreakpointRulerAction.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/EnableDisableBreakpointRulerAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 QNX Software Systems and others. + * 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 @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * Anton Leherbauer (Wind River Systems) - bug 183397 *******************************************************************************/ package org.eclipse.cdt.debug.internal.ui.actions; @@ -14,18 +15,20 @@ import org.eclipse.cdt.debug.internal.ui.ICDebugHelpContextIds; import org.eclipse.cdt.debug.internal.ui.IInternalCDebugUIConstants; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.model.IBreakpoint; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.jface.text.source.IVerticalRulerInfo; import org.eclipse.ui.IWorkbenchPart; public class EnableDisableBreakpointRulerAction extends AbstractBreakpointRulerAction { + private IBreakpoint fBreakpoint; + /** * Creates the action to enable/disable breakpoints */ public EnableDisableBreakpointRulerAction( IWorkbenchPart part, IVerticalRulerInfo info ) { - setInfo( info ); - setTargetPart( part ); + super( part, info ); setText( ActionMessages.getString( "EnableDisableBreakpointRulerAction.Enable_Breakpoint_1" ) ); //$NON-NLS-1$ part.getSite().getWorkbenchWindow().getWorkbench().getHelpSystem().setHelp( this, ICDebugHelpContextIds.ENABLE_DISABLE_BREAKPOINT_ACTION ); setId( IInternalCDebugUIConstants.ACTION_ENABLE_DISABLE_BREAKPOINT ); @@ -51,18 +54,16 @@ public class EnableDisableBreakpointRulerAction extends AbstractBreakpointRulerA * @see org.eclipse.ui.texteditor.IUpdate#update() */ public void update() { - setBreakpoint( determineBreakpoint() ); - if ( getBreakpoint() == null ) { - setEnabled( false ); - return; - } - setEnabled( true ); - try { - boolean enabled = getBreakpoint().isEnabled(); - setText( enabled ? ActionMessages.getString( "EnableDisableBreakpointRulerAction.Disable_Breakpoint_1" ) : ActionMessages.getString( "EnableDisableBreakpointRulerAction.Enable_Breakpoint_1" ) ); //$NON-NLS-1$ //$NON-NLS-2$ - } - catch( CoreException e ) { - DebugPlugin.log( e ); + fBreakpoint = getBreakpoint(); + setEnabled( fBreakpoint != null ); + if ( isEnabled() ) { + try { + boolean enabled = getBreakpoint().isEnabled(); + setText( enabled ? ActionMessages.getString( "EnableDisableBreakpointRulerAction.Disable_Breakpoint_1" ) : ActionMessages.getString( "EnableDisableBreakpointRulerAction.Enable_Breakpoint_1" ) ); //$NON-NLS-1$ //$NON-NLS-2$ + } + catch( CoreException e ) { + DebugPlugin.log( e ); + } } } }