1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 22:22:11 +02:00

Fix for 183396: Open up breakpoint ruler actions for other debug models

This commit is contained in:
Anton Leherbauer 2007-04-26 09:06:33 +00:00
parent 6342a2854c
commit 987b06a53e
3 changed files with 95 additions and 113 deletions

View file

@ -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,124 +7,107 @@
*
* 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 final IWorkbenchPart fTargetPart;
private final IVerticalRulerInfo fRulerInfo;
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;
/**
* 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 <code>null</code> if none.
*
* @return breakpoint associated with activity in the ruler or <code>null</code>
*/
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() ) {
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 breakpoint.getLineNumber();
}
catch( CoreException e ) {
DebugPlugin.log( e );
}
}
else {
Position position = getBreakpointPosition( breakpoint );
if ( position != null ) {
IDocument doc = getDocument();
if ( doc != null ) {
try {
return doc.getLineOfOffset( position.getOffset() );
}
catch ( BadLocationException x ) {
DebugPlugin.log( x );
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) {
}
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();
if ( targetPart instanceof ITextEditor ) {

View file

@ -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 );
}
}

View file

@ -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,12 +54,9 @@ 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 );
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$
@ -66,3 +66,4 @@ public class EnableDisableBreakpointRulerAction extends AbstractBreakpointRulerA
}
}
}
}