diff options
author | Mikhail Khodjaiants | 2002-09-18 15:04:01 +0000 |
---|---|---|
committer | Mikhail Khodjaiants | 2002-09-18 15:04:01 +0000 |
commit | df4e0dbe8deeb37240e13c4f272a3eeb0a8541a9 (patch) | |
tree | 9a4fb4f6472089b5b2749f904ee2eb50a173ab98 /debug/org.eclipse.cdt.debug.ui | |
parent | f45c2224185cc9cf83e8e2f47cb1607f98918fb4 (diff) | |
download | org.eclipse.cdt-df4e0dbe8deeb37240e13c4f272a3eeb0a8541a9.tar.gz org.eclipse.cdt-df4e0dbe8deeb37240e13c4f272a3eeb0a8541a9.tar.xz org.eclipse.cdt-df4e0dbe8deeb37240e13c4f272a3eeb0a8541a9.zip |
Implementation of expressions.
Diffstat (limited to 'debug/org.eclipse.cdt.debug.ui')
5 files changed, 447 insertions, 1 deletions
diff --git a/debug/org.eclipse.cdt.debug.ui/icons/full/obj16/expression_obj.gif b/debug/org.eclipse.cdt.debug.ui/icons/full/obj16/expression_obj.gif Binary files differnew file mode 100644 index 00000000000..870df5c473a --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/icons/full/obj16/expression_obj.gif diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.properties b/debug/org.eclipse.cdt.debug.ui/plugin.properties index 6f7c42e970e..4fcf1584e41 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.properties +++ b/debug/org.eclipse.cdt.debug.ui/plugin.properties @@ -24,4 +24,5 @@ EnableBreakpoint.label=T&oggle Breakpoint BreakpointProperties.label=Breakpoint P&roperties... ManageBreakpointAction.label=Add/Remove C/C++ Brea&kpoint BreakpointPropertiesAction.label=P&roperties... -ManageWatchpointAction.label=Add C/C++ &Watchpoint +ManageWatchpointAction.label=Add C/C++ &Watchpoint... +AddExpressionAction.label=Add C/C++ &Expression... diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml index 8bbe13f6595..0da2046c5c3 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.xml +++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml @@ -95,6 +95,14 @@ name="cBreakpointGroup"> </separator> </menu> + <menu + label="%RunMenu.label" + path="additions" + id="org.eclipse.ui.run"> + <separator + name="cExpressionGroup"> + </separator> + </menu> <action id="org.eclipse.cdt.debug.ui.internal.actions.RestartActionDelegate" hoverIcon="icons/full/clcl16/restart.gif" @@ -141,6 +149,20 @@ </pluginState> </enablement> </action> + <action + label="%AddExpressionAction.label" + icon="icons/full/obj16/expression_obj.gif" + helpContextId="add_expression_action_context" + class="org.eclipse.cdt.debug.internal.ui.actions.AddExpressionActionDelegate" + menubarPath="org.eclipse.ui.run/cExpressionGroup" + id="org.eclipse.cdt.debug.internal.ui.actions.AddExpressionActionDelegate"> + <enablement> + <pluginState + value="activated" + id="org.eclipse.cdt.debug.ui"> + </pluginState> + </enablement> + </action> </actionSet> </extension> <extension diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddExpressionActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddExpressionActionDelegate.java new file mode 100644 index 00000000000..2a188d4590a --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddExpressionActionDelegate.java @@ -0,0 +1,283 @@ +/* + *(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.CDebugModel; +import org.eclipse.cdt.debug.core.ICExpressionEvaluator; +import org.eclipse.cdt.debug.ui.CDebugUIPlugin; +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.core.model.IExpression; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorActionDelegate; +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; + +/** + * + * Enter type comment. + * + * @since Sep 17, 2002 + */ +public class AddExpressionActionDelegate implements IWorkbenchWindowActionDelegate, + IEditorActionDelegate, + IPartListener +{ + private IAction fAction; + private IWorkbenchWindow fWorkbenchWindow; + private IWorkbenchPart fTargetPart; + private IEditorPart fTargetEditor; + private IDebugTarget fDebugTarget; + + /** + * Constructor for AddExpressionActionDelegate. + */ + public AddExpressionActionDelegate() + { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() + */ + public void dispose() + { + IWorkbenchWindow win = getWorkbenchWindow(); + if ( win != null ) + { + win.getPartService().removePartListener( this ); + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(IWorkbenchWindow) + */ + public void init( IWorkbenchWindow window ) + { + setWorkbenchWindow( window ); + IWorkbenchPage page = window.getActivePage(); + if ( page != null ) + { + setTargetPart( page.getActivePart() ); + } + window.getPartService().addPartListener( this ); + IAdaptable context = DebugUITools.getDebugContext(); + if ( context != null ) + { + IDebugTarget target = ((IDebugElement)context.getAdapter( IDebugElement.class )).getDebugTarget(); + if ( target != null ) + { + ICExpressionEvaluator ee = (ICExpressionEvaluator)target.getAdapter( ICExpressionEvaluator.class ); + if ( ee != null && ee.canEvaluate() ) + { + setDebugTarget( target ); + } + } + } + update(); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener#partActivated(IWorkbenchPart) + */ + public void partActivated( IWorkbenchPart part ) + { + setTargetPart( 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 == getTargetPart() ) + { + setTargetPart( null ); + } + } + + /* (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 ) + { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate#run(IAction) + */ + public void run( IAction action ) + { + String text = getSelectedText(); + ExpressionDialog dlg = new ExpressionDialog( getShell(), text ); + if ( dlg.open() != Dialog.OK ) + return; + createExpression( dlg.getExpression() ); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection) + */ + public void selectionChanged( IAction action, ISelection selection ) + { + setAction( action ); + update(); + } + + protected IAction getAction() + { + return fAction; + } + + protected void setAction( IAction action ) + { + fAction = action; + } + + protected IWorkbenchWindow getWorkbenchWindow() + { + return fWorkbenchWindow; + } + + protected void setWorkbenchWindow( IWorkbenchWindow workbenchWindow ) + { + fWorkbenchWindow = workbenchWindow; + } + + protected String getSelectedText() + { + ISelection selection = getTargetSelection(); + if ( selection != null && selection instanceof ITextSelection ) + { + return ((ITextSelection)selection).getText().trim(); + } + return ""; + } + + protected void update() + { + IAction action = getAction(); + if ( action != null ) + { + action.setEnabled( getDebugTarget() != null && getTargetPart() != null ); + } + } + + protected void setEnabledState( ITextEditor editor ) + { + if ( getAction() != null ) + { + getAction().setEnabled( editor != null ); + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(IAction, IEditorPart) + */ + public void setActiveEditor( IAction action, IEditorPart targetEditor ) + { + setAction( action ); + setTargetPart( targetEditor ); + update(); + } + + protected IWorkbenchPart getTargetPart() + { + return fTargetPart; + } + + protected void setTargetPart( IWorkbenchPart part ) + { + fTargetPart = part; + } + + protected Shell getShell() + { + if ( getTargetPart() != null ) + { + return getTargetPart().getSite().getShell(); + } + else + { + return CDebugUIPlugin.getActiveWorkbenchShell(); + } + } + + protected ISelection getTargetSelection() + { + IWorkbenchPart part = getTargetPart(); + if ( part != null ) + { + ISelectionProvider provider = part.getSite().getSelectionProvider(); + if ( provider != null ) + { + return provider.getSelection(); + } + } + return null; + } + + protected IDebugTarget getDebugTarget() + { + return fDebugTarget; + } + + protected void setDebugTarget( IDebugTarget target ) + { + fDebugTarget = target; + } + + private void createExpression( final String text ) + { + final Display display = CDebugUIPlugin.getStandardDisplay(); + if ( display.isDisposed() ) + { + return; + } + display.asyncExec( new Runnable() + { + public void run() + { + try + { + CDebugModel.createExpression( getDebugTarget(), text ); + } + 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/ExpressionDialog.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ExpressionDialog.java new file mode 100644 index 00000000000..8b2a15c8855 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ExpressionDialog.java @@ -0,0 +1,140 @@ +/* + *(c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + * + */ +package org.eclipse.cdt.debug.internal.ui.actions; + +import org.eclipse.debug.internal.ui.DebugPluginImages; +import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +/** + * + * Enter type comment. + * + * @since Sep 17, 2002 + */ +public class ExpressionDialog extends Dialog +{ + private Button fBtnOk = null; + private Button fBtnCancel = null; + private Text fTextExpression; + + private String fExpression = ""; + + /** + * Constructor for ExpressionDialog. + * @param parentShell + */ + public ExpressionDialog( Shell parentShell, String expression ) + { + super( parentShell ); + if ( expression != null ) + fExpression = expression; + } + + protected void configureShell( Shell shell ) + { + super.configureShell( shell ); + shell.setText( "Add Expression" ); + shell.setImage( DebugPluginImages.getImage( IDebugUIConstants.IMG_OBJS_EXPRESSION ) ); + } + + protected Control createContents( Composite parent ) + { + Control control = super.createContents( parent ); + setOkButtonState(); + return control; + } + + protected Control createDialogArea( Composite parent ) + { + Composite composite = new Composite( parent, SWT.NONE ); + composite.setLayout( new GridLayout() ); + ((GridLayout)composite.getLayout()).marginWidth = 10; + composite.setLayoutData( new GridData( GridData.FILL_BOTH ) ); + createDataWidgets( composite ); + initializeDataWidgets(); + return composite; + } + + protected void createButtonsForButtonBar( Composite parent ) + { + fBtnOk = createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true ); + fBtnCancel = createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false ); + } + + private void createDataWidgets( Composite parent ) + { + fTextExpression = createExpressionText( parent ); + } + + private void initializeDataWidgets() + { + fTextExpression.setText( fExpression ); + setOkButtonState(); + } + + private Text createExpressionText( Composite parent ) + { + Label label = new Label( parent, SWT.RIGHT ); + label.setText( "Expression to add:" ); + final Text text = new Text( parent, SWT.BORDER ); + GridData gridData = new GridData( GridData.FILL_HORIZONTAL ); + gridData.widthHint = 300; + text.setLayoutData( gridData ); + addModifyListener( text ); + return text; + } + + private void setOkButtonState() + { + if ( fBtnOk == null ) + return; + fBtnOk.setEnabled( fTextExpression.getText().trim().length() > 0 ); + } + + private void storeData() + { + fExpression = fTextExpression.getText().trim(); + } + + private void addModifyListener( Text text ) + { + text.addModifyListener( + new ModifyListener() + { + public void modifyText( ModifyEvent e ) + { + setOkButtonState(); + } + } ); + } + + public String getExpression() + { + return fExpression; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#okPressed() + */ + protected void okPressed() + { + storeData(); + super.okPressed(); + } +} |