diff options
author | Mikhail Khodjaiants | 2002-09-19 21:12:37 +0000 |
---|---|---|
committer | Mikhail Khodjaiants | 2002-09-19 21:12:37 +0000 |
commit | c0691323a6cdcb133f4a179287cf20564ee304e2 (patch) | |
tree | ec7e6c210aa3bb1fde3476d4c5cc2958d24d4934 /debug | |
parent | 5c2a9794410fd652d7d639d21d05c6a911f45119 (diff) | |
download | org.eclipse.cdt-c0691323a6cdcb133f4a179287cf20564ee304e2.tar.gz org.eclipse.cdt-c0691323a6cdcb133f4a179287cf20564ee304e2.tar.xz org.eclipse.cdt-c0691323a6cdcb133f4a179287cf20564ee304e2.zip |
Implementation of 'Run To Line' action.
Diffstat (limited to 'debug')
5 files changed, 244 insertions, 5 deletions
diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml index 4775d2e9bc2..4fdbc54d2f8 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.xml +++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml @@ -207,6 +207,14 @@ targetID="#CEditorRulerContext" 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 label="%BreakpointProperties.label" helpContextId="breakpoint_properties_action_context" class="org.eclipse.cdt.debug.internal.ui.actions.CBreakpointPropertiesRulerActionDelegate" @@ -246,13 +254,13 @@ </enablement> </action> <action - menubarPath="additions" label="%RunToLineAction.label" icon="icons/full/clcl16/runtoline_co.gif" + helpContextId="run_to_line_action_context" class="org.eclipse.cdt.debug.internal.ui.actions.RunToLineActionDelegate" + menubarPath="additions" enablesFor="1" - id="org.eclipse.cdt.debug.internal.ui.actions.RunToLineActionDelegate" - helpContextId="run_to_line_action_context"> + id="org.eclipse.cdt.debug.internal.ui.actions.RunToLineActionDelegate"> <enablement> <pluginState value="activated" 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 7fd83dd6153..e90df7e0828 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 @@ -28,12 +28,13 @@ public class CBreakpointPropertiesRulerAction extends AbstractBreakpointRulerAct setTextEditor( editor ); setText( "Breakpoint &Properties..." ); } + /** * @see Action#run() */ public void run() { - if (getBreakpoint() != null) + if ( getBreakpoint() != null ) { Dialog d = new CBreakpointPropertiesDialog( getTextEditor().getEditorSite().getShell(), (ICBreakpoint)getBreakpoint() ); d.open(); diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ManageBreakpointRulerActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ManageBreakpointRulerActionDelegate.java index acf1f6d036a..f1509deac47 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ManageBreakpointRulerActionDelegate.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ManageBreakpointRulerActionDelegate.java @@ -21,10 +21,11 @@ import org.eclipse.ui.texteditor.ITextEditor; public class ManageBreakpointRulerActionDelegate 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) + public void setActiveEditor( IAction callerAction, IEditorPart targetEditor ) { if ( targetEditor != null ) { diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineRulerAction.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineRulerAction.java new file mode 100644 index 00000000000..352b1d31cba --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineRulerAction.java @@ -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 ); + } + } +} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineRulerActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineRulerActionDelegate.java new file mode 100644 index 00000000000..ac619e67e3d --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineRulerActionDelegate.java @@ -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 ); + } +} |