mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-12 02:35:37 +02:00
More implementation of breakpoints.
This commit is contained in:
parent
becf2c5ca0
commit
477450be7a
13 changed files with 508 additions and 6 deletions
|
@ -50,6 +50,9 @@
|
||||||
<super
|
<super
|
||||||
type="org.eclipse.debug.core.lineBreakpointMarker">
|
type="org.eclipse.debug.core.lineBreakpointMarker">
|
||||||
</super>
|
</super>
|
||||||
|
<persistent
|
||||||
|
value="true">
|
||||||
|
</persistent>
|
||||||
</extension>
|
</extension>
|
||||||
<extension
|
<extension
|
||||||
id="cLineBreakpointMarker"
|
id="cLineBreakpointMarker"
|
||||||
|
@ -68,7 +71,7 @@
|
||||||
type="org.eclipse.cdt.debug.core.commonCLineBreakpointMarker">
|
type="org.eclipse.cdt.debug.core.commonCLineBreakpointMarker">
|
||||||
</super>
|
</super>
|
||||||
<persistent
|
<persistent
|
||||||
value="org.eclipse.cdt.debug.core.persistent3">
|
value="true">
|
||||||
</persistent>
|
</persistent>
|
||||||
<attribute
|
<attribute
|
||||||
name="address">
|
name="address">
|
||||||
|
@ -103,17 +106,17 @@
|
||||||
<extension
|
<extension
|
||||||
point="org.eclipse.debug.core.breakpoints">
|
point="org.eclipse.debug.core.breakpoints">
|
||||||
<breakpoint
|
<breakpoint
|
||||||
markerType="cLineBreakpointMarker"
|
markerType="org.eclipse.cdt.debug.core.cLineBreakpointMarker"
|
||||||
class="org.eclipse.cdt.debug.internal.core.breakpoints.CLineBreakpoint"
|
class="org.eclipse.cdt.debug.internal.core.breakpoints.CLineBreakpoint"
|
||||||
id="cLineBreakpoint">
|
id="cLineBreakpoint">
|
||||||
</breakpoint>
|
</breakpoint>
|
||||||
<breakpoint
|
<breakpoint
|
||||||
markerType="cAddressBreakpointMarker"
|
markerType="org.eclipse.cdt.debug.core.cAddressBreakpointMarker"
|
||||||
class="org.eclipse.cdt.debug.internal.core.breakpoints.CAddressBreakpoint"
|
class="org.eclipse.cdt.debug.internal.core.breakpoints.CAddressBreakpoint"
|
||||||
id="cAddressBreakpoint">
|
id="cAddressBreakpoint">
|
||||||
</breakpoint>
|
</breakpoint>
|
||||||
<breakpoint
|
<breakpoint
|
||||||
markerType="cFunctionBreakpointMarker"
|
markerType="org.eclipse.cdt.debug.core.cFunctionBreakpointMarker"
|
||||||
class="org.eclipse.cdt.debug.internal.core.breakpoints.CFunctionBreakpoint"
|
class="org.eclipse.cdt.debug.internal.core.breakpoints.CFunctionBreakpoint"
|
||||||
id="cFunctionBreakpoint">
|
id="cFunctionBreakpoint">
|
||||||
</breakpoint>
|
</breakpoint>
|
||||||
|
|
|
@ -159,7 +159,7 @@ public class CDebugModel
|
||||||
ICLineBreakpoint breakpoint = (ICLineBreakpoint)breakpoints[i];
|
ICLineBreakpoint breakpoint = (ICLineBreakpoint)breakpoints[i];
|
||||||
if ( breakpoint.getMarker().getType().equals( markerType ) )
|
if ( breakpoint.getMarker().getType().equals( markerType ) )
|
||||||
{
|
{
|
||||||
if ( breakpoint.getMarker().getResource().getLocation().toString().equals( fileName ) )
|
if ( breakpoint.getMarker().getResource().getLocation().toOSString().equals( fileName ) )
|
||||||
{
|
{
|
||||||
if ( breakpoint.getLineNumber() == lineNumber )
|
if ( breakpoint.getLineNumber() == lineNumber )
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,6 +30,13 @@ public class CAddressBreakpoint extends CBreakpoint implements ICAddressBreakpoi
|
||||||
*/
|
*/
|
||||||
protected static final String ADDRESS = "org.eclipse.cdt.debug.core.address"; //$NON-NLS-1$
|
protected static final String ADDRESS = "org.eclipse.cdt.debug.core.address"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for CAddressBreakpoint.
|
||||||
|
*/
|
||||||
|
public CAddressBreakpoint()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for CAddressBreakpoint.
|
* Constructor for CAddressBreakpoint.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -61,6 +61,13 @@ public abstract class CBreakpoint extends Breakpoint
|
||||||
*/
|
*/
|
||||||
protected static final String THREAD_ID = "org.eclipse.cdt.debug.core.threadId"; //$NON-NLS-1$
|
protected static final String THREAD_ID = "org.eclipse.cdt.debug.core.threadId"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for CBreakpoint.
|
||||||
|
*/
|
||||||
|
public CBreakpoint()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for CBreakpoint.
|
* Constructor for CBreakpoint.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -30,6 +30,13 @@ public class CFunctionBreakpoint extends CBreakpoint implements ICFunctionBreakp
|
||||||
*/
|
*/
|
||||||
protected static final String FUNCTION = "org.eclipse.cdt.debug.core.function"; //$NON-NLS-1$
|
protected static final String FUNCTION = "org.eclipse.cdt.debug.core.function"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for CFunctionBreakpoint.
|
||||||
|
*/
|
||||||
|
public CFunctionBreakpoint()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for CFunctionBreakpoint.
|
* Constructor for CFunctionBreakpoint.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -25,6 +25,13 @@ public class CLineBreakpoint extends CBreakpoint implements ICLineBreakpoint
|
||||||
{
|
{
|
||||||
private static final String C_LINE_BREAKPOINT = "org.eclipse.cdt.debug.core.cLineBreakpointMarker"; //$NON-NLS-1$
|
private static final String C_LINE_BREAKPOINT = "org.eclipse.cdt.debug.core.cLineBreakpointMarker"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for CLineBreakpoint.
|
||||||
|
*/
|
||||||
|
public CLineBreakpoint()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for CLineBreakpoint.
|
* Constructor for CLineBreakpoint.
|
||||||
*/
|
*/
|
||||||
|
|
BIN
debug/org.eclipse.cdt.debug.ui/icons/full/obj16/brkpi_obj.gif
Normal file
BIN
debug/org.eclipse.cdt.debug.ui/icons/full/obj16/brkpi_obj.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 107 B |
|
@ -18,4 +18,6 @@ RestartAction.tooltip=Restart
|
||||||
|
|
||||||
AddBreakpoint.label=Add/Remove &Breakpoint
|
AddBreakpoint.label=Add/Remove &Breakpoint
|
||||||
EnableBreakpoint.label=T&oggle Breakpoint
|
EnableBreakpoint.label=T&oggle Breakpoint
|
||||||
BreakpointProperties.label=Breakpoint &Properties...
|
BreakpointProperties.label=Breakpoint P&roperties...
|
||||||
|
ManageBreakpointAction.label=Add/Remove C/C++ Brea&kpoint
|
||||||
|
BreakpointPropertiesAction.label=P&roperties...
|
|
@ -90,6 +90,26 @@
|
||||||
helpContextId="restart_action_context"
|
helpContextId="restart_action_context"
|
||||||
label="%RestartAction.label"
|
label="%RestartAction.label"
|
||||||
menubarPath="org.eclipse.ui.run/stepGroup">
|
menubarPath="org.eclipse.ui.run/stepGroup">
|
||||||
|
<enablement>
|
||||||
|
<pluginState
|
||||||
|
value="activated"
|
||||||
|
id="org.eclipse.cdt.debug.ui">
|
||||||
|
</pluginState>
|
||||||
|
</enablement>
|
||||||
|
</action>
|
||||||
|
<action
|
||||||
|
label="%ManageBreakpointAction.label"
|
||||||
|
icon="icons/full/obj16/brkpi_obj.gif"
|
||||||
|
helpContextId="manage_breakpoint_action_context"
|
||||||
|
class="org.eclipse.cdt.debug.internal.ui.actions.ManageBreakpointActionDelegate"
|
||||||
|
menubarPath="org.eclipse.ui.run/breakpointGroup"
|
||||||
|
id="org.eclipse.cdt.debug.ui.internal.actions.ManageBreakpointActionDelegate">
|
||||||
|
<enablement>
|
||||||
|
<pluginState
|
||||||
|
value="activated"
|
||||||
|
id="org.eclipse.cdt.debug.ui">
|
||||||
|
</pluginState>
|
||||||
|
</enablement>
|
||||||
</action>
|
</action>
|
||||||
</actionSet>
|
</actionSet>
|
||||||
</extension>
|
</extension>
|
||||||
|
@ -133,6 +153,18 @@
|
||||||
id="org.eclipse.cdt.debug.internal.ui.actions.ManageBreakpointRulerActionDelegate">
|
id="org.eclipse.cdt.debug.internal.ui.actions.ManageBreakpointRulerActionDelegate">
|
||||||
</action>
|
</action>
|
||||||
</viewerContribution>
|
</viewerContribution>
|
||||||
|
<objectContribution
|
||||||
|
objectClass="org.eclipse.cdt.debug.core.ICBreakpoint"
|
||||||
|
id="org.eclipse.cdt.debug.ui.CBreakpointActions">
|
||||||
|
<action
|
||||||
|
label="%BreakpointPropertiesAction.label"
|
||||||
|
helpContextId="breakpoint_properties_action_context"
|
||||||
|
class="org.eclipse.cdt.debug.internal.ui.actions.CBreakpointPropertiesAction"
|
||||||
|
menubarPath="additions"
|
||||||
|
enablesFor="1"
|
||||||
|
id="org.eclipse.cdt.debug.internal.ui.actions.CBreakpointPropertiesAction">
|
||||||
|
</action>
|
||||||
|
</objectContribution>
|
||||||
</extension>
|
</extension>
|
||||||
<extension
|
<extension
|
||||||
point="org.eclipse.ui.viewActions">
|
point="org.eclipse.ui.viewActions">
|
||||||
|
@ -153,5 +185,18 @@
|
||||||
</action>
|
</action>
|
||||||
</viewContribution>
|
</viewContribution>
|
||||||
</extension>
|
</extension>
|
||||||
|
<extension
|
||||||
|
point="org.eclipse.ui.editorActions">
|
||||||
|
<editorContribution
|
||||||
|
targetID="org.eclipse.cdt.ui.editor.CEditor"
|
||||||
|
id="org.eclipse.cdt.debug.ui.CEditor.BreakpointRulerActions">
|
||||||
|
<action
|
||||||
|
label="%Dummy.label"
|
||||||
|
class="org.eclipse.cdt.debug.internal.ui.actions.ManageBreakpointRulerActionDelegate"
|
||||||
|
actionID="RulerDoubleClick"
|
||||||
|
id="org.eclipse.cdt.debug.ui.CEditor.ManageBreakpointRulerAction">
|
||||||
|
</action>
|
||||||
|
</editorContribution>
|
||||||
|
</extension>
|
||||||
|
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
|
@ -118,6 +118,8 @@ public class CDTDebugModelPresentation extends LabelProvider
|
||||||
}
|
}
|
||||||
if ( element instanceof IFile )
|
if ( element instanceof IFile )
|
||||||
file = (IFile)element;
|
file = (IFile)element;
|
||||||
|
if ( element instanceof ICLineBreakpoint )
|
||||||
|
file = (IFile)((ICLineBreakpoint)element).getMarker().getResource().getAdapter( IFile.class );
|
||||||
if ( file != null )
|
if ( file != null )
|
||||||
return new FileEditorInput( file );
|
return new FileEditorInput( file );
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
/*
|
||||||
|
*(c) Copyright QNX Software Systems Ltd. 2002.
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.eclipse.cdt.debug.internal.ui.actions;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.debug.core.ICBreakpoint;
|
||||||
|
import org.eclipse.jface.action.IAction;
|
||||||
|
import org.eclipse.jface.dialogs.Dialog;
|
||||||
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
|
import org.eclipse.ui.IObjectActionDelegate;
|
||||||
|
import org.eclipse.ui.IWorkbenchPart;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Presents a custom properties dialog to configure the attibutes of a C/C++ breakpoint.
|
||||||
|
*
|
||||||
|
* @since Sep 3, 2002
|
||||||
|
*/
|
||||||
|
public class CBreakpointPropertiesAction implements IObjectActionDelegate
|
||||||
|
{
|
||||||
|
private IWorkbenchPart fPart;
|
||||||
|
private ICBreakpoint fBreakpoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for CBreakpointPropertiesAction.
|
||||||
|
*/
|
||||||
|
public CBreakpointPropertiesAction()
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
|
||||||
|
*/
|
||||||
|
public void setActivePart( IAction action, IWorkbenchPart targetPart )
|
||||||
|
{
|
||||||
|
fPart = targetPart;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IActionDelegate#run(IAction)
|
||||||
|
*/
|
||||||
|
public void run( IAction action )
|
||||||
|
{
|
||||||
|
Dialog d = new CBreakpointPropertiesDialog( getActivePart().getSite().getShell(), getBreakpoint() );
|
||||||
|
d.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
|
||||||
|
*/
|
||||||
|
public void selectionChanged( IAction action, ISelection selection )
|
||||||
|
{
|
||||||
|
if ( selection instanceof IStructuredSelection )
|
||||||
|
{
|
||||||
|
IStructuredSelection ss = (IStructuredSelection)selection;
|
||||||
|
if ( ss.isEmpty() || ss.size() > 1 )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Object element = ss.getFirstElement();
|
||||||
|
if ( element instanceof ICBreakpoint )
|
||||||
|
{
|
||||||
|
setBreakpoint( (ICBreakpoint)element );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IWorkbenchPart getActivePart()
|
||||||
|
{
|
||||||
|
return fPart;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setActivePart( IWorkbenchPart part )
|
||||||
|
{
|
||||||
|
fPart = part;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ICBreakpoint getBreakpoint()
|
||||||
|
{
|
||||||
|
return fBreakpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setBreakpoint( ICBreakpoint breakpoint )
|
||||||
|
{
|
||||||
|
fBreakpoint = breakpoint;
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,6 +6,7 @@
|
||||||
package org.eclipse.cdt.debug.internal.ui.actions;
|
package org.eclipse.cdt.debug.internal.ui.actions;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.debug.core.ICBreakpoint;
|
import org.eclipse.cdt.debug.core.ICBreakpoint;
|
||||||
|
@ -311,6 +312,20 @@ public class CBreakpointPropertiesDialog extends Dialog
|
||||||
{
|
{
|
||||||
public void run( IProgressMonitor monitor ) throws CoreException
|
public void run( IProgressMonitor monitor ) throws CoreException
|
||||||
{
|
{
|
||||||
|
ICBreakpoint breakpoint = getBreakpoint();
|
||||||
|
Iterator changed = changedProperties.iterator();
|
||||||
|
while ( changed.hasNext() )
|
||||||
|
{
|
||||||
|
String property = (String)changed.next();
|
||||||
|
if ( property.equals( CBreakpointPreferenceStore.IGNORE_COUNT ) )
|
||||||
|
{
|
||||||
|
breakpoint.setIgnoreCount( getPreferenceStore().getInt( CBreakpointPreferenceStore.IGNORE_COUNT ) );
|
||||||
|
}
|
||||||
|
else if ( property.equals( CBreakpointPreferenceStore.CONDITION ) )
|
||||||
|
{
|
||||||
|
breakpoint.setCondition( getPreferenceStore().getString( CBreakpointPreferenceStore.CONDITION ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,316 @@
|
||||||
|
/*
|
||||||
|
*(c) Copyright QNX Software Systems Ltd. 2002.
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.eclipse.cdt.debug.internal.ui.actions;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.debug.core.CDebugModel;
|
||||||
|
import org.eclipse.cdt.debug.core.ICLineBreakpoint;
|
||||||
|
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.debug.core.DebugPlugin;
|
||||||
|
import org.eclipse.jface.action.IAction;
|
||||||
|
import org.eclipse.jface.text.IDocument;
|
||||||
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
import org.eclipse.jface.viewers.ISelectionProvider;
|
||||||
|
import org.eclipse.ui.IEditorInput;
|
||||||
|
import org.eclipse.ui.IEditorPart;
|
||||||
|
import org.eclipse.ui.IPartListener;
|
||||||
|
import org.eclipse.ui.IWorkbenchPage;
|
||||||
|
import org.eclipse.ui.IWorkbenchPart;
|
||||||
|
import org.eclipse.ui.IWorkbenchWindow;
|
||||||
|
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
|
||||||
|
import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Action for adding/removing breakpoints at a line in the source file
|
||||||
|
* shown in the active C/C++ Editor.
|
||||||
|
*
|
||||||
|
* @since Sep 3, 2002
|
||||||
|
*/
|
||||||
|
public class ManageBreakpointActionDelegate implements IWorkbenchWindowActionDelegate,
|
||||||
|
IPartListener
|
||||||
|
{
|
||||||
|
private boolean fInitialized = false;
|
||||||
|
private IAction fAction = null;
|
||||||
|
private int fLineNumber;
|
||||||
|
private ITextEditor fTextEditor = null;
|
||||||
|
private IWorkbenchWindow fWorkbenchWindow = null;
|
||||||
|
private IFile fFile = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for ManageBreakpointActionDelegate.
|
||||||
|
*/
|
||||||
|
public ManageBreakpointActionDelegate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
|
||||||
|
*/
|
||||||
|
public void dispose()
|
||||||
|
{
|
||||||
|
getWorkbenchWindow().getPartService().removePartListener( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(IWorkbenchWindow)
|
||||||
|
*/
|
||||||
|
public void init( IWorkbenchWindow window )
|
||||||
|
{
|
||||||
|
setWorkbenchWindow( window );
|
||||||
|
window.getPartService().addPartListener( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IPartListener#partActivated(IWorkbenchPart)
|
||||||
|
*/
|
||||||
|
public void partActivated( IWorkbenchPart part )
|
||||||
|
{
|
||||||
|
if ( part instanceof ITextEditor )
|
||||||
|
{
|
||||||
|
setTextEditor( (ITextEditor)part );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IPartListener#partBroughtToTop(IWorkbenchPart)
|
||||||
|
*/
|
||||||
|
public void partBroughtToTop( IWorkbenchPart part )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IPartListener#partClosed(IWorkbenchPart)
|
||||||
|
*/
|
||||||
|
public void partClosed( IWorkbenchPart part )
|
||||||
|
{
|
||||||
|
if ( part == getTextEditor() )
|
||||||
|
{
|
||||||
|
setTextEditor( null );
|
||||||
|
if ( getAction() != null )
|
||||||
|
{
|
||||||
|
getAction().setEnabled( false );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IPartListener#partDeactivated(IWorkbenchPart)
|
||||||
|
*/
|
||||||
|
public void partDeactivated( IWorkbenchPart part )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IPartListener#partOpened(IWorkbenchPart)
|
||||||
|
*/
|
||||||
|
public void partOpened( IWorkbenchPart part )
|
||||||
|
{
|
||||||
|
if ( part instanceof ITextEditor )
|
||||||
|
{
|
||||||
|
if ( getTextEditor() == null )
|
||||||
|
{
|
||||||
|
setTextEditor( (ITextEditor)part );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IActionDelegate#run(IAction)
|
||||||
|
*/
|
||||||
|
public void run( IAction action )
|
||||||
|
{
|
||||||
|
if ( getTextEditor() != null )
|
||||||
|
{
|
||||||
|
update();
|
||||||
|
manageBreakpoint( getTextEditor().getEditorInput() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void update( ISelection selection )
|
||||||
|
{
|
||||||
|
setEnabledState( getTextEditor() );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void update()
|
||||||
|
{
|
||||||
|
IAction action = getAction();
|
||||||
|
if ( action != null )
|
||||||
|
{
|
||||||
|
if ( getTextEditor() != null )
|
||||||
|
{
|
||||||
|
breakpointExists( getTextEditor().getEditorInput() );
|
||||||
|
}
|
||||||
|
action.setEnabled( getTextEditor() != null && getFile() != null );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
|
||||||
|
*/
|
||||||
|
public void selectionChanged( IAction action, ISelection selection )
|
||||||
|
{
|
||||||
|
if ( !fInitialized )
|
||||||
|
{
|
||||||
|
setAction( action );
|
||||||
|
if ( getWorkbenchWindow() != null )
|
||||||
|
{
|
||||||
|
IWorkbenchPage page = getWorkbenchWindow().getActivePage();
|
||||||
|
if ( page != null )
|
||||||
|
{
|
||||||
|
IEditorPart part = page.getActiveEditor();
|
||||||
|
if ( part instanceof ITextEditor )
|
||||||
|
{
|
||||||
|
setTextEditor( (ITextEditor)part );
|
||||||
|
update( getTextEditor().getSelectionProvider().getSelection() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fInitialized = true;
|
||||||
|
}
|
||||||
|
update( selection );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages a breakpoint.
|
||||||
|
*/
|
||||||
|
protected void manageBreakpoint( IEditorInput editorInput )
|
||||||
|
{
|
||||||
|
ISelectionProvider sp = getTextEditor().getSelectionProvider();
|
||||||
|
if ( sp == null || getFile() == null )
|
||||||
|
{
|
||||||
|
beep();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ISelection selection = sp.getSelection();
|
||||||
|
if ( selection instanceof ITextSelection )
|
||||||
|
{
|
||||||
|
if ( getFile() == null )
|
||||||
|
return;
|
||||||
|
IDocument document = getTextEditor().getDocumentProvider().getDocument( editorInput );
|
||||||
|
BreakpointLocationVerifier bv = new BreakpointLocationVerifier();
|
||||||
|
int lineNumber = bv.getValidBreakpointLocation( document, ((ITextSelection)selection).getStartLine());
|
||||||
|
if ( lineNumber > -1 )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ICLineBreakpoint breakpoint = CDebugModel.lineBreakpointExists( getFile().getLocation().toOSString(), lineNumber );
|
||||||
|
if ( breakpoint != null )
|
||||||
|
{
|
||||||
|
DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( breakpoint, true );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CDebugModel.createLineBreakpoint( getFile(),
|
||||||
|
lineNumber,
|
||||||
|
true,
|
||||||
|
0,
|
||||||
|
"",
|
||||||
|
true );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch( CoreException ce )
|
||||||
|
{
|
||||||
|
CDebugUIPlugin.errorDialog( "Cannot add breakpoint", ce );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if a breakpoint exists on the line of the current selection.
|
||||||
|
*/
|
||||||
|
protected boolean breakpointExists(IEditorInput editorInput)
|
||||||
|
{
|
||||||
|
if ( getFile() != null )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return CDebugModel.lineBreakpointExists( getFile().getLocation().toOSString(), getLineNumber() ) == null;
|
||||||
|
}
|
||||||
|
catch (CoreException ce)
|
||||||
|
{
|
||||||
|
CDebugUIPlugin.log( ce );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IWorkbenchWindow getWorkbenchWindow()
|
||||||
|
{
|
||||||
|
return fWorkbenchWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setWorkbenchWindow( IWorkbenchWindow workbenchWindow )
|
||||||
|
{
|
||||||
|
fWorkbenchWindow = workbenchWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ITextEditor getTextEditor()
|
||||||
|
{
|
||||||
|
return fTextEditor;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setTextEditor( ITextEditor editor )
|
||||||
|
{
|
||||||
|
fTextEditor = editor;
|
||||||
|
IEditorInput input = fTextEditor.getEditorInput();
|
||||||
|
fFile = (IFile)input.getAdapter( IFile.class );
|
||||||
|
setEnabledState( editor );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setEnabledState( ITextEditor editor )
|
||||||
|
{
|
||||||
|
if ( getAction() != null )
|
||||||
|
{
|
||||||
|
getAction().setEnabled( editor != null );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void beep()
|
||||||
|
{
|
||||||
|
if ( CDebugUIPlugin.getActiveWorkbenchShell() != null )
|
||||||
|
{
|
||||||
|
CDebugUIPlugin.getActiveWorkbenchShell().getDisplay().beep();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getLineNumber()
|
||||||
|
{
|
||||||
|
return fLineNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setLineNumber( int lineNumber )
|
||||||
|
{
|
||||||
|
fLineNumber = lineNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IAction getAction()
|
||||||
|
{
|
||||||
|
return fAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setAction( IAction action )
|
||||||
|
{
|
||||||
|
fAction = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IFile getFile()
|
||||||
|
{
|
||||||
|
return fFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setFile( IFile file )
|
||||||
|
{
|
||||||
|
fFile = file;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue