mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
Implementation of 'Run To Line' action.
This commit is contained in:
parent
5c2a979441
commit
c0691323a6
5 changed files with 244 additions and 5 deletions
|
@ -206,6 +206,14 @@
|
||||||
<viewerContribution
|
<viewerContribution
|
||||||
targetID="#CEditorRulerContext"
|
targetID="#CEditorRulerContext"
|
||||||
id="org.eclipse.cdt.debug.ui.CEditorRulerActions">
|
id="org.eclipse.cdt.debug.ui.CEditorRulerActions">
|
||||||
|
<action
|
||||||
|
label="%RunToLineAction.label"
|
||||||
|
icon="icons/full/clcl16/runtoline_co.gif"
|
||||||
|
helpContextId="run_to_line_action_context"
|
||||||
|
class="org.eclipse.cdt.debug.internal.ui.actions.RunToLineRulerActionDelegate"
|
||||||
|
menubarPath="debug"
|
||||||
|
id="org.eclipse.cdt.debug.internal.ui.actions.RunToLineRulerActionDelegate">
|
||||||
|
</action>
|
||||||
<action
|
<action
|
||||||
label="%BreakpointProperties.label"
|
label="%BreakpointProperties.label"
|
||||||
helpContextId="breakpoint_properties_action_context"
|
helpContextId="breakpoint_properties_action_context"
|
||||||
|
@ -246,13 +254,13 @@
|
||||||
</enablement>
|
</enablement>
|
||||||
</action>
|
</action>
|
||||||
<action
|
<action
|
||||||
menubarPath="additions"
|
|
||||||
label="%RunToLineAction.label"
|
label="%RunToLineAction.label"
|
||||||
icon="icons/full/clcl16/runtoline_co.gif"
|
icon="icons/full/clcl16/runtoline_co.gif"
|
||||||
|
helpContextId="run_to_line_action_context"
|
||||||
class="org.eclipse.cdt.debug.internal.ui.actions.RunToLineActionDelegate"
|
class="org.eclipse.cdt.debug.internal.ui.actions.RunToLineActionDelegate"
|
||||||
|
menubarPath="additions"
|
||||||
enablesFor="1"
|
enablesFor="1"
|
||||||
id="org.eclipse.cdt.debug.internal.ui.actions.RunToLineActionDelegate"
|
id="org.eclipse.cdt.debug.internal.ui.actions.RunToLineActionDelegate">
|
||||||
helpContextId="run_to_line_action_context">
|
|
||||||
<enablement>
|
<enablement>
|
||||||
<pluginState
|
<pluginState
|
||||||
value="activated"
|
value="activated"
|
||||||
|
|
|
@ -28,12 +28,13 @@ public class CBreakpointPropertiesRulerAction extends AbstractBreakpointRulerAct
|
||||||
setTextEditor( editor );
|
setTextEditor( editor );
|
||||||
setText( "Breakpoint &Properties..." );
|
setText( "Breakpoint &Properties..." );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see Action#run()
|
* @see Action#run()
|
||||||
*/
|
*/
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
if (getBreakpoint() != null)
|
if ( getBreakpoint() != null )
|
||||||
{
|
{
|
||||||
Dialog d = new CBreakpointPropertiesDialog( getTextEditor().getEditorSite().getShell(), (ICBreakpoint)getBreakpoint() );
|
Dialog d = new CBreakpointPropertiesDialog( getTextEditor().getEditorSite().getShell(), (ICBreakpoint)getBreakpoint() );
|
||||||
d.open();
|
d.open();
|
||||||
|
|
|
@ -21,10 +21,11 @@ import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
public class ManageBreakpointRulerActionDelegate extends AbstractRulerActionDelegate
|
public class ManageBreakpointRulerActionDelegate extends AbstractRulerActionDelegate
|
||||||
{
|
{
|
||||||
static final private String C_EDITOR_ID = "org.eclipse.cdt.ui.editor.CEditor"; //$NON-NLS-1$
|
static final private String C_EDITOR_ID = "org.eclipse.cdt.ui.editor.CEditor"; //$NON-NLS-1$
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see IEditorActionDelegate#setActiveEditor(IAction, IEditorPart)
|
* @see IEditorActionDelegate#setActiveEditor(IAction, IEditorPart)
|
||||||
*/
|
*/
|
||||||
public void setActiveEditor(IAction callerAction, IEditorPart targetEditor)
|
public void setActiveEditor( IAction callerAction, IEditorPart targetEditor )
|
||||||
{
|
{
|
||||||
if ( targetEditor != null )
|
if ( targetEditor != null )
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,184 @@
|
||||||
|
/*
|
||||||
|
*(c) Copyright QNX Software Systems Ltd. 2002.
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.eclipse.cdt.debug.internal.ui.actions;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.debug.core.IRunToLine;
|
||||||
|
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
|
import org.eclipse.debug.core.DebugException;
|
||||||
|
import org.eclipse.debug.core.model.IDebugElement;
|
||||||
|
import org.eclipse.debug.core.model.IDebugTarget;
|
||||||
|
import org.eclipse.debug.ui.DebugUITools;
|
||||||
|
import org.eclipse.debug.ui.IDebugUIConstants;
|
||||||
|
import org.eclipse.jface.action.Action;
|
||||||
|
import org.eclipse.jface.text.IDocument;
|
||||||
|
import org.eclipse.jface.text.source.IVerticalRulerInfo;
|
||||||
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
|
import org.eclipse.ui.IEditorInput;
|
||||||
|
import org.eclipse.ui.IFileEditorInput;
|
||||||
|
import org.eclipse.ui.INullSelectionListener;
|
||||||
|
import org.eclipse.ui.ISelectionListener;
|
||||||
|
import org.eclipse.ui.IWorkbenchPart;
|
||||||
|
import org.eclipse.ui.texteditor.IDocumentProvider;
|
||||||
|
import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
|
import org.eclipse.ui.texteditor.IUpdate;
|
||||||
|
import sun.security.krb5.internal.crypto.e;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Enter type comment.
|
||||||
|
*
|
||||||
|
* @since Sep 19, 2002
|
||||||
|
*/
|
||||||
|
public class RunToLineRulerAction extends Action
|
||||||
|
implements IUpdate,
|
||||||
|
ISelectionListener,
|
||||||
|
INullSelectionListener
|
||||||
|
{
|
||||||
|
private IVerticalRulerInfo fInfo;
|
||||||
|
private ITextEditor fTextEditor;
|
||||||
|
private IDebugTarget fDebugTarget = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for RunToLineRulerAction.
|
||||||
|
*/
|
||||||
|
public RunToLineRulerAction( IVerticalRulerInfo info, ITextEditor editor )
|
||||||
|
{
|
||||||
|
setInfo( info );
|
||||||
|
setTextEditor( editor );
|
||||||
|
setText( "Run To Line" );
|
||||||
|
initializeDebugTarget();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.texteditor.IUpdate#update()
|
||||||
|
*/
|
||||||
|
public void update()
|
||||||
|
{
|
||||||
|
boolean enabled = false;
|
||||||
|
IResource resource = getResource();
|
||||||
|
int lineNumber = getLineNumber();
|
||||||
|
IDocumentProvider provider = getTextEditor().getDocumentProvider();
|
||||||
|
IDocument doc = provider.getDocument( getTextEditor().getEditorInput() );
|
||||||
|
if ( resource != null && lineNumber <= doc.getNumberOfLines() && lineNumber > 0 )
|
||||||
|
{
|
||||||
|
enabled = ( getDebugTarget() != null && ((IRunToLine)getDebugTarget()).canRunToLine( resource, lineNumber ) );
|
||||||
|
}
|
||||||
|
setEnabled( enabled );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see Action#run()
|
||||||
|
*/
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
runToLine( getResource(), getLineNumber() );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.ISelectionListener#selectionChanged(IWorkbenchPart, ISelection)
|
||||||
|
*/
|
||||||
|
public void selectionChanged( IWorkbenchPart part, ISelection selection )
|
||||||
|
{
|
||||||
|
IDebugTarget target = null;
|
||||||
|
if ( part.getSite().getId().equals( IDebugUIConstants.ID_DEBUG_VIEW ) )
|
||||||
|
{
|
||||||
|
if ( selection != null && selection instanceof IStructuredSelection )
|
||||||
|
{
|
||||||
|
Object element = ((IStructuredSelection)selection).getFirstElement();
|
||||||
|
if ( element != null && element instanceof IDebugElement )
|
||||||
|
{
|
||||||
|
IDebugTarget target1 = ((IDebugElement)element).getDebugTarget();
|
||||||
|
if ( target1 != null && target1 instanceof IRunToLine )
|
||||||
|
{
|
||||||
|
target = target1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setDebugTarget( target );
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void initializeDebugTarget()
|
||||||
|
{
|
||||||
|
setDebugTarget( null );
|
||||||
|
IAdaptable context = DebugUITools.getDebugContext();
|
||||||
|
if ( context != null && context instanceof IDebugElement )
|
||||||
|
{
|
||||||
|
IDebugTarget target = ((IDebugElement)context).getDebugTarget();
|
||||||
|
if ( target != null && target instanceof IRunToLine )
|
||||||
|
{
|
||||||
|
setDebugTarget( target );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setDebugTarget( IDebugTarget target )
|
||||||
|
{
|
||||||
|
fDebugTarget = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IDebugTarget getDebugTarget()
|
||||||
|
{
|
||||||
|
return fDebugTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IVerticalRulerInfo getInfo()
|
||||||
|
{
|
||||||
|
return fInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setInfo( IVerticalRulerInfo info )
|
||||||
|
{
|
||||||
|
fInfo = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ITextEditor getTextEditor()
|
||||||
|
{
|
||||||
|
return fTextEditor;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setTextEditor( ITextEditor textEditor )
|
||||||
|
{
|
||||||
|
fTextEditor = textEditor;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IResource getResource()
|
||||||
|
{
|
||||||
|
IEditorInput input = getTextEditor().getEditorInput();
|
||||||
|
if ( input != null && input instanceof IFileEditorInput )
|
||||||
|
{
|
||||||
|
return ((IFileEditorInput)input).getFile();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getLineNumber()
|
||||||
|
{
|
||||||
|
return getInfo().getLineOfLastMouseButtonActivity() + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void runToLine( IResource resource, int lineNumber )
|
||||||
|
{
|
||||||
|
if ( !((IRunToLine)getDebugTarget()).canRunToLine( resource, lineNumber ) )
|
||||||
|
{
|
||||||
|
getTextEditor().getSite().getShell().getDisplay().beep();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
((IRunToLine)getDebugTarget()).runToLine( resource, lineNumber );
|
||||||
|
}
|
||||||
|
catch( DebugException e )
|
||||||
|
{
|
||||||
|
CDebugUIPlugin.errorDialog( e.getMessage(), e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
*(c) Copyright QNX Software Systems Ltd. 2002.
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Enter type comment.
|
||||||
|
*
|
||||||
|
* @since Sep 19, 2002
|
||||||
|
*/
|
||||||
|
public class RunToLineRulerActionDelegate extends AbstractRulerActionDelegate
|
||||||
|
{
|
||||||
|
static final private String C_EDITOR_ID = "org.eclipse.cdt.ui.editor.CEditor"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see IEditorActionDelegate#setActiveEditor(IAction, IEditorPart)
|
||||||
|
*/
|
||||||
|
public void setActiveEditor( IAction callerAction, IEditorPart targetEditor )
|
||||||
|
{
|
||||||
|
if ( targetEditor != null )
|
||||||
|
{
|
||||||
|
String id = targetEditor.getSite().getId();
|
||||||
|
if ( !id.equals( C_EDITOR_ID ) )
|
||||||
|
targetEditor = null;
|
||||||
|
}
|
||||||
|
super.setActiveEditor( callerAction, targetEditor );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.texteditor.AbstractRulerActionDelegate#createAction(ITextEditor, IVerticalRulerInfo)
|
||||||
|
*/
|
||||||
|
public IAction createAction( ITextEditor editor, IVerticalRulerInfo rulerInfo )
|
||||||
|
{
|
||||||
|
return new RunToLineRulerAction( rulerInfo, editor );
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue