mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-15 04:05:38 +02:00
Add 'Enable/Disable Breakpoint' action.
This commit is contained in:
parent
094838afc5
commit
8d6b618921
8 changed files with 270 additions and 1 deletions
|
@ -15,3 +15,6 @@ CDebuggerPage.name=C Debugger UI Page
|
||||||
DebugActionSet.label=DebugActionSet
|
DebugActionSet.label=DebugActionSet
|
||||||
RestartAction.label=Restart
|
RestartAction.label=Restart
|
||||||
RestartAction.tooltip=Restart
|
RestartAction.tooltip=Restart
|
||||||
|
|
||||||
|
AddBreakpoint.label=Add/Remove &Breakpoint
|
||||||
|
EnableBreakpoint.label=T&oggle Breakpoint
|
||||||
|
|
|
@ -111,6 +111,13 @@
|
||||||
<viewerContribution
|
<viewerContribution
|
||||||
targetID="#RulerContext"
|
targetID="#RulerContext"
|
||||||
id="org.eclipse.cdt.debug.ui.CEditorPopupActions">
|
id="org.eclipse.cdt.debug.ui.CEditorPopupActions">
|
||||||
|
<action
|
||||||
|
label="%EnableBreakpoint.label"
|
||||||
|
helpContextId="enable_disable_breakpoint_action_context"
|
||||||
|
class="org.eclipse.cdt.debug.internal.ui.actions.EnableDisableBreakpointRulerActionDelegate"
|
||||||
|
menubarPath="debug"
|
||||||
|
id="org.eclipse.cdt.debug.internal.ui.actions.EnableDisableBreakpointRulerActionDelegate">
|
||||||
|
</action>
|
||||||
<action
|
<action
|
||||||
label="%AddBreakpoint.label"
|
label="%AddBreakpoint.label"
|
||||||
helpContextId="manage_breakpoint_action_context"
|
helpContextId="manage_breakpoint_action_context"
|
||||||
|
|
|
@ -0,0 +1,163 @@
|
||||||
|
/*
|
||||||
|
*(c) Copyright QNX Software Systems Ltd. 2002.
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.eclipse.cdt.debug.internal.ui.actions;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
|
||||||
|
import org.eclipse.cdt.debug.core.ICLineBreakpoint;
|
||||||
|
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.debug.core.DebugPlugin;
|
||||||
|
import org.eclipse.debug.core.model.IBreakpoint;
|
||||||
|
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.IAnnotationModel;
|
||||||
|
import org.eclipse.jface.text.source.IVerticalRulerInfo;
|
||||||
|
import org.eclipse.ui.IEditorInput;
|
||||||
|
import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
|
||||||
|
import org.eclipse.ui.texteditor.IDocumentProvider;
|
||||||
|
import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
|
import org.eclipse.ui.texteditor.IUpdate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Enter type comment.
|
||||||
|
*
|
||||||
|
* @since Aug 26, 2002
|
||||||
|
*/
|
||||||
|
public abstract class AbstractBreakpointRulerAction extends Action implements IUpdate
|
||||||
|
{
|
||||||
|
private IVerticalRulerInfo fInfo;
|
||||||
|
|
||||||
|
private ITextEditor fTextEditor;
|
||||||
|
|
||||||
|
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 ICLineBreakpoint )
|
||||||
|
{
|
||||||
|
ICLineBreakpoint cBreakpoint = (ICLineBreakpoint)breakpoint;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if ( breakpointAtRulerLine( cBreakpoint ) )
|
||||||
|
{
|
||||||
|
return cBreakpoint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch( CoreException ce )
|
||||||
|
{
|
||||||
|
CDebugUIPlugin.log( ce );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IVerticalRulerInfo getInfo()
|
||||||
|
{
|
||||||
|
return fInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setInfo( IVerticalRulerInfo info )
|
||||||
|
{
|
||||||
|
fInfo = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ITextEditor getTextEditor()
|
||||||
|
{
|
||||||
|
return fTextEditor;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setTextEditor( ITextEditor textEditor )
|
||||||
|
{
|
||||||
|
fTextEditor = textEditor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the resource for which to create the marker,
|
||||||
|
* or <code>null</code> if there is no applicable resource.
|
||||||
|
*
|
||||||
|
* @return the resource for which to create the marker or <code>null</code>
|
||||||
|
*/
|
||||||
|
protected IResource getResource()
|
||||||
|
{
|
||||||
|
IEditorInput input = fTextEditor.getEditorInput();
|
||||||
|
IResource resource = (IResource)input.getAdapter( IFile.class );
|
||||||
|
if ( resource == null )
|
||||||
|
{
|
||||||
|
resource = (IResource)input.getAdapter( IResource.class );
|
||||||
|
}
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean breakpointAtRulerLine( ICLineBreakpoint cBreakpoint ) throws CoreException
|
||||||
|
{
|
||||||
|
AbstractMarkerAnnotationModel model = getAnnotationModel();
|
||||||
|
if ( model != null )
|
||||||
|
{
|
||||||
|
Position position = model.getMarkerPosition( cBreakpoint.getMarker() );
|
||||||
|
if ( position != null )
|
||||||
|
{
|
||||||
|
IDocumentProvider provider = getTextEditor().getDocumentProvider();
|
||||||
|
IDocument doc = provider.getDocument( getTextEditor().getEditorInput() );
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int markerLineNumber = doc.getLineOfOffset( position.getOffset() );
|
||||||
|
int rulerLine = getInfo().getLineOfLastMouseButtonActivity();
|
||||||
|
if ( rulerLine == markerLineNumber )
|
||||||
|
{
|
||||||
|
if ( getTextEditor().isDirty() )
|
||||||
|
{
|
||||||
|
return cBreakpoint.getLineNumber() == markerLineNumber + 1;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch ( BadLocationException x )
|
||||||
|
{
|
||||||
|
CDebugUIPlugin.log( x );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IBreakpoint getBreakpoint()
|
||||||
|
{
|
||||||
|
return fBreakpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setBreakpoint( IBreakpoint breakpoint )
|
||||||
|
{
|
||||||
|
fBreakpoint = breakpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the <code>AbstractMarkerAnnotationModel</code> of the editor's input.
|
||||||
|
*
|
||||||
|
* @return the marker annotation model
|
||||||
|
*/
|
||||||
|
protected AbstractMarkerAnnotationModel getAnnotationModel()
|
||||||
|
{
|
||||||
|
IDocumentProvider provider = fTextEditor.getDocumentProvider();
|
||||||
|
IAnnotationModel model = provider.getAnnotationModel( getTextEditor().getEditorInput() );
|
||||||
|
if ( model instanceof AbstractMarkerAnnotationModel )
|
||||||
|
{
|
||||||
|
return (AbstractMarkerAnnotationModel)model;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
package org.eclipse.cdt.debug.internal.ui.actions;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.jface.dialogs.ErrorDialog;
|
||||||
|
import org.eclipse.jface.text.source.IVerticalRulerInfo;
|
||||||
|
import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
|
|
||||||
|
public class EnableDisableBreakpointRulerAction extends AbstractBreakpointRulerAction
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Creates the action to enable/disable breakpoints
|
||||||
|
*/
|
||||||
|
public EnableDisableBreakpointRulerAction( ITextEditor editor, IVerticalRulerInfo info )
|
||||||
|
{
|
||||||
|
setInfo( info );
|
||||||
|
setTextEditor( editor );
|
||||||
|
setText( "&Enable Breakpoint" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Action#run()
|
||||||
|
*/
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
if (getBreakpoint() != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
getBreakpoint().setEnabled( !getBreakpoint().isEnabled() );
|
||||||
|
}
|
||||||
|
catch (CoreException e)
|
||||||
|
{
|
||||||
|
ErrorDialog.openError( getTextEditor().getEditorSite().getShell(),
|
||||||
|
"Enabling/disabling breakpoints",
|
||||||
|
"Exceptions occurred enabling disabling the breakpoint",
|
||||||
|
e.getStatus() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see IUpdate#update()
|
||||||
|
*/
|
||||||
|
public void update()
|
||||||
|
{
|
||||||
|
setBreakpoint(determineBreakpoint());
|
||||||
|
if ( getBreakpoint() == null )
|
||||||
|
{
|
||||||
|
setEnabled( false );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setEnabled( true );
|
||||||
|
try
|
||||||
|
{
|
||||||
|
boolean enabled = getBreakpoint().isEnabled();
|
||||||
|
setText( enabled ? "&Disable Breakpoint" : "&Enable Breakpoint" );
|
||||||
|
}
|
||||||
|
catch( CoreException ce )
|
||||||
|
{
|
||||||
|
CDebugUIPlugin.log( ce );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
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.texteditor.AbstractRulerActionDelegate;
|
||||||
|
import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
|
|
||||||
|
public class EnableDisableBreakpointRulerActionDelegate extends AbstractRulerActionDelegate
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @see AbstractRulerActionDelegate#createAction(ITextEditor, IVerticalRulerInfo)
|
||||||
|
*/
|
||||||
|
protected IAction createAction( ITextEditor editor, IVerticalRulerInfo rulerInfo )
|
||||||
|
{
|
||||||
|
return new EnableDisableBreakpointRulerAction( editor, rulerInfo );
|
||||||
|
}
|
||||||
|
}
|
|
@ -38,7 +38,7 @@ public class ManageBreakpointRulerActionDelegate extends AbstractRulerActionDele
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.ui.texteditor.AbstractRulerActionDelegate#createAction(ITextEditor, IVerticalRulerInfo)
|
* @see org.eclipse.ui.texteditor.AbstractRulerActionDelegate#createAction(ITextEditor, IVerticalRulerInfo)
|
||||||
*/
|
*/
|
||||||
protected IAction createAction( ITextEditor editor, IVerticalRulerInfo rulerInfo )
|
public IAction createAction( ITextEditor editor, IVerticalRulerInfo rulerInfo )
|
||||||
{
|
{
|
||||||
return new ManageBreakpointRulerAction( rulerInfo, editor );
|
return new ManageBreakpointRulerAction( rulerInfo, editor );
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,6 +164,16 @@ public class CDebugUIPlugin extends AbstractUIPlugin
|
||||||
public static void log(IStatus status) {
|
public static void log(IStatus status) {
|
||||||
getDefault().getLog().log(status);
|
getDefault().getLog().log(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs an internal error with the specified throwable
|
||||||
|
*
|
||||||
|
* @param e the exception to be logged
|
||||||
|
*/
|
||||||
|
public static void log( Throwable e )
|
||||||
|
{
|
||||||
|
log( new Status( IStatus.ERROR, getUniqueIdentifier(), ICDebugUIConstants.INTERNAL_ERROR, "Internal Error", e ) );
|
||||||
|
}
|
||||||
|
|
||||||
public ILaunchConfigurationTab getDebuggerPage(String debuggerID) {
|
public ILaunchConfigurationTab getDebuggerPage(String debuggerID) {
|
||||||
if (fDebuggerPageMap == null) {
|
if (fDebuggerPageMap == null) {
|
||||||
|
|
|
@ -32,4 +32,9 @@ public interface ICDebugUIConstants
|
||||||
* Memory view identifier (value <code>"org.eclipse.cdt.debug.ui.MemoryView"</code>).
|
* Memory view identifier (value <code>"org.eclipse.cdt.debug.ui.MemoryView"</code>).
|
||||||
*/
|
*/
|
||||||
public static final String ID_MEMORY_VIEW = "org.eclipse.cdt.debug.ui.MemoryView"; //$NON-NLS-1$
|
public static final String ID_MEMORY_VIEW = "org.eclipse.cdt.debug.ui.MemoryView"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Status code indicating an unexpected internal error.
|
||||||
|
*/
|
||||||
|
public static final int INTERNAL_ERROR = 150;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue