mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-05 07:15:39 +02:00
Implementation of expressions.
This commit is contained in:
parent
f45c222418
commit
df4e0dbe8d
9 changed files with 565 additions and 6 deletions
|
@ -12,6 +12,7 @@ import java.util.HashMap;
|
||||||
import org.eclipse.cdt.debug.core.cdi.CDIException;
|
import org.eclipse.cdt.debug.core.cdi.CDIException;
|
||||||
import org.eclipse.cdt.debug.core.cdi.ICDILocation;
|
import org.eclipse.cdt.debug.core.cdi.ICDILocation;
|
||||||
import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpoint;
|
import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpoint;
|
||||||
|
import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression;
|
||||||
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
|
import org.eclipse.cdt.debug.core.cdi.model.ICDITarget;
|
||||||
import org.eclipse.cdt.debug.internal.core.breakpoints.CLineBreakpoint;
|
import org.eclipse.cdt.debug.internal.core.breakpoints.CLineBreakpoint;
|
||||||
import org.eclipse.cdt.debug.internal.core.breakpoints.CWatchpoint;
|
import org.eclipse.cdt.debug.internal.core.breakpoints.CWatchpoint;
|
||||||
|
@ -24,12 +25,15 @@ import org.eclipse.core.resources.IWorkspaceRunnable;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.debug.core.DebugException;
|
import org.eclipse.debug.core.DebugException;
|
||||||
import org.eclipse.debug.core.DebugPlugin;
|
import org.eclipse.debug.core.DebugPlugin;
|
||||||
import org.eclipse.debug.core.IBreakpointManager;
|
import org.eclipse.debug.core.IBreakpointManager;
|
||||||
import org.eclipse.debug.core.ILaunch;
|
import org.eclipse.debug.core.ILaunch;
|
||||||
import org.eclipse.debug.core.model.IBreakpoint;
|
import org.eclipse.debug.core.model.IBreakpoint;
|
||||||
import org.eclipse.debug.core.model.IDebugTarget;
|
import org.eclipse.debug.core.model.IDebugTarget;
|
||||||
|
import org.eclipse.debug.core.model.IExpression;
|
||||||
import org.eclipse.debug.core.model.IProcess;
|
import org.eclipse.debug.core.model.IProcess;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -275,4 +279,24 @@ public class CDebugModel
|
||||||
attributes.put( ICWatchpoint.WRITE, new Boolean( writeAccess ) );
|
attributes.put( ICWatchpoint.WRITE, new Boolean( writeAccess ) );
|
||||||
return new CWatchpoint( resource, attributes, add );
|
return new CWatchpoint( resource, attributes, add );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IExpression createExpression( IDebugTarget target, String text ) throws DebugException
|
||||||
|
{
|
||||||
|
if ( target != null && target instanceof CDebugTarget )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ICDIExpression cdiExpression = ((CDebugTarget)target).getCDISession().getExpressionManager().createExpression( text );
|
||||||
|
}
|
||||||
|
catch( CDIException e )
|
||||||
|
{
|
||||||
|
throw new DebugException( new Status( IStatus.ERROR,
|
||||||
|
getPluginIdentifier(),
|
||||||
|
DebugException.TARGET_REQUEST_FAILED,
|
||||||
|
"Create expression failed.",
|
||||||
|
e ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,10 +59,12 @@ import org.eclipse.debug.core.DebugEvent;
|
||||||
import org.eclipse.debug.core.DebugException;
|
import org.eclipse.debug.core.DebugException;
|
||||||
import org.eclipse.debug.core.DebugPlugin;
|
import org.eclipse.debug.core.DebugPlugin;
|
||||||
import org.eclipse.debug.core.IBreakpointManager;
|
import org.eclipse.debug.core.IBreakpointManager;
|
||||||
|
import org.eclipse.debug.core.IExpressionListener;
|
||||||
import org.eclipse.debug.core.ILaunch;
|
import org.eclipse.debug.core.ILaunch;
|
||||||
import org.eclipse.debug.core.ILaunchListener;
|
import org.eclipse.debug.core.ILaunchListener;
|
||||||
import org.eclipse.debug.core.model.IBreakpoint;
|
import org.eclipse.debug.core.model.IBreakpoint;
|
||||||
import org.eclipse.debug.core.model.IDebugTarget;
|
import org.eclipse.debug.core.model.IDebugTarget;
|
||||||
|
import org.eclipse.debug.core.model.IExpression;
|
||||||
import org.eclipse.debug.core.model.IMemoryBlock;
|
import org.eclipse.debug.core.model.IMemoryBlock;
|
||||||
import org.eclipse.debug.core.model.IProcess;
|
import org.eclipse.debug.core.model.IProcess;
|
||||||
import org.eclipse.debug.core.model.IRegisterGroup;
|
import org.eclipse.debug.core.model.IRegisterGroup;
|
||||||
|
@ -81,6 +83,7 @@ public class CDebugTarget extends CDebugElement
|
||||||
IFormattedMemoryRetrieval,
|
IFormattedMemoryRetrieval,
|
||||||
IState,
|
IState,
|
||||||
ILaunchListener,
|
ILaunchListener,
|
||||||
|
IExpressionListener,
|
||||||
ICExpressionEvaluator
|
ICExpressionEvaluator
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -1656,4 +1659,25 @@ public class CDebugTarget extends CDebugElement
|
||||||
((CRegisterGroup)it.next()).preserve();
|
((CRegisterGroup)it.next()).preserve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.debug.core.IExpressionListener#expressionAdded(IExpression)
|
||||||
|
*/
|
||||||
|
public void expressionAdded( IExpression expression )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.debug.core.IExpressionListener#expressionChanged(IExpression)
|
||||||
|
*/
|
||||||
|
public void expressionChanged( IExpression expression )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.debug.core.IExpressionListener#expressionRemoved(IExpression)
|
||||||
|
*/
|
||||||
|
public void expressionRemoved( IExpression expression )
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
*(c) Copyright QNX Software Systems Ltd. 2002.
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.eclipse.cdt.debug.internal.core.model;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.debug.core.ICValue;
|
||||||
|
import org.eclipse.cdt.debug.core.cdi.CDIException;
|
||||||
|
import org.eclipse.cdt.debug.core.cdi.event.ICDIEvent;
|
||||||
|
import org.eclipse.cdt.debug.core.cdi.event.ICDIEventListener;
|
||||||
|
import org.eclipse.cdt.debug.core.cdi.model.ICDIExpression;
|
||||||
|
import org.eclipse.debug.core.DebugException;
|
||||||
|
import org.eclipse.debug.core.model.IExpression;
|
||||||
|
import org.eclipse.debug.core.model.IValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Enter type comment.
|
||||||
|
*
|
||||||
|
* @since Sep 17, 2002
|
||||||
|
*/
|
||||||
|
public class CExpression extends CVariable
|
||||||
|
implements IExpression
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Constructor for CExpression.
|
||||||
|
* @param target
|
||||||
|
*/
|
||||||
|
public CExpression( CDebugTarget target, ICDIExpression cdiExpression )
|
||||||
|
{
|
||||||
|
super( target, cdiExpression );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.debug.core.model.IExpression#getExpressionText()
|
||||||
|
*/
|
||||||
|
public String getExpressionText()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return getName();
|
||||||
|
}
|
||||||
|
catch( DebugException e )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.debug.core.model.IExpression#getValue()
|
||||||
|
*/
|
||||||
|
public IValue getValue()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return super.getValue();
|
||||||
|
}
|
||||||
|
catch( DebugException e )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dispose()
|
||||||
|
{
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,16 +12,12 @@ import org.eclipse.debug.core.DebugException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Generates variable values.
|
* Generates values for variable and expressions.
|
||||||
*
|
*
|
||||||
* @since Sep 9, 2002
|
* @since Sep 9, 2002
|
||||||
*/
|
*/
|
||||||
public class CValueFactory
|
public class CValueFactory
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Creates the appropriate kind of value, or <code>null</code>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
static public ICValue createValue( CVariable parent, ICDIValue cdiValue ) throws DebugException
|
static public ICValue createValue( CVariable parent, ICDIValue cdiValue ) throws DebugException
|
||||||
{
|
{
|
||||||
return new CValue( parent, cdiValue );
|
return new CValue( parent, cdiValue );
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 909 B |
|
@ -24,4 +24,5 @@ EnableBreakpoint.label=T&oggle Breakpoint
|
||||||
BreakpointProperties.label=Breakpoint P&roperties...
|
BreakpointProperties.label=Breakpoint P&roperties...
|
||||||
ManageBreakpointAction.label=Add/Remove C/C++ Brea&kpoint
|
ManageBreakpointAction.label=Add/Remove C/C++ Brea&kpoint
|
||||||
BreakpointPropertiesAction.label=P&roperties...
|
BreakpointPropertiesAction.label=P&roperties...
|
||||||
ManageWatchpointAction.label=Add C/C++ &Watchpoint
|
ManageWatchpointAction.label=Add C/C++ &Watchpoint...
|
||||||
|
AddExpressionAction.label=Add C/C++ &Expression...
|
||||||
|
|
|
@ -95,6 +95,14 @@
|
||||||
name="cBreakpointGroup">
|
name="cBreakpointGroup">
|
||||||
</separator>
|
</separator>
|
||||||
</menu>
|
</menu>
|
||||||
|
<menu
|
||||||
|
label="%RunMenu.label"
|
||||||
|
path="additions"
|
||||||
|
id="org.eclipse.ui.run">
|
||||||
|
<separator
|
||||||
|
name="cExpressionGroup">
|
||||||
|
</separator>
|
||||||
|
</menu>
|
||||||
<action
|
<action
|
||||||
id="org.eclipse.cdt.debug.ui.internal.actions.RestartActionDelegate"
|
id="org.eclipse.cdt.debug.ui.internal.actions.RestartActionDelegate"
|
||||||
hoverIcon="icons/full/clcl16/restart.gif"
|
hoverIcon="icons/full/clcl16/restart.gif"
|
||||||
|
@ -141,6 +149,20 @@
|
||||||
</pluginState>
|
</pluginState>
|
||||||
</enablement>
|
</enablement>
|
||||||
</action>
|
</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>
|
</actionSet>
|
||||||
</extension>
|
</extension>
|
||||||
<extension
|
<extension
|
||||||
|
|
|
@ -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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue