Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikhail Khodjaiants2004-04-11 21:23:36 +0000
committerMikhail Khodjaiants2004-04-11 21:23:36 +0000
commita1f408bc47711f6c627d82a46eaa1a0f17c57103 (patch)
treebf9689417cdfc519f6e5e58d39a6f53ed47a4a72 /debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug
parentead83ba6f7cbc5b7a1a0bd4689bd49c0e424141c (diff)
downloadorg.eclipse.cdt-a1f408bc47711f6c627d82a46eaa1a0f17c57103.tar.gz
org.eclipse.cdt-a1f408bc47711f6c627d82a46eaa1a0f17c57103.tar.xz
org.eclipse.cdt-a1f408bc47711f6c627d82a46eaa1a0f17c57103.zip
Implementation of the "Run To Line" retargettable action.
Diffstat (limited to 'debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug')
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties4
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineActionDelegate.java192
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineAdapter.java23
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineRulerAction.java173
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineRulerActionDelegate.java45
5 files changed, 66 insertions, 371 deletions
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties
index 2c31d1312c8..63ca5ef8c57 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties
@@ -10,3 +10,7 @@ SignalPropertiesDialog.Stop_label_1=Suspend the program when this signal happens
SignalPropertiesDialog.Pass_label_1=Pass this signal to the program.
SignalPropertiesActionDelegate.Unable_to_change_signal_properties_1=Unable to change signal properties.
SignalPropertiesActionDelegate.Operation_failed_1=Operation failed.
+RunToLineActionDelegate.Error_1=Error
+RunToLineActionDelegate.Operation_failed_1=Operation failed.
+RunToLineAdapter.Empty_editor_1=Empty editor
+RunToLineAdapter.Missing_document_1=Missing document
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineActionDelegate.java
index b0c4c14b30e..da0352fd4c1 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineActionDelegate.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineActionDelegate.java
@@ -1,135 +1,89 @@
/*
- *(c) Copyright QNX Software Systems Ltd. 2002.
- * All Rights Reserved.
- *
+ * (c) Copyright QNX Software Systems Ltd. 2002. All Rights Reserved.
+ *
*/
package org.eclipse.cdt.debug.internal.ui.actions;
-import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.debug.core.model.IRunToAddress;
import org.eclipse.cdt.debug.core.model.IRunToLine;
-import org.eclipse.cdt.debug.core.sourcelookup.IDisassemblyStorage;
-import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.IDebugTarget;
+import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.IDebugUIConstants;
+import org.eclipse.debug.ui.actions.IRunToLineTarget;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.text.ITextSelection;
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.IStorageEditorInput;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.texteditor.ITextEditor;
/**
- *
- * Enter type comment.
- *
- * @since Sep 19, 2002
+ * Run to line action of C editor popup menu.
*/
-public class RunToLineActionDelegate extends AbstractEditorActionDelegate
-{
+public class RunToLineActionDelegate extends AbstractEditorActionDelegate {
+
+ IRunToLineTarget fRunToLineTarget;
+
/**
* Constructor for RunToLineActionDelegate.
*/
- public RunToLineActionDelegate()
- {
+ public RunToLineActionDelegate() {
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.ui.IActionDelegate#run(IAction)
*/
- public void run( IAction action )
- {
- if ( getTargetPart() != null && getTargetPart() instanceof ITextEditor )
- {
- IEditorInput input = ((ITextEditor)getTargetPart()).getEditorInput();
- if ( input != null && input instanceof IFileEditorInput )
- {
- IFile file = ((IFileEditorInput)input).getFile();
- if ( file != null )
- {
- ITextSelection selection = (ITextSelection)((ITextEditor)getTargetPart()).getSelectionProvider().getSelection();
- int lineNumber = selection.getStartLine() + 1;
- runToLine( file, lineNumber );
- }
- }
- else if ( input != null && input instanceof IStorageEditorInput )
- {
- try
- {
- IStorage storage = ((IStorageEditorInput)input).getStorage();
- if ( storage instanceof FileStorage )
- {
- IPath path = storage.getFullPath();
- if ( path != null )
- {
- ITextSelection selection = (ITextSelection)((ITextEditor)getTargetPart()).getSelectionProvider().getSelection();
- int lineNumber = selection.getStartLine() + 1;
- runToLine( path.lastSegment(), lineNumber );
- }
- }
- else if ( storage != null && storage.getAdapter( IDisassemblyStorage.class ) != null )
- {
- IDisassemblyStorage disassemblyStorage = (IDisassemblyStorage)storage.getAdapter( IDisassemblyStorage.class );
- ITextSelection selection = (ITextSelection)((ITextEditor)getTargetPart()).getSelectionProvider().getSelection();
- int lineNumber = selection.getStartLine();
- long address = disassemblyStorage.getAddress( lineNumber );
- if ( address > 0 )
- runToAddress( address );
- }
+ public void run( IAction action ) {
+ if ( getTargetPart() instanceof ITextEditor ) {
+ ITextSelection selection = (ITextSelection)((ITextEditor)getTargetPart()).getSelectionProvider().getSelection();
+ if ( getRunToLineTarget() != null ) {
+ try {
+ getRunToLineTarget().runToLine( getTargetPart(), selection, getDebugTarget() );
}
- catch( CoreException e )
- {
+ catch( CoreException e ) {
+ DebugUIPlugin.errorDialog( getTargetPart().getSite().getShell(), ActionMessages.getString( "RunToLineActionDelegate.Error_1" ), ActionMessages.getString( "RunToLineActionDelegate.Operation_failed_1" ), e.getStatus() ); //$NON-NLS-1$ //$NON-NLS-2$
}
}
+
}
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.cdt.debug.internal.ui.actions.AbstractEditorActionDelegate#initializeDebugTarget()
*/
- protected void initializeDebugTarget()
- {
+ protected void initializeDebugTarget() {
setDebugTarget( null );
IAdaptable context = DebugUITools.getDebugContext();
- if ( context != null && context instanceof IDebugElement )
- {
+ if ( context != null && context instanceof IDebugElement ) {
IDebugTarget target = ((IDebugElement)context).getDebugTarget();
- if ( target != null &&
- ( target instanceof IRunToLine || target instanceof IRunToAddress ) )
- {
+ if ( target != null && (target instanceof IRunToLine || target instanceof IRunToAddress) ) {
setDebugTarget( target );
- }
+ }
}
}
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.ISelectionListener#selectionChanged(IWorkbenchPart, ISelection)
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.ISelectionListener#selectionChanged(IWorkbenchPart,
+ * ISelection)
*/
- public void selectionChanged( IWorkbenchPart part, ISelection selection )
- {
+ public void selectionChanged( IWorkbenchPart part, ISelection selection ) {
IDebugTarget target = null;
- if ( part != null && part.getSite().getId().equals( IDebugUIConstants.ID_DEBUG_VIEW ) )
- {
- if ( selection instanceof IStructuredSelection )
- {
+ if ( part != null && part.getSite().getId().equals( IDebugUIConstants.ID_DEBUG_VIEW ) ) {
+ if ( selection instanceof IStructuredSelection ) {
Object element = ((IStructuredSelection)selection).getFirstElement();
- if ( element != null && element instanceof IDebugElement )
- {
+ if ( element != null && element instanceof IDebugElement ) {
IDebugTarget target1 = ((IDebugElement)element).getDebugTarget();
- if ( target1 != null &&
- ( target1 instanceof IRunToLine || target1 instanceof IRunToAddress ) )
- {
+ if ( target1 != null && (target1 instanceof IRunToLine || target1 instanceof IRunToAddress) ) {
target = target1;
}
}
@@ -139,66 +93,10 @@ public class RunToLineActionDelegate extends AbstractEditorActionDelegate
}
}
- protected void runToLine( IFile file, int lineNumber )
- {
- IRunToLine target = (IRunToLine)getDebugTarget().getAdapter( IRunToLine.class );
- if ( target != null )
- {
- if ( !target.canRunToLine( file, lineNumber ) )
- {
- getTargetPart().getSite().getShell().getDisplay().beep();
- return;
- }
- try
- {
- target.runToLine( file, lineNumber );
- }
- catch( DebugException e )
- {
- CDebugUIPlugin.errorDialog( e.getMessage(), e );
- }
- }
- }
-
- protected void runToLine( String fileName, int lineNumber )
- {
- IRunToLine target = (IRunToLine)getDebugTarget().getAdapter( IRunToLine.class );
- if ( target != null )
- {
- if ( !target.canRunToLine( fileName, lineNumber ) )
- {
- getTargetPart().getSite().getShell().getDisplay().beep();
- return;
- }
- try
- {
- target.runToLine( fileName, lineNumber );
- }
- catch( DebugException e )
- {
- CDebugUIPlugin.errorDialog( e.getMessage(), e );
- }
- }
- }
-
- protected void runToAddress( long address )
- {
- IRunToAddress target = (IRunToAddress)getDebugTarget().getAdapter( IRunToAddress.class );
- if ( target != null )
- {
- if ( !target.canRunToAddress( address ) )
- {
- getTargetPart().getSite().getShell().getDisplay().beep();
- return;
- }
- try
- {
- target.runToAddress( address );
- }
- catch( DebugException e )
- {
- CDebugUIPlugin.errorDialog( e.getMessage(), e );
- }
+ private IRunToLineTarget getRunToLineTarget() {
+ if ( fRunToLineTarget == null ) {
+ fRunToLineTarget = new RunToLineAdapter();
}
+ return fRunToLineTarget;
}
-}
+} \ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineAdapter.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineAdapter.java
index 413c31e025d..a4af1410a23 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineAdapter.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineAdapter.java
@@ -11,10 +11,11 @@
package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.cdt.debug.core.CDIDebugModel;
+import org.eclipse.cdt.debug.core.model.IRunToLine;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.cdt.debug.ui.ICDebugUIConstants;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.model.IDebugElement;
@@ -26,6 +27,7 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.texteditor.ITextEditor;
@@ -45,18 +47,24 @@ public class RunToLineAdapter implements IRunToLineTarget {
IEditorInput input = editorPart.getEditorInput();
String errorMessage = null;
if ( input == null ) {
- errorMessage = "Empty editor";
+ errorMessage = ActionMessages.getString( "RunToLineAdapter.Empty_editor_1" ); //$NON-NLS-1$
}
else {
final ITextEditor textEditor = (ITextEditor)editorPart;
final IDocument document = textEditor.getDocumentProvider().getDocument( input );
if ( document == null ) {
- errorMessage = "Missing document";
+ errorMessage = ActionMessages.getString( "RunToLineAdapter.Missing_document_1" ); //$NON-NLS-1$
}
else {
- IFile file = getFile( input );
+ String fileName = getFileName( input );
ITextSelection textSelection = (ITextSelection)selection;
int lineNumber = textSelection.getStartLine() + 1;
+ if ( target instanceof IAdaptable ) {
+ IRunToLine runToLine = (IRunToLine)((IAdaptable)target).getAdapter( IRunToLine.class );
+ if ( runToLine != null && runToLine.canRunToLine( fileName, lineNumber ) )
+ runToLine.runToLine( fileName, lineNumber );
+ }
+ return;
}
}
throw new CoreException( new Status( IStatus.ERROR, CDebugUIPlugin.getUniqueIdentifier(), ICDebugUIConstants.INTERNAL_ERROR, errorMessage, null ) );
@@ -72,9 +80,12 @@ public class RunToLineAdapter implements IRunToLineTarget {
return target instanceof IDebugElement && ((IDebugElement)target).getModelIdentifier().equals( CDIDebugModel.getPluginIdentifier() );
}
- private IFile getFile( IEditorInput input ) {
+ private String getFileName( IEditorInput input ) throws CoreException {
if ( input instanceof IFileEditorInput ) {
- return ((IFileEditorInput)input).getFile();
+ return ((IFileEditorInput)input).getFile().getName();
+ }
+ if ( input instanceof IStorageEditorInput ) {
+ return ((IStorageEditorInput)input).getStorage().getName();
}
return 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
deleted file mode 100644
index 22abd4bae07..00000000000
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineRulerAction.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- *(c) Copyright QNX Software Systems Ltd. 2002.
- * All Rights Reserved.
- *
- */
-package org.eclipse.cdt.debug.internal.ui.actions;
-
-import org.eclipse.cdt.debug.core.model.IRunToLine;
-import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.debug.core.DebugException;
-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;
-
-/**
- *
- * Enter type comment.
- *
- * @since Sep 19, 2002
- */
-public class RunToLineRulerAction extends Action
- implements IUpdate,
- ISelectionListener,
- INullSelectionListener
-{
- private IVerticalRulerInfo fInfo;
- private ITextEditor fTextEditor;
- private IRunToLine fTarget = null;
-
- /**
- * Constructor for RunToLineRulerAction.
- */
- public RunToLineRulerAction( IVerticalRulerInfo info, ITextEditor editor )
- {
- setInfo( info );
- setTextEditor( editor );
- setText( CDebugUIPlugin.getResourceString("internal.ui.actions.RunToLineRulerAction.Run_To_Line") ); //$NON-NLS-1$
- initializeTarget();
- update();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.texteditor.IUpdate#update()
- */
- public void update()
- {
- boolean enabled = false;
- IFile file = getFile();
- int lineNumber = getLineNumber();
- IDocumentProvider provider = getTextEditor().getDocumentProvider();
- IDocument doc = provider.getDocument( getTextEditor().getEditorInput() );
- if ( file != null && lineNumber <= doc.getNumberOfLines() && lineNumber > 0 )
- {
- enabled = ( getTarget() != null && getTarget().canRunToLine( file, lineNumber ) );
- }
- setEnabled( enabled );
- }
-
- /**
- * @see Action#run()
- */
- public void run()
- {
- runToLine( getFile(), getLineNumber() );
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.ISelectionListener#selectionChanged(IWorkbenchPart, ISelection)
- */
- public void selectionChanged( IWorkbenchPart part, ISelection selection )
- {
- IRunToLine 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 IRunToLine )
- {
- target = (IRunToLine)element;
- }
- }
- setTarget( target );
- update();
- }
- }
-
- protected void initializeTarget()
- {
- setTarget( null );
- IAdaptable context = DebugUITools.getDebugContext();
- if ( context != null && context instanceof IRunToLine )
- {
- setTarget( (IRunToLine)context );
- }
- }
-
- protected void setTarget( IRunToLine target )
- {
- fTarget = target;
- }
-
- protected IRunToLine getTarget()
- {
- return fTarget;
- }
-
- 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 IFile getFile()
- {
- 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( IFile file, int lineNumber )
- {
- if ( !getTarget().canRunToLine( file, lineNumber ) )
- {
- getTextEditor().getSite().getShell().getDisplay().beep();
- return;
- }
- try
- {
- getTarget().runToLine( file, 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
deleted file mode 100644
index ac619e67e3d..00000000000
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RunToLineRulerActionDelegate.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- *(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 );
- }
-}

Back to the top