diff --git a/debug/org.eclipse.cdt.debug.ui/.classpath b/debug/org.eclipse.cdt.debug.ui/.classpath index ef2ab8a4103..3ca60357b63 100644 --- a/debug/org.eclipse.cdt.debug.ui/.classpath +++ b/debug/org.eclipse.cdt.debug.ui/.classpath @@ -7,6 +7,7 @@ + diff --git a/debug/org.eclipse.cdt.debug.ui/.project b/debug/org.eclipse.cdt.debug.ui/.project index 2457163a427..3c1535e67bd 100644 --- a/debug/org.eclipse.cdt.debug.ui/.project +++ b/debug/org.eclipse.cdt.debug.ui/.project @@ -3,6 +3,7 @@ org.eclipse.cdt.debug.ui + org.eclipse.cdt.core org.eclipse.cdt.debug.core org.eclipse.cdt.ui org.eclipse.core.boot diff --git a/debug/org.eclipse.cdt.debug.ui/ChangeLog b/debug/org.eclipse.cdt.debug.ui/ChangeLog index b645a198b56..e8f81d6ed0a 100644 --- a/debug/org.eclipse.cdt.debug.ui/ChangeLog +++ b/debug/org.eclipse.cdt.debug.ui/ChangeLog @@ -1,3 +1,14 @@ +2002-11-05 Mikhail Khodjaiants + Implementation of the "Add Global Variables" action of the Expressions view. + Action images: + watch_globals.gif (clcl, dlcl, elcl). + * AddGlobalsActionDelegate.java: implementation. + * plugin.xml: contribution to the Expression view + * plugin.xml: added dependency to org.eclipse.cdt.core + * .classpath: added dependency to org.eclipse.cdt.core + * .project: added dependency to org.eclipse.cdt.core + * plugin.properties: action's label and tooltip text + 2002-11-03 Mikhail Khodjaiants Implementation of the "Format/Decimal" and "Format/Unsigned Decimal" actions of the Memory view. * MemoryFormataction.java diff --git a/debug/org.eclipse.cdt.debug.ui/icons/full/clcl16/watch_globals.gif b/debug/org.eclipse.cdt.debug.ui/icons/full/clcl16/watch_globals.gif new file mode 100644 index 00000000000..30fabfdfa95 Binary files /dev/null and b/debug/org.eclipse.cdt.debug.ui/icons/full/clcl16/watch_globals.gif differ diff --git a/debug/org.eclipse.cdt.debug.ui/icons/full/dlcl16/watch_globals.gif b/debug/org.eclipse.cdt.debug.ui/icons/full/dlcl16/watch_globals.gif new file mode 100644 index 00000000000..797b0e0e7b4 Binary files /dev/null and b/debug/org.eclipse.cdt.debug.ui/icons/full/dlcl16/watch_globals.gif differ diff --git a/debug/org.eclipse.cdt.debug.ui/icons/full/elcl16/watch_globals.gif b/debug/org.eclipse.cdt.debug.ui/icons/full/elcl16/watch_globals.gif new file mode 100644 index 00000000000..dc1a3bce85d Binary files /dev/null and b/debug/org.eclipse.cdt.debug.ui/icons/full/elcl16/watch_globals.gif differ diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.properties b/debug/org.eclipse.cdt.debug.ui/plugin.properties index ac4ad17c59e..ef982a577df 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.properties +++ b/debug/org.eclipse.cdt.debug.ui/plugin.properties @@ -37,4 +37,7 @@ RunToLineAction.label=Run To C/C++ &Line ShowFullPathsAction.label=Show Full Paths ShowFullPathsAction.tooltip=Show Full Paths +AddGlobalsAction.label=Add Global Variables... +AddGlobalsAction.tooltip=Add Global Variables + CDebugActionGroup.name=C/C++ Debug diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml index 093d0d3487a..81d57ab8445 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.xml +++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml @@ -18,6 +18,7 @@ + @@ -238,12 +239,12 @@ + + + + + + + + @@ -420,6 +440,28 @@ tooltip="%ShowFullPathsAction.tooltip"> + + + + + + + + @@ -490,6 +532,9 @@ + + diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddGlobalsActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddGlobalsActionDelegate.java new file mode 100644 index 00000000000..87e1d5c7fb8 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddGlobalsActionDelegate.java @@ -0,0 +1,376 @@ +/* + *(c) Copyright QNX Software Systems Ltd. 2002. + * All Rights Reserved. + * + */ +package org.eclipse.cdt.debug.internal.ui.actions; + +import org.eclipse.cdt.debug.core.CDebugModel; +import org.eclipse.cdt.debug.core.IExecFileInfo; +import org.eclipse.cdt.debug.core.IGlobalVariable; +import org.eclipse.cdt.debug.ui.CDebugUIPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.DebugPlugin; +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.IDebugUIConstants; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IPartListener; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.IViewActionDelegate; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.dialogs.ListSelectionDialog; + +/** + * Enter type comment. + * + * @since: Nov 4, 2002 + */ +public class AddGlobalsActionDelegate implements IViewActionDelegate, + ISelectionListener, + IPartListener +{ + protected class Global + { + private String fName; + private IPath fPath; + + /** + * Constructor for Global. + */ + public Global( String name, IPath path ) + { + fName = name; + fPath = path; + } + + public String getName() + { + return fName; + } + + public IPath getPath() + { + return fPath; + } + + public String toString() + { + String path = ""; + if ( getPath() != null ) + { + path = getPath().toString(); + int index = path.lastIndexOf( '/' ); + if ( index != -1 ) + path = path.substring( index + 1 ); + } + return ( path.length() > 0 ? ( '\'' + path + "\'::" ) : "" ) + getName(); + } + } + + private Global[] fGlobals; + private IViewPart fView = null; + private IAction fAction; + private IStructuredSelection fSelection; + private IStatus fStatus = null; + + /** + * Constructor for AddGlobalsActionDelegate. + */ + public AddGlobalsActionDelegate() + { + super(); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart) + */ + public void init( IViewPart view ) + { + fView = view; + view.getSite().getPage().addPartListener( this ); + view.getSite().getPage().addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this ); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.ISelectionListener#selectionChanged(IWorkbenchPart, ISelection) + */ + public void selectionChanged( IWorkbenchPart part, ISelection selection ) + { + if ( part.getSite().getId().equals( IDebugUIConstants.ID_DEBUG_VIEW ) ) + { + update( getAction(), selection ); + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate#run(IAction) + */ + public void run( IAction action ) + { + final IStructuredSelection selection = getSelection(); + if ( selection != null && selection.size() != 1 ) + return; + BusyIndicator.showWhile( Display.getCurrent(), + new Runnable() + { + public void run() + { + try + { + doAction( selection.getFirstElement() ); + } + catch( DebugException e ) + { + setStatus( e.getStatus() ); + } + } + } ); + if ( getStatus() != null && !getStatus().isOK() ) + { + IWorkbenchWindow window= CDebugUIPlugin.getActiveWorkbenchWindow(); + if ( window != null ) + { + CDebugUIPlugin.errorDialog( getErrorDialogMessage(), getStatus() ); + } + else + { + CDebugUIPlugin.log( getStatus() ); + } + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection) + */ + public void selectionChanged( IAction action, ISelection selection ) + { + setAction( action ); + if ( getView() != null ) + { + update( action, selection ); + } + } + + protected void update( IAction action, ISelection s ) + { + if ( action != null && s instanceof IStructuredSelection ) + { + IStructuredSelection ss = (IStructuredSelection)s; + action.setEnabled( getEnableStateForSelection( ss ) ); + setSelection( ss ); + } + else + { + action.setEnabled( false ); + setSelection( StructuredSelection.EMPTY ); + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IPartListener#partActivated(IWorkbenchPart) + */ + public void partActivated( IWorkbenchPart 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.equals( getView() ) ) + { + dispose(); + } + } + + /* (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 ) + { + } + + protected IViewPart getView() + { + return fView; + } + + protected void setView( IViewPart viewPart ) + { + fView = viewPart; + } + + protected void setAction( IAction action ) + { + fAction = action; + } + + protected IAction getAction() + { + return fAction; + } + + private void setSelection( IStructuredSelection selection ) + { + fSelection = selection; + } + + private IStructuredSelection getSelection() + { + return fSelection; + } + + protected void dispose() + { + if ( getView() != null ) + { + getView().getViewSite().getPage().removeSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this ); + getView().getViewSite().getPage().removePartListener( this ); + } + } + + protected boolean getEnableStateForSelection( IStructuredSelection selection ) + { + if ( selection.size() != 1 ) + { + return false; + } + Object element = selection.getFirstElement(); + return ( element != null && + element instanceof IDebugElement && + ((IDebugElement)element).getDebugTarget().getAdapter( IExecFileInfo.class ) != null ); + } + + private ListSelectionDialog createDialog() + { + return new ListSelectionDialog( getView().getSite().getShell(), + fGlobals, + new IStructuredContentProvider() + { + public void inputChanged( Viewer viewer, Object oldInput, Object newInput ) + { + } + + public void dispose() + { + } + + public Object[] getElements( Object parent ) + { + return getGlobals(); + } + }, + new LabelProvider() + { + public String getText( Object element ) + { + if ( element instanceof Global ) + { + String path = ""; + if ( ((Global)element).getPath() != null ) + { + path = ((Global)element).getPath().toString(); + int index = path.lastIndexOf( '/' ); + if ( index != -1 ) + path = path.substring( index + 1 ); + } + return ( path.length() > 0 ? ( '\'' + path + "\'::" ) : "" ) + ((Global)element).getName(); + } + return null; + } + }, + "Select Variables:" ); + } + + protected Global[] getGlobals() + { + return fGlobals; + } + + protected void doAction( Object element ) throws DebugException + { + if ( getView() == null ) + return; + if ( element != null && element instanceof IDebugElement ) + { + IExecFileInfo info = (IExecFileInfo)((IDebugElement)element).getDebugTarget().getAdapter( IExecFileInfo.class ); + if ( info != null ) + { + IGlobalVariable[] globalVars = (IGlobalVariable[])info.getGlobals(); + fGlobals = new Global[globalVars.length]; + for ( int i = 0; i < globalVars.length; ++i ) + { + fGlobals[i] = new Global( globalVars[i].getName(), globalVars[i].getPath() ); + } + ListSelectionDialog dlg = createDialog(); + if ( dlg.open() == Dialog.OK ) + { + Object[] selections = dlg.getResult(); + for ( int i = 0; i < selections.length; ++i ) + { + createExpression( ((IDebugElement)element).getDebugTarget(), ((Global)selections[i]).toString() ); + } + } + } + } + } + + protected String getStatusMessage() + { + return "Exceptions occurred attempting to add global variables."; + } + + /** + * @see AbstractDebugActionDelegate#getErrorDialogMessage() + */ + protected String getErrorDialogMessage() + { + return "Add global variables failed."; + } + + protected void setStatus( IStatus status ) + { + fStatus = status; + } + + protected IStatus getStatus() + { + return fStatus; + } + + private void createExpression( IDebugTarget target, String text ) throws DebugException + { + IExpression expression = CDebugModel.createExpression( target, text ); + DebugPlugin.getDefault().getExpressionManager().addExpression( expression ); + } +}