1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-03 14:25:37 +02:00

Display global variables in the Variables view.

This commit is contained in:
Mikhail Khodjaiants 2004-05-27 21:53:39 +00:00
parent 742d1b1514
commit f7b0d8de3b
25 changed files with 729 additions and 300 deletions

View file

@ -1,3 +1,18 @@
2004-05-27 Mikhail Khodjaiants
Display global variables in the Variables view.
* CDIDebugModel.java
* ICGlobalVariableManager.java: new
* IGlobalVariable.java: removed
* ICGlobalVariable.java
* IExecFileInfo.java
* IGlobalVariableDescriptor.java: new
* CGlobalVariableManager.java: new
* CDebugTarget.java
* CGlobalVariable.java
* CRegister.java
* CStackFrame.java
* CVariable.java
2004-05-20 Mikhail Khodjaiants
Removed dependencies on the compatibility plugin and replaced deprecated classes and methods.
Warning cleanup.

View file

@ -19,14 +19,17 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject;
import org.eclipse.cdt.debug.core.model.ICAddressBreakpoint;
import org.eclipse.cdt.debug.core.model.ICBreakpoint;
import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint;
import org.eclipse.cdt.debug.core.model.ICGlobalVariable;
import org.eclipse.cdt.debug.core.model.ICLineBreakpoint;
import org.eclipse.cdt.debug.core.model.ICWatchpoint;
import org.eclipse.cdt.debug.core.model.IGlobalVariableDescriptor;
import org.eclipse.cdt.debug.internal.core.breakpoints.CAddressBreakpoint;
import org.eclipse.cdt.debug.internal.core.breakpoints.CFunctionBreakpoint;
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.model.CDebugTarget;
import org.eclipse.cdt.debug.internal.core.model.CExpression;
import org.eclipse.cdt.debug.internal.core.model.CGlobalVariable;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
@ -389,4 +392,19 @@ public class CDIDebugModel {
}
return null;
}
public static ICGlobalVariable createGlobalVariable( IDebugTarget target, IGlobalVariableDescriptor info ) throws DebugException {
if ( target != null && target instanceof CDebugTarget ) {
ICDIVariableObject vo = null;
try {
vo = ((CDebugTarget)target).getCDISession().getVariableManager().getGlobalVariableObject( info.getPath().lastSegment(), null, info.getName() );
ICDIVariable cdiVariable = ((CDebugTarget)target).getCDISession().getVariableManager().createVariable( vo );
return new CGlobalVariable( (CDebugTarget)target, cdiVariable );
}
catch( CDIException e ) {
throw new DebugException( new Status( IStatus.ERROR, getPluginIdentifier(), DebugException.TARGET_REQUEST_FAILED, (vo != null) ? vo.getName() + ": " + e.getMessage() : e.getMessage(), null ) ); //$NON-NLS-1$
}
}
return null;
}
}

View file

@ -0,0 +1,48 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.core;
import org.eclipse.cdt.debug.core.model.ICGlobalVariable;
import org.eclipse.cdt.debug.core.model.IGlobalVariableDescriptor;
import org.eclipse.debug.core.DebugException;
/**
* Manages the collection of global variables added to a debug target.
*/
public interface ICGlobalVariableManager {
/**
* Registers with this manager the global variables specified by given descriptors.
*
* @param descriptors the descriptors of global variables to register with this manager
* @throws DebugException
*/
public void addGlobals( IGlobalVariableDescriptor[] descriptors ) throws DebugException;
/**
* Removes specified global variables from this manager.
*
* @param globals global variables to remove
*/
public void removeGlobals( ICGlobalVariable[] globals );
/**
* Removes all global variables from this manager.
*/
public void removeAllGlobals();
/**
* Returns the array of the global variables descriptors registered with this manager.
*
* @return the array of the global variables descriptors registered with this manager
*/
public IGlobalVariableDescriptor[] getDescriptors();
}

View file

@ -0,0 +1,18 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.core.model;
/**
* Represents a global C/C++ variable.
*/
public interface ICGlobalVariable extends ICVariable {
public void dispose();
}

View file

@ -22,5 +22,5 @@ public interface IExecFileInfo {
public boolean isLittleEndian();
public IGlobalVariable[] getGlobals() throws DebugException;
public IGlobalVariableDescriptor[] getGlobals() throws DebugException;
}

View file

@ -12,7 +12,7 @@ import org.eclipse.core.runtime.IPath;
*
* @since: Nov 4, 2002
*/
public interface IGlobalVariable
public interface IGlobalVariableDescriptor
{
String getName();
IPath getPath();

View file

@ -0,0 +1,124 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.internal.core;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import org.eclipse.cdt.debug.core.CDIDebugModel;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.ICGlobalVariableManager;
import org.eclipse.cdt.debug.core.model.ICGlobalVariable;
import org.eclipse.cdt.debug.core.model.IGlobalVariableDescriptor;
import org.eclipse.cdt.debug.internal.core.model.CDebugTarget;
import org.eclipse.cdt.debug.internal.core.model.CVariable;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
/**
* Manages all global variables registered with a debug target.
*/
public class CGlobalVariableManager implements ICGlobalVariableManager {
private CDebugTarget fDebugTarget;
private ArrayList fGlobals = new ArrayList( 10 );
/**
* Constructor for CGlobalVariableManager.
*/
public CGlobalVariableManager( CDebugTarget target ) {
super();
setDebugTarget( target );
}
protected CDebugTarget getDebugTarget() {
return fDebugTarget;
}
private void setDebugTarget( CDebugTarget debugTarget ) {
fDebugTarget = debugTarget;
}
public ICGlobalVariable[] getGlobals() {
return (ICGlobalVariable[])fGlobals.toArray( new ICGlobalVariable[fGlobals.size()] );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.ICGlobalVariableManager#addGlobals(IGlobalVariableDescriptor[])
*/
public void addGlobals( IGlobalVariableDescriptor[] descriptors ) throws DebugException {
MultiStatus ms = new MultiStatus( CDebugCorePlugin.getUniqueIdentifier(), 0, "", null ); //$NON-NLS-1$
ArrayList globals = new ArrayList( descriptors.length );
for ( int i = 0; i < descriptors.length; ++i ) {
try {
globals.add( CDIDebugModel.createGlobalVariable( getDebugTarget(), descriptors[i] ) );
}
catch( DebugException e ) {
ms.add( e.getStatus() );
}
}
if ( globals.size() > 0 ) {
synchronized( fGlobals ) {
fGlobals.addAll( globals );
}
getDebugTarget().fireChangeEvent( DebugEvent.CONTENT );
}
if ( !ms.isOK() ) {
throw new DebugException( ms );
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.ICGlobalVariableManager#removeGlobals(ICGlobalVariable[])
*/
public void removeGlobals( ICGlobalVariable[] globals ) {
synchronized( fGlobals ) {
fGlobals.removeAll( Arrays.asList( globals ) );
}
for ( int i = 0; i < globals.length; ++i ) {
globals[i].dispose();
}
getDebugTarget().fireChangeEvent( DebugEvent.CONTENT );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.ICGlobalVariableManager#removeAllGlobals()
*/
public void removeAllGlobals() {
ICGlobalVariable[] globals = new ICGlobalVariable[0];
synchronized( fGlobals ) {
globals = (ICGlobalVariable[])fGlobals.toArray( new ICGlobalVariable[fGlobals.size()] );
fGlobals.clear();
}
for ( int i = 0; i < globals.length; ++i ) {
((CVariable)globals[i]).dispose();
}
getDebugTarget().fireChangeEvent( DebugEvent.CONTENT );
}
public void dispose() {
Iterator it = fGlobals.iterator();
while( it.hasNext() ) {
((ICGlobalVariable)it.next()).dispose();
}
fGlobals.clear();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.ICGlobalVariableManager#getDescriptors()
*/
public IGlobalVariableDescriptor[] getDescriptors() {
// TODO Auto-generated method stub
return null;
}
}

View file

@ -20,6 +20,7 @@ import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.CDebugModel;
import org.eclipse.cdt.debug.core.CDebugUtils;
import org.eclipse.cdt.debug.core.ICGlobalVariableManager;
import org.eclipse.cdt.debug.core.ICMemoryManager;
import org.eclipse.cdt.debug.core.ICRegisterManager;
import org.eclipse.cdt.debug.core.ICSharedLibraryManager;
@ -66,7 +67,7 @@ import org.eclipse.cdt.debug.core.model.ICSignal;
import org.eclipse.cdt.debug.core.model.IDebuggerProcessSupport;
import org.eclipse.cdt.debug.core.model.IDisassembly;
import org.eclipse.cdt.debug.core.model.IExecFileInfo;
import org.eclipse.cdt.debug.core.model.IGlobalVariable;
import org.eclipse.cdt.debug.core.model.IGlobalVariableDescriptor;
import org.eclipse.cdt.debug.core.model.IJumpToAddress;
import org.eclipse.cdt.debug.core.model.IJumpToLine;
import org.eclipse.cdt.debug.core.model.IRunToAddress;
@ -75,6 +76,7 @@ import org.eclipse.cdt.debug.core.model.IState;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
import org.eclipse.cdt.debug.internal.core.CBreakpointManager;
import org.eclipse.cdt.debug.internal.core.CExpressionTarget;
import org.eclipse.cdt.debug.internal.core.CGlobalVariableManager;
import org.eclipse.cdt.debug.internal.core.CMemoryManager;
import org.eclipse.cdt.debug.internal.core.CRegisterManager;
import org.eclipse.cdt.debug.internal.core.CSharedLibraryManager;
@ -250,6 +252,8 @@ public class CDebugTarget extends CDebugElement
private CExpressionTarget fExpressionTarget;
private CGlobalVariableManager fGlobalVariableManager;
/**
* The suspension thread.
*/
@ -302,6 +306,7 @@ public class CDebugTarget extends CDebugElement
setSignalManager( new CSignalManager( this ) );
setRegisterManager( new CRegisterManager( this ) );
setBreakpointManager( new CBreakpointManager( this ) );
setGlobalVariableManager( new CGlobalVariableManager( this ) );
initialize();
DebugPlugin.getDefault().getLaunchManager().addLaunchListener( this );
DebugPlugin.getDefault().getExpressionManager().addExpressionListener( this );
@ -997,6 +1002,8 @@ public class CDebugTarget extends CDebugElement
return getRegisterManager();
if ( adapter.equals( CExpressionTarget.class ) )
return getExpressionTarget();
if ( adapter.equals( ICGlobalVariableManager.class ) )
return getGlobalVariableManager();
if ( adapter.equals( ICDISession.class ) )
return getCDISession();
return super.getAdapter( adapter );
@ -1226,6 +1233,7 @@ public class CDebugTarget extends CDebugElement
DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener( this );
DebugPlugin.getDefault().getExpressionManager().removeExpressionListener( this );
DebugPlugin.getDefault().getLaunchManager().removeLaunchListener( this );
disposeGlobalVariableManager();
disposeMemoryManager();
disposeSharedLibraryManager();
disposeSignalManager();
@ -1988,7 +1996,7 @@ public class CDebugTarget extends CDebugElement
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.IExecFileInfo#getGlobals()
*/
public IGlobalVariable[] getGlobals() throws DebugException
public IGlobalVariableDescriptor[] getGlobals() throws DebugException
{
ArrayList list = new ArrayList();
if ( getExecFile() != null && CoreModel.getDefault().isBinary( getExecFile() ) )
@ -1999,7 +2007,7 @@ public class CDebugTarget extends CDebugElement
list.addAll( getCFileGlobals( (IParent)cFile ) );
}
}
return (IGlobalVariable[])list.toArray( new IGlobalVariable[list.size()] );
return (IGlobalVariableDescriptor[])list.toArray( new IGlobalVariableDescriptor[list.size()] );
}
private List getCFileGlobals( IParent file ) throws DebugException
@ -2027,9 +2035,9 @@ public class CDebugTarget extends CDebugElement
return list;
}
private IGlobalVariable createGlobalVariable( final org.eclipse.cdt.core.model.IVariable var )
private IGlobalVariableDescriptor createGlobalVariable( final org.eclipse.cdt.core.model.IVariable var )
{
return new IGlobalVariable()
return new IGlobalVariableDescriptor()
{
public String getName()
{
@ -2084,6 +2092,10 @@ public class CDebugTarget extends CDebugElement
fRegisterManager.dispose();
}
protected void disposeGlobalVariableManager() {
fGlobalVariableManager.dispose();
}
/**
* @see org.eclipse.cdt.debug.core.model.IRunToAddress#canRunToAddress(long)
*/
@ -2488,4 +2500,12 @@ public class CDebugTarget extends CDebugElement
}
return fExpressionTarget;
}
protected CGlobalVariableManager getGlobalVariableManager() {
return fGlobalVariableManager;
}
private void setGlobalVariableManager( CGlobalVariableManager globalVariableManager ) {
fGlobalVariableManager = globalVariableManager;
}
}

View file

@ -8,6 +8,7 @@ import org.eclipse.cdt.debug.core.cdi.model.ICDIObject;
import org.eclipse.cdt.debug.core.cdi.model.ICDIValue;
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariable;
import org.eclipse.cdt.debug.core.cdi.model.type.ICDIArrayValue;
import org.eclipse.cdt.debug.core.model.ICGlobalVariable;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IValue;
@ -17,7 +18,7 @@ import org.eclipse.debug.core.model.IValue;
*
* @since: Oct 2, 2002
*/
public class CGlobalVariable extends CModificationVariable
public class CGlobalVariable extends CModificationVariable implements ICGlobalVariable
{
/**
* Constructor for CGlobalVariable.
@ -37,6 +38,8 @@ public class CGlobalVariable extends CModificationVariable
*/
public IValue getValue() throws DebugException
{
if ( !isEnabled() )
return fDisabledValue;
if ( fValue == null )
{
ICDIValue cdiValue = getCurrentValue();
@ -90,4 +93,25 @@ public class CGlobalVariable extends CModificationVariable
}
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.internal.core.model.CVariable#dispose()
*/
public void dispose() {
if ( getShadow() != null )
getShadow().dispose();
try {
getCDISession().getVariableManager().destroyVariable( getCDIVariable() );
}
catch( CDIException e ) {
}
super.dispose();
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#canEnableDisable()
*/
public boolean canEnableDisable() {
return true;
}
}

View file

@ -69,12 +69,4 @@ public class CRegister extends CGlobalVariable implements IRegister
{
return true;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.model.ICVariable#canEnableDisable()
*/
public boolean canEnableDisable()
{
return false;
}
}

View file

@ -22,6 +22,7 @@ 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.ICDIStackFrame;
import org.eclipse.cdt.debug.core.cdi.model.ICDIVariableObject;
import org.eclipse.cdt.debug.core.model.ICGlobalVariable;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
import org.eclipse.cdt.debug.core.model.IRestart;
import org.eclipse.cdt.debug.core.model.IResumeWithoutSignal;
@ -29,6 +30,7 @@ import org.eclipse.cdt.debug.core.model.IRunToAddress;
import org.eclipse.cdt.debug.core.model.IRunToLine;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
import org.eclipse.cdt.debug.internal.core.CExpressionTarget;
import org.eclipse.cdt.debug.internal.core.CGlobalVariableManager;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IRegisterGroup;
@ -95,8 +97,12 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart
* @see org.eclipse.debug.core.model.IStackFrame#getVariables()
*/
public IVariable[] getVariables() throws DebugException {
List list = getVariables0();
return (IVariable[])list.toArray( new IVariable[list.size()] );
ICGlobalVariable[] globals = getGlobals();
List vars = getVariables0();
List all = new ArrayList( globals.length + vars.size() );
all.addAll( Arrays.asList( globals ) );
all.addAll( vars );
return (IVariable[])all.toArray( new IVariable[all.size()] );
}
protected synchronized List getVariables0() throws DebugException {
@ -712,4 +718,12 @@ public class CStackFrame extends CDebugElement implements ICStackFrame, IRestart
CExpressionTarget target = (CExpressionTarget)getDebugTarget().getAdapter( CExpressionTarget.class );
return (target != null) ? target.evaluateExpression( expression ) : null;
}
private ICGlobalVariable[] getGlobals() {
CGlobalVariableManager gvm = ((CDebugTarget)getDebugTarget()).getGlobalVariableManager();
if ( gvm != null ) {
return gvm.getGlobals();
}
return new ICGlobalVariable[0];
}
}

View file

@ -350,7 +350,7 @@ public abstract class CVariable extends CDebugElement
* Temporary solution to avoid NPE in VariablesView.
* This is fixed in the Eclipse 2.1.1 Maintenance Build.
*/
static private IValue fDisabledValue = new IValue()
static protected IValue fDisabledValue = new IValue()
{
public String getReferenceTypeName() throws DebugException
{
@ -559,7 +559,7 @@ public abstract class CVariable extends CDebugElement
return ( fValue instanceof CValue ) ? ((CValue)fValue).getUnderlyingValue() : null;
}
protected void dispose()
public void dispose()
{
if ( fValue != null )
{
@ -807,7 +807,7 @@ public abstract class CVariable extends CDebugElement
return ( fOriginal != null ) ? fOriginal.getCDIVariable() : null;
}
private InternalVariable getShadow()
protected InternalVariable getShadow()
{
return fShadow;
}

View file

@ -1,3 +1,18 @@
2004-05-27 Mikhail Khodjaiants
Display global variables in the Variables view.
* CDebugImages.java
* CDTDebugModelPresentation.java
* AddGlobalsActionDelegate.java
* RemoveAllGlobalsActionDelegate.java: new
* RemoveGlobalsActionDelegate.java: new
* plugin.properties
* plugin.xml
* icons/full/dlcl16/rem_all_co.gif: new
* icons/full/dlcl16/rem_co.gif: new
* icons/full/elcl16/rem_all_co.gif: new
* icons/full/elcl16/rem_co.gif: new
* icons/full/ovr16/global_ovr.gif: new
2004-05-25 Mikhail Khodjaiants
New instructuion pointer images for the Disassembly view.
* icons/full/obj16/inst_ptr_top.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 B

View file

@ -48,6 +48,10 @@ ShowFullPathsAction.tooltip=Show Full Paths
AddGlobalsAction.label=Add Global Variables...
AddGlobalsAction.tooltip=Add Global Variables
RemoveGlobalsAction.label=Remove Global Variables
RemoveGlobalsAction.tooltip=Remove Selected Global Variables
RemoveAllGlobalsAction.label=Remove All Global Variables
RemoveAllGlobalsAction.tooltip=Remove All Global Variables
CVariableFormatMenu.label=Format
HexVariableFormatAction.label=Hexadecimal

View file

@ -409,25 +409,6 @@
targetID="org.eclipse.debug.ui.BreakpointView"
id="org.eclipse.cdt.debug.ui.breakpointview.popupMenu">
</viewerContribution>
<viewerContribution
targetID="org.eclipse.debug.ui.ExpressionView"
id="org.eclipse.debug.ui.expressionView.popupMenu">
<action
label="%AddGlobalsAction.label"
icon="icons/full/clcl16/watch_globals.gif"
helpContextId="add_globals_action_context"
class="org.eclipse.cdt.debug.internal.ui.actions.AddGlobalsActionDelegate"
menubarPath="expressionGroup"
enablesFor="1"
id="org.eclipse.cdt.debug.internal.ui.actions.AddGlobalsActionDelegate">
<enablement>
<pluginState
value="activated"
id="org.eclipse.cdt.debug.ui">
</pluginState>
</enablement>
</action>
</viewerContribution>
<viewerContribution
targetID="#ASMEditorRulerContext"
id="org.eclipse.cdt.debug.ui.AsmEditorRulerActions">
@ -752,7 +733,7 @@
helpContextId="restore_default_type_action_context"
tooltip="%RestoreDefaultTypeAction.tooltip"
class="org.eclipse.cdt.debug.internal.ui.actions.RestoreDefaultTypeActionDelegate"
menubarPath="additions"
menubarPath="variableGroup"
enablesFor="1"
id="org.eclipse.cdt.debug.internal.ui.actions.RestoreDefaultTypeActionDelegate">
<enablement>
@ -768,7 +749,7 @@
helpContextId="cast_to_type_action_context"
tooltip="%CastToTypeAction.tooltip"
class="org.eclipse.cdt.debug.internal.ui.actions.CastToTypeActionDelegate"
menubarPath="additions"
menubarPath="variableGroup"
enablesFor="1"
id="org.eclipse.cdt.debug.internal.ui.actions.CastToTypeActionDelegate">
<enablement>
@ -784,7 +765,7 @@
helpContextId="cast_to_array_action_context"
tooltip="%CastToArrayAction.tooltip"
class="org.eclipse.cdt.debug.internal.ui.actions.CastToArrayActionDelegate"
menubarPath="additions"
menubarPath="variableGroup"
enablesFor="1"
id="org.eclipse.cdt.debug.internal.ui.actions.CastToArrayActionDelegate">
<enablement>
@ -818,6 +799,50 @@
<viewerContribution
targetID="org.eclipse.debug.ui.VariableView"
id="org.eclipse.debug.ui.variablesView.popupMenu">
<action
helpContextId="remove_all_globals_action_context"
enablesFor="*"
label="%RemoveAllGlobalsAction.label"
tooltip="%RemoveAllGlobalsAction.tooltip"
icon="icons/full/elcl16/rem_all_co.gif"
class="org.eclipse.cdt.debug.internal.ui.actions.RemoveAllGlobalsActionDelegate"
menubarPath="additions"
id="org.eclipse.cdt.debug.internal.ui.actions.RemoveAllGlobalsActionDelegate">
<enablement>
<pluginState
value="activated"
id="org.eclipse.cdt.debug.ui"/>
</enablement>
</action>
<action
helpContextId="remove_globals_action_context"
enablesFor="+"
label="%RemoveGlobalsAction.label"
tooltip="%RemoveGlobalsAction.tooltip"
icon="icons/full/elcl16/rem_co.gif"
class="org.eclipse.cdt.debug.internal.ui.actions.RemoveGlobalsActionDelegate"
menubarPath="additions"
id="org.eclipse.cdt.debug.internal.ui.actions.RemoveGlobalsActionDelegate">
<enablement>
<pluginState
value="activated"
id="org.eclipse.cdt.debug.ui"/>
</enablement>
</action>
<action
helpContextId="add_globals_action_context"
enablesFor="1"
label="%AddGlobalsAction.label"
class="org.eclipse.cdt.debug.internal.ui.actions.AddGlobalsActionDelegate"
icon="icons/full/clcl16/watch_globals.gif"
menubarPath="additions"
id="org.eclipse.cdt.debug.internal.ui.actions.AddGlobalsActionDelegate">
<enablement>
<pluginState
value="activated"
id="org.eclipse.cdt.debug.ui"/>
</enablement>
</action>
<action
label="%DisableVariablesAction.label"
icon="icons/full/clcl16/disabled_co.gif"
@ -935,24 +960,57 @@
</action>
</viewContribution>
<viewContribution
targetID="org.eclipse.debug.ui.ExpressionView"
id="org.eclipse.debug.ui.expressionsView.toolbar">
targetID="org.eclipse.debug.ui.VariableView"
id="org.eclipse.debug.ui.variablesView.toolbar">
<action
id="org.eclipse.cdt.debug.internal.ui.actions.AddGlobalsActionDelegate"
toolbarPath="expressionGroup"
hoverIcon="icons/full/clcl16/watch_globals.gif"
class="org.eclipse.cdt.debug.internal.ui.actions.AddGlobalsActionDelegate"
disabledIcon="icons/full/dlcl16/watch_globals.gif"
enablesFor="1"
icon="icons/full/elcl16/watch_globals.gif"
helpContextId="add_globals_action_context"
label="%AddGlobalsAction.label"
tooltip="%AddGlobalsAction.tooltip">
helpContextId="remove_all_globals_action_context"
disabledIcon="icons/full/dlcl16/rem_all_co.gif"
hoverIcon="icons/full/elcl16/rem_all_co.gif"
enablesFor="*"
toolbarPath="additions"
label="%RemoveAllGlobalsAction.label"
tooltip="%RemoveAllGlobalsAction.tooltip"
icon="icons/full/elcl16/rem_all_co.gif"
class="org.eclipse.cdt.debug.internal.ui.actions.RemoveAllGlobalsActionDelegate"
id="org.eclipse.cdt.debug.internal.ui.actions.RemoveAllGlobalsActionDelegate">
<enablement>
<pluginState
value="activated"
id="org.eclipse.cdt.debug.ui">
</pluginState>
id="org.eclipse.cdt.debug.ui"/>
</enablement>
</action>
<action
helpContextId="remove_globals_action_context"
disabledIcon="icons/full/dlcl16/rem_co.gif"
hoverIcon="icons/full/elcl16/rem_co.gif"
enablesFor="+"
toolbarPath="additions"
label="%RemoveGlobalsAction.label"
tooltip="%RemoveGlobalsAction.tooltip"
icon="icons/full/elcl16/rem_co.gif"
class="org.eclipse.cdt.debug.internal.ui.actions.RemoveGlobalsActionDelegate"
id="org.eclipse.cdt.debug.internal.ui.actions.RemoveGlobalsActionDelegate">
<enablement>
<pluginState
value="activated"
id="org.eclipse.cdt.debug.ui"/>
</enablement>
</action>
<action
helpContextId="add_globals_action_context"
disabledIcon="icons/full/dlcl16/watch_globals.gif"
hoverIcon="icons/full/clcl16/watch_globals.gif"
enablesFor="1"
toolbarPath="additions"
label="%AddGlobalsAction.label"
tooltip="%AddGlobalsAction.tooltip"
icon="icons/full/elcl16/watch_globals.gif"
class="org.eclipse.cdt.debug.internal.ui.actions.AddGlobalsActionDelegate"
id="org.eclipse.cdt.debug.internal.ui.actions.AddGlobalsActionDelegate">
<enablement>
<pluginState
value="activated"
id="org.eclipse.cdt.debug.ui"/>
</enablement>
</action>
</viewContribution>

View file

@ -23,6 +23,7 @@ import org.eclipse.cdt.debug.core.model.ICBreakpoint;
import org.eclipse.cdt.debug.core.model.ICDebugElementErrorStatus;
import org.eclipse.cdt.debug.core.model.ICDebugTargetType;
import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint;
import org.eclipse.cdt.debug.core.model.ICGlobalVariable;
import org.eclipse.cdt.debug.core.model.ICLineBreakpoint;
import org.eclipse.cdt.debug.core.model.ICSharedLibrary;
import org.eclipse.cdt.debug.core.model.ICStackFrame;
@ -219,6 +220,8 @@ public class CDTDebugModelPresentation extends LabelProvider
overlays[OverlayImageDescriptor.BOTTOM_LEFT] = CDebugImages.DESC_OVRS_ERROR;
if ( element instanceof ICVariable && ((ICVariable)element).isArgument() )
overlays[OverlayImageDescriptor.TOP_RIGHT] = CDebugImages.DESC_OVRS_ARGUMENT;
if ( element instanceof ICGlobalVariable && !(element instanceof IRegister) )
overlays[OverlayImageDescriptor.TOP_RIGHT] = CDebugImages.DESC_OVRS_GLOBAL;
return fImageCache.getImageFor( new OverlayImageDescriptor( baseImage, overlays ) );
}

View file

@ -62,6 +62,7 @@ public class CDebugImages
public static final String IMG_OVRS_SYMBOLS = NAME_PREFIX + "symbols_ovr.gif"; //$NON-NLS-1$
public static final String IMG_OVRS_VARIABLE_CASTED = NAME_PREFIX + "casttype_ovr.gif"; //$NON-NLS-1$
public static final String IMG_OVRS_ARGUMENT = NAME_PREFIX + "argument_ovr.gif"; //$NON-NLS-1$
public static final String IMG_OVRS_GLOBAL = NAME_PREFIX + "global_ovr.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_BREAKPOINT_ENABLED = NAME_PREFIX + "brkp_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_BREAKPOINT_DISABLED = NAME_PREFIX + "brkpd_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_ADDRESS_BREAKPOINT_ENABLED = NAME_PREFIX + "addrbrkp_obj.gif"; //$NON-NLS-1$
@ -137,6 +138,7 @@ public class CDebugImages
public static final ImageDescriptor DESC_OVRS_SYMBOLS = createManaged( T_OVR, IMG_OVRS_SYMBOLS );
public static final ImageDescriptor DESC_OVRS_VARIABLE_CASTED = createManaged( T_OVR, IMG_OVRS_VARIABLE_CASTED );
public static final ImageDescriptor DESC_OVRS_ARGUMENT = createManaged( T_OVR, IMG_OVRS_ARGUMENT );
public static final ImageDescriptor DESC_OVRS_GLOBAL = createManaged( T_OVR, IMG_OVRS_GLOBAL );
public static final ImageDescriptor DESC_OBJS_BREAKPOINT_ENABLED = createManaged( T_OBJ, IMG_OBJS_BREAKPOINT_ENABLED );
public static final ImageDescriptor DESC_OBJS_BREAKPOINT_DISABLED = createManaged( T_OBJ, IMG_OBJS_BREAKPOINT_DISABLED );
public static final ImageDescriptor DESC_OBJS_WATCHPOINT_ENABLED = createManaged( T_OBJ, IMG_OBJS_WATCHPOINT_ENABLED );

View file

@ -1,23 +1,24 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.CDebugModel;
import java.util.Arrays;
import java.util.List;
import org.eclipse.cdt.debug.core.ICGlobalVariableManager;
import org.eclipse.cdt.debug.core.model.IExecFileInfo;
import org.eclipse.cdt.debug.core.model.IGlobalVariable;
import org.eclipse.cdt.debug.core.model.IGlobalVariableDescriptor;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
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.DebugUITools;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jface.action.IAction;
@ -40,354 +41,256 @@ import org.eclipse.ui.actions.ActionDelegate;
import org.eclipse.ui.dialogs.ListSelectionDialog;
/**
* Enter type comment.
*
* @since: Nov 4, 2002
* A delegate for the "Add Globals" action.
*/
public class AddGlobalsActionDelegate extends ActionDelegate
implements IViewActionDelegate,
ISelectionListener,
IPartListener
{
protected class Global
{
private String fName;
private IPath fPath;
public class AddGlobalsActionDelegate extends ActionDelegate implements IViewActionDelegate, ISelectionListener, IPartListener {
/**
* Constructor for Global.
*/
public Global( String name, IPath path )
{
fName = name;
fPath = path;
}
private IGlobalVariableDescriptor[] fGlobals;
public String getName()
{
return fName;
}
public IPath getPath()
{
return fPath;
}
}
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)
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
*/
public void init( IViewPart view )
{
public void init( IViewPart view ) {
fView = view;
view.getSite().getPage().addPartListener( this );
view.getSite().getPage().addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this );
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.ISelectionListener#selectionChanged(IWorkbenchPart, ISelection)
*/
public void selectionChanged( IWorkbenchPart part, ISelection selection )
{
if ( part != null && part.getSite().getId().equals( IDebugUIConstants.ID_DEBUG_VIEW ) )
{
if ( selection instanceof IStructuredSelection )
{
public void selectionChanged( IWorkbenchPart part, ISelection selection ) {
if ( part != null && part.getSite().getId().equals( IDebugUIConstants.ID_DEBUG_VIEW ) ) {
if ( selection instanceof IStructuredSelection ) {
setSelection( (IStructuredSelection)selection );
}
else
{
else {
setSelection( null );
}
update( getAction() );
}
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IActionDelegate#run(IAction)
*/
public void run( IAction action )
{
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() );
setStatus( null );
}
catch( DebugException e )
{
setStatus( e.getStatus() );
}
}
} );
if ( getStatus() != null && !getStatus().isOK() )
{
IWorkbenchWindow window= CDebugUIPlugin.getActiveWorkbenchWindow();
if ( window != null )
{
BusyIndicator.showWhile( Display.getCurrent(), new Runnable() {
public void run() {
try {
doAction( selection.getFirstElement() );
setStatus( null );
}
catch( DebugException e ) {
setStatus( e.getStatus() );
}
}
} );
if ( getStatus() != null && !getStatus().isOK() ) {
IWorkbenchWindow window = CDebugUIPlugin.getActiveWorkbenchWindow();
if ( window != null ) {
CDebugUIPlugin.errorDialog( getErrorDialogMessage(), getStatus() );
}
else
{
}
else {
CDebugUIPlugin.log( getStatus() );
}
}
}
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
*/
public void selectionChanged( IAction action, ISelection selection )
{
public void selectionChanged( IAction action, ISelection selection ) {
setAction( action );
if ( getView() != null )
{
if ( getView() != null ) {
update( action );
}
}
protected void update( IAction action )
{
if ( action != null )
{
protected void update( IAction action ) {
if ( action != null ) {
action.setEnabled( getEnableStateForSelection( getSelection() ) );
}
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IPartListener#partActivated(IWorkbenchPart)
*/
public void partActivated( IWorkbenchPart part )
{
public void partActivated( IWorkbenchPart part ) {
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IPartListener#partBroughtToTop(IWorkbenchPart)
*/
public void partBroughtToTop( IWorkbenchPart part )
{
public void partBroughtToTop( IWorkbenchPart part ) {
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IPartListener#partClosed(IWorkbenchPart)
*/
public void partClosed( IWorkbenchPart part )
{
if ( part.equals( getView() ) )
{
public void partClosed( IWorkbenchPart part ) {
if ( part.equals( getView() ) ) {
dispose();
}
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IPartListener#partDeactivated(IWorkbenchPart)
*/
public void partDeactivated( IWorkbenchPart part )
{
public void partDeactivated( IWorkbenchPart part ) {
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IPartListener#partOpened(IWorkbenchPart)
*/
public void partOpened( IWorkbenchPart part )
{
public void partOpened( IWorkbenchPart part ) {
}
protected IViewPart getView()
{
protected IViewPart getView() {
return fView;
}
protected void setView( IViewPart viewPart )
{
protected void setView( IViewPart viewPart ) {
fView = viewPart;
}
protected void setAction( IAction action )
{
protected void setAction( IAction action ) {
fAction = action;
}
protected IAction getAction()
{
protected IAction getAction() {
return fAction;
}
private void setSelection( IStructuredSelection selection )
{
private void setSelection( IStructuredSelection selection ) {
fSelection = selection;
}
private IStructuredSelection getSelection()
{
private IStructuredSelection getSelection() {
return fSelection;
}
public void dispose()
{
if ( getView() != null )
{
public 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 == null || selection.size() != 1 )
{
protected boolean getEnableStateForSelection( IStructuredSelection selection ) {
if ( selection == null || selection.size() != 1 ) {
return false;
}
Object element = selection.getFirstElement();
return ( element != null &&
element instanceof IDebugElement &&
((IDebugElement)element).getDebugTarget().getAdapter( IExecFileInfo.class ) != null );
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 = ""; //$NON-NLS-1$
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(); //$NON-NLS-1$ //$NON-NLS-2$
}
return null;
}
},
CDebugUIPlugin.getResourceString("internal.ui.actions.AddGlobalsActionDelegate.Select_Variables") ); //$NON-NLS-1$
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 IGlobalVariableDescriptor ) {
String path = ""; //$NON-NLS-1$
if ( ((IGlobalVariableDescriptor)element).getPath() != null ) {
path = ((IGlobalVariableDescriptor)element).getPath().toString();
int index = path.lastIndexOf( '/' );
if ( index != -1 )
path = path.substring( index + 1 );
}
return (path.length() > 0 ? ('\'' + path + "\'::") : "") + ((IGlobalVariableDescriptor)element).getName(); //$NON-NLS-1$ //$NON-NLS-2$
}
return null;
}
}, CDebugUIPlugin.getResourceString( "internal.ui.actions.AddGlobalsActionDelegate.Select_Variables" ) ); //$NON-NLS-1$
}
protected Global[] getGlobals()
{
protected IGlobalVariableDescriptor[] getGlobals() {
return fGlobals;
}
protected void doAction( Object element ) throws DebugException
{
protected void doAction( Object element ) throws DebugException {
if ( getView() == null )
return;
if ( element != null && element instanceof IDebugElement )
{
if ( element != null && element instanceof IDebugElement ) {
IExecFileInfo info = (IExecFileInfo)((IDebugElement)element).getDebugTarget().getAdapter( IExecFileInfo.class );
if ( info != null )
{
IGlobalVariable[] globalVars = 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() );
}
ICGlobalVariableManager gvm = (ICGlobalVariableManager)((IDebugElement)element).getDebugTarget().getAdapter( ICGlobalVariableManager.class );
if ( info != null && gvm != null ) {
fGlobals = info.getGlobals();
ListSelectionDialog dlg = createDialog();
if ( dlg.open() == Window.OK )
{
MultiStatus ms = new MultiStatus( CDebugCorePlugin.getUniqueIdentifier(), DebugException.REQUEST_FAILED, getStatusMessage(), null );
Object[] selections = dlg.getResult();
for ( int i = 0; i < selections.length; ++i )
{
try
{
createExpression( ((IDebugElement)element).getDebugTarget(), (Global)selections[i] );
}
catch( DebugException e )
{
ms.merge( e.getStatus() );
}
}
if ( !ms.isOK() )
{
throw new DebugException( ms );
}
if ( dlg.open() == Window.OK ) {
List list = Arrays.asList( dlg.getResult() );
IGlobalVariableDescriptor[] selections = (IGlobalVariableDescriptor[])list.toArray( new IGlobalVariableDescriptor[list.size()] );
gvm.addGlobals( selections );
}
}
}
}
protected String getStatusMessage()
{
return CDebugUIPlugin.getResourceString("internal.ui.actions.AddGlobalsActionDelegate.Exceptions_occurred_attempting_to_add_global_variables."); //$NON-NLS-1$
}
/**
* @see AbstractDebugActionDelegate#getErrorDialogMessage()
*/
protected String getErrorDialogMessage()
{
return CDebugUIPlugin.getResourceString("internal.ui.actions.AddGlobalsActionDelegate.Add_global_variables_failed"); //$NON-NLS-1$
protected String getErrorDialogMessage() {
return CDebugUIPlugin.getResourceString( "internal.ui.actions.AddGlobalsActionDelegate.Add_global_variables_failed" ); //$NON-NLS-1$
}
protected void setStatus( IStatus status )
{
protected void setStatus( IStatus status ) {
fStatus = status;
}
protected IStatus getStatus()
{
protected IStatus getStatus() {
return fStatus;
}
private void createExpression( IDebugTarget target, Global global ) throws DebugException
{
IExpression expression = CDebugModel.createExpressionForGlobalVariable( target, global.getPath(), global.getName() );
DebugPlugin.getDefault().getExpressionManager().addExpression( expression );
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
*/
public void init( IAction action )
{
public void init( IAction action ) {
super.init( action );
Object element = DebugUITools.getDebugContext();
setSelection( (element != null ) ? new StructuredSelection( element ) : new StructuredSelection() );
setSelection( (element != null) ? new StructuredSelection( element ) : new StructuredSelection() );
update( action );
}
}
}

View file

@ -0,0 +1,51 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.cdt.debug.core.ICGlobalVariableManager;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.action.IAction;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.actions.ActionDelegate;
/**
* A delegate for the "Remove All Globals" action.
*/
public class RemoveAllGlobalsActionDelegate extends ActionDelegate implements IViewActionDelegate {
/* (non-Javadoc)
* @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
*/
public void init( IViewPart view ) {
}
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
public void run( IAction action ) {
IAdaptable context = DebugUITools.getDebugContext();
if ( context instanceof IDebugElement ) {
final ICGlobalVariableManager gvm = (ICGlobalVariableManager)((IDebugElement)context).getDebugTarget().getAdapter( ICGlobalVariableManager.class );
if ( gvm != null ) {
DebugPlugin.getDefault().asyncExec(
new Runnable() {
public void run() {
gvm.removeAllGlobals();
}
} );
}
}
}
}

View file

@ -0,0 +1,120 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
import java.util.ArrayList;
import java.util.Iterator;
import org.eclipse.cdt.debug.core.ICGlobalVariableManager;
import org.eclipse.cdt.debug.core.model.ICGlobalVariable;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.actions.ActionDelegate;
/**
* A delegate for the "Remove Globals" action.
*/
public class RemoveGlobalsActionDelegate extends ActionDelegate implements IViewActionDelegate {
private IAction fAction;
private ISelection fSelection;
/* (non-Javadoc)
* @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
*/
public void init( IViewPart view ) {
}
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
*/
public void init( IAction action ) {
setAction( action );
update();
}
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
public void run( IAction action ) {
ISelection selection = getSelection();
if ( !(selection instanceof IStructuredSelection) )
return;
IStructuredSelection ss = (IStructuredSelection)selection;
final Iterator enum = ss.iterator();
ArrayList list = new ArrayList( ss.size() );
while( enum.hasNext() ) {
Object obj = enum.next();
if ( obj instanceof ICGlobalVariable )
list.add( obj );
}
if ( list.size() == 0 )
return;
final ICGlobalVariable[] globals = (ICGlobalVariable[])list.toArray( new ICGlobalVariable[list.size()] );
final ICGlobalVariableManager gvm = (ICGlobalVariableManager)globals[0].getDebugTarget().getAdapter( ICGlobalVariableManager.class );
if ( gvm == null )
return;
Runnable r = new Runnable() {
public void run() {
gvm.removeGlobals( globals );
}
};
DebugPlugin.getDefault().asyncExec( r );
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
*/
public void selectionChanged( IAction action, ISelection selection ) {
setSelection( selection );
update();
}
protected IAction getAction() {
return fAction;
}
protected ISelection getSelection() {
return fSelection;
}
private void setAction( IAction action ) {
fAction = action;
}
private void setSelection( ISelection selection ) {
fSelection = selection;
}
private void update() {
IAction action = getAction();
if ( action != null ) {
ISelection selection = getSelection();
boolean enabled = false;
if ( selection instanceof IStructuredSelection ) {
Iterator it = ((IStructuredSelection)selection).iterator();
while( it.hasNext() ) {
if ( it.next() instanceof ICGlobalVariable ) {
enabled = true;
break;
}
}
}
action.setEnabled( enabled );
}
}
}