diff options
author | Alena Laskavaia | 2009-01-28 19:44:23 +0000 |
---|---|---|
committer | Alena Laskavaia | 2009-01-28 19:44:23 +0000 |
commit | 7d71c4678d947e974f5d72504cc37e08b9157928 (patch) | |
tree | 8c37b2e966c2e8e4413d94cfbd386799358e9513 | |
parent | 284fbbad7fb50aa3f245747f09363236a8e17b82 (diff) | |
download | org.eclipse.cdt-7d71c4678d947e974f5d72504cc37e08b9157928.tar.gz org.eclipse.cdt-7d71c4678d947e974f5d72504cc37e08b9157928.tar.xz org.eclipse.cdt-7d71c4678d947e974f5d72504cc37e08b9157928.zip |
[216618] - Format submenu now should appear for expressions as well
4 files changed, 288 insertions, 83 deletions
diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml index 4d98862c063..c30843f3e51 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.xml +++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml @@ -171,6 +171,67 @@ </action> </actionSet> </extension> + + <extension + point="org.eclipse.ui.menus"> + <menuContribution + locationURI="popup:org.eclipse.debug.ui.ExpressionView?after=additions"> + <menu + id="org.eclipse.cdt.debug.ui.expressionsView_CVariableFormatMenu" + label="%CVariableFormatMenu.label"> + <visibleWhen> + <reference definitionId="org.eclipse.cdt.debug.ui.testAreNumberFormatsSupported"/> + </visibleWhen> + <dynamic + id="org.eclipse.cdt.debug.ui.numberFormats" + class="org.eclipse.cdt.debug.internal.ui.actions.NumberFormatsContribution"> + </dynamic> + <separator name="formatGroup" visible="false"/> + </menu> + </menuContribution> + <menuContribution + locationURI="popup:org.eclipse.debug.ui.VariableView?after=variableGroup"> + <menu + id="org.eclipse.cdt.debug.ui.CVariableFormatMenu" + label="%CVariableFormatMenu.label"> + <visibleWhen> + <reference definitionId="org.eclipse.cdt.debug.ui.testAreNumberFormatsSupported"/> + </visibleWhen> + <dynamic + id="org.eclipse.cdt.debug.ui.numberFormats" + class="org.eclipse.cdt.debug.internal.ui.actions.NumberFormatsContribution"> + </dynamic> + <separator name="formatGroup" visible="false"/> + + </menu> + </menuContribution> + </extension> + + <extension point="org.eclipse.core.expressions.definitions"> + <definition + id="org.eclipse.cdt.debug.ui.testAreNumberFormatsSupported"> + <with variable="selection"> + <count + value="+"> + </count> + <iterate> + <test property="org.eclipse.cdt.debug.ui.canFormatObject" value="true"/> + </iterate> + </with> + </definition> + </extension> + + <extension point="org.eclipse.core.expressions.propertyTesters"> + <propertyTester + namespace="org.eclipse.cdt.debug.ui" + properties="canFormatObject" + type="org.eclipse.core.runtime.IAdaptable" + class="org.eclipse.cdt.debug.internal.ui.actions.CanFormatObjectTester" + id="org.eclipse.cdt.debug.ui.canFormatObjectTester"> + </propertyTester> + </extension> + + <extension point="org.eclipse.ui.popupMenus"> <viewerContribution @@ -415,50 +476,8 @@ id="org.eclipse.cdt.debug.ui.actions.ViewMemoryAction"> </action> </objectContribution> - - <objectContribution - objectClass="org.eclipse.cdt.debug.core.model.ICVariable" - id="org.eclipse.cdt.debug.ui.CVariableActions"> - <menu - label="%CVariableFormatMenu.label" - path="renderGroup" - id="org.eclipse.cdt.debug.ui.CVariableFormatMenu"> - <separator - name="formatGroup"> - </separator> - </menu> - <action - label="%HexVariableFormatAction.label" - helpContextId="hexadecimal_variable_format_action_context" - class="org.eclipse.cdt.debug.internal.ui.actions.HexVariableFormatActionDelegate" - menubarPath="org.eclipse.cdt.debug.ui.CVariableFormatMenu/formatGroup" - enablesFor="1" - id="org.eclipse.cdt.debug.internal.ui.actions.HexVariableFormatActionDelegate"> - </action> - <action - label="%DecVariableFormatAction.label" - helpContextId="decimal_variable_format_action_context" - class="org.eclipse.cdt.debug.internal.ui.actions.DecVariableFormatActionDelegate" - menubarPath="org.eclipse.cdt.debug.ui.CVariableFormatMenu/formatGroup" - enablesFor="1" - id="org.eclipse.cdt.debug.internal.ui.actions.DecVariableFormatActionDelegate"> - </action> - <action - label="%NaturalVariableFormatAction.label" - helpContextId="naturall_variable_format_action_context" - class="org.eclipse.cdt.debug.internal.ui.actions.NaturalVariableFormatActionDelegate" - menubarPath="org.eclipse.cdt.debug.ui.CVariableFormatMenu/formatGroup" - enablesFor="1" - id="org.eclipse.cdt.debug.internal.ui.actions.NaturalVariableFormatActionDelegate"> - </action> - <action - class="org.eclipse.cdt.debug.internal.ui.actions.BinaryVariableFormatActionDelegate" - enablesFor="1" - helpContextId="binary_variable_format_action_context" - id="org.eclipse.cdt.debug.internal.ui.actions.BinaryVariableFormatActionDelegate" - label="%BinaryVariableFormatAction.label" - menubarPath="org.eclipse.cdt.debug.ui.CVariableFormatMenu/formatGroup"/> - </objectContribution> + + <objectContribution objectClass="org.eclipse.cdt.debug.core.model.ICSignal" id="org.eclipse.cdt.debug.ui.SignalActions"> diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CanFormatObjectTester.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CanFormatObjectTester.java new file mode 100644 index 00000000000..5fc6b2da5e2 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/CanFormatObjectTester.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2009 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.debug.internal.ui.actions; + +import org.eclipse.cdt.debug.core.model.ICValue; +import org.eclipse.cdt.debug.core.model.ICVariable; +import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.debug.core.model.IWatchExpression; + +/** + * Property test for object in selection. + * property: canFormatObject - if object is C/C++ formattable + * @author elaskavaia + * + */ +public class CanFormatObjectTester extends PropertyTester { + + public CanFormatObjectTester() { + + } + + public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { + if (property.equals("canFormatObject")) { + if (receiver instanceof ICVariable) { return expectedValue == Boolean.TRUE; } + if (receiver instanceof IWatchExpression) { + IWatchExpression w = (IWatchExpression) receiver; + if (w.getValue() instanceof ICValue) + return expectedValue == Boolean.TRUE; + } + return expectedValue == Boolean.FALSE; + } + return false; + } + +} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/NumberFormatsContribution.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/NumberFormatsContribution.java new file mode 100644 index 00000000000..e56506918d4 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/NumberFormatsContribution.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2009 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-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.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.cdt.debug.core.model.CVariableFormat; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.ContributionItem; +import org.eclipse.jface.action.IContributionItem; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.ui.ISelectionService; +import org.eclipse.ui.actions.CompoundContributionItem; +import org.eclipse.ui.menus.IWorkbenchContribution; +import org.eclipse.ui.services.IServiceLocator; + +/** + * Dynamic menu contribution that shows available number formats + * in the current view. + * + * @since 6.0 + */ +public class NumberFormatsContribution extends CompoundContributionItem implements IWorkbenchContribution { + static final String CURRENT_FORMAT = "current_format"; + + private static final Map<CVariableFormat, String> FORMATS = new LinkedHashMap<CVariableFormat, String>(); + static { + FORMATS.put(CVariableFormat.NATURAL, "Natural"); + FORMATS.put(CVariableFormat.DECIMAL, "Decimal"); + FORMATS.put(CVariableFormat.HEXADECIMAL, "Hexadecimal"); + //FORMATS.put(CVariableFormat.OCTAL, "Octal"); + FORMATS.put(CVariableFormat.BINARY, "Binary"); + } + + private class SelectNumberFormatAction extends Action { + private final CVariableFormat fFormat; + private VariableFormatActionDelegate delegate; + + public VariableFormatActionDelegate getDelegate() { + return delegate; + } + + SelectNumberFormatAction(CVariableFormat format) { + super(FORMATS.get(format), AS_RADIO_BUTTON); + + fFormat = format; + delegate = new VariableFormatActionDelegate(fFormat); + } + + void selectionChanged(ISelection sel) { + delegate.selectionChanged(this, sel); + } + + @Override + public void run() { + if (isChecked()) { + delegate.run(this); + } + } + } + + private IServiceLocator fServiceLocator; + + private static IContributionItem[] NO_ITEMS = new IContributionItem[] { new ContributionItem() { + @Override + public void fill(Menu menu, int index) { + MenuItem item = new MenuItem(menu, SWT.NONE); + item.setEnabled(false); + item.setText("Empty"); + } + + @Override + public boolean isEnabled() { + return false; + } + } }; + + @Override + protected IContributionItem[] getContributionItems() { + ISelectionService service = (ISelectionService) fServiceLocator.getService(ISelectionService.class); + ISelection selection = service.getSelection(); + + + List<Action> actions = new ArrayList<Action>(FORMATS.size()); + + for (CVariableFormat formatId : FORMATS.keySet()) { + SelectNumberFormatAction action = new SelectNumberFormatAction(formatId); + action.selectionChanged(selection); + actions.add(action); + } + + if (actions.isEmpty()) { return NO_ITEMS; } + + IContributionItem[] items = new IContributionItem[actions.size()]; + for (int i = 0; i < actions.size(); i++) { + items[i] = new ActionContributionItem(actions.get(i)); + } + return items; + } + + public void initialize(IServiceLocator serviceLocator) { + fServiceLocator = serviceLocator; + } +} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/VariableFormatActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/VariableFormatActionDelegate.java index 8abb3c43285..ab7f7b0bd6d 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/VariableFormatActionDelegate.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/VariableFormatActionDelegate.java @@ -13,11 +13,16 @@ package org.eclipse.cdt.debug.internal.ui.actions; import java.util.ArrayList; import java.util.Iterator; import java.util.List; + import org.eclipse.cdt.debug.core.model.CVariableFormat; import org.eclipse.cdt.debug.core.model.ICVariable; +import org.eclipse.cdt.debug.internal.core.model.CValue; import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.core.runtime.MultiStatus; import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IValue; +import org.eclipse.debug.core.model.IWatchExpression; +import org.eclipse.debug.internal.core.WatchExpression; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; @@ -30,50 +35,46 @@ import org.eclipse.ui.IWorkbenchWindow; /** * The superclass of the all format action delegates. */ -public abstract class VariableFormatActionDelegate implements IObjectActionDelegate { - +public class VariableFormatActionDelegate implements IObjectActionDelegate { private CVariableFormat fFormat = CVariableFormat.NATURAL; - private ICVariable[] fVariables = null; + private IStructuredSelection selection; /** * Constructor for VariableFormatActionDelegate. */ - public VariableFormatActionDelegate( CVariableFormat format ) { + public VariableFormatActionDelegate(CVariableFormat format) { fFormat = format; } /** * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart) */ - public void setActivePart( IAction action, IWorkbenchPart targetPart ) { + public void setActivePart(IAction action, IWorkbenchPart targetPart) { } /** * @see org.eclipse.ui.IActionDelegate#run(IAction) */ - public void run( IAction action ) { + public void run(IAction action) { ICVariable[] vars = getVariables(); - if ( vars != null && vars.length > 0 ) { - final MultiStatus ms = new MultiStatus( CDebugUIPlugin.getUniqueIdentifier(), DebugException.REQUEST_FAILED, "", null ); //$NON-NLS-1$ - BusyIndicator.showWhile( Display.getCurrent(), new Runnable() { - + if (vars != null && vars.length > 0) { + final MultiStatus ms = new MultiStatus(CDebugUIPlugin.getUniqueIdentifier(), DebugException.REQUEST_FAILED, "", null); //$NON-NLS-1$ + BusyIndicator.showWhile(Display.getCurrent(), new Runnable() { public void run() { try { - doAction( getVariables() ); - } - catch( DebugException e ) { - ms.merge( e.getStatus() ); + doAction(getVariables()); + } catch (DebugException e) { + ms.merge(e.getStatus()); } } - } ); - if ( !ms.isOK() ) { + }); + if (!ms.isOK()) { IWorkbenchWindow window = CDebugUIPlugin.getActiveWorkbenchWindow(); - if ( window != null ) { - CDebugUIPlugin.errorDialog( ActionMessages.getString( "VariableFormatActionDelegate.0" ), ms ); //$NON-NLS-1$ - } - else { - CDebugUIPlugin.log( ms ); + if (window != null) { + CDebugUIPlugin.errorDialog(ActionMessages.getString("VariableFormatActionDelegate.0"), ms); //$NON-NLS-1$ + } else { + CDebugUIPlugin.log(ms); } } } @@ -82,42 +83,64 @@ public abstract class VariableFormatActionDelegate implements IObjectActionDeleg /** * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection) */ - public void selectionChanged( IAction action, ISelection selection ) { - if ( selection instanceof IStructuredSelection ) { - List list = new ArrayList(); - IStructuredSelection ssel = (IStructuredSelection)selection; + public void selectionChanged(IAction action, ISelection selection) { + + if (selection instanceof IStructuredSelection) { + this.selection = (IStructuredSelection) selection; + List<ICVariable> list = new ArrayList<ICVariable>(); + IStructuredSelection ssel = (IStructuredSelection) selection; Iterator i = ssel.iterator(); - while( i.hasNext() ) { + while (i.hasNext()) { Object o = i.next(); - if ( o instanceof ICVariable ) { - ICVariable var = (ICVariable)o; - boolean enabled = var.supportsFormatting(); - action.setEnabled( enabled ); - if ( enabled ) { - action.setChecked( var.getFormat() == fFormat ); - list.add( o ); + if (o instanceof ICVariable) { + ICVariable var = (ICVariable) o; + list.add(var); + } else if (o instanceof IWatchExpression) { + IWatchExpression expr = (IWatchExpression) o; + IValue value = expr.getValue(); + if (value instanceof CValue) { + ICVariable parent = ((CValue) value).getParentVariable(); + if (parent != null) { + list.add(parent); + } } } } - setVariables( (ICVariable[])list.toArray( new ICVariable[list.size()] ) ); - } - else { - action.setChecked( false ); - action.setEnabled( false ); + for (Iterator<ICVariable> iterator = list.iterator(); iterator.hasNext();) { + ICVariable var = iterator.next(); + boolean enabled = var.supportsFormatting(); + action.setEnabled(enabled); + if (enabled) { + action.setChecked(var.getFormat() == fFormat); + } else { + iterator.remove(); + } + } + setVariables(list.toArray(new ICVariable[list.size()])); + } else { + action.setChecked(false); + action.setEnabled(false); } } + protected void doAction( ICVariable[] vars ) throws DebugException { for( int i = 0; i < vars.length; i++ ) { vars[i].changeFormat( fFormat ); } + for (Iterator iterator = selection.iterator(); iterator.hasNext();) { + Object o = iterator.next(); + if (o instanceof WatchExpression){ + ((WatchExpression)o).evaluate(); + } + } } protected ICVariable[] getVariables() { return fVariables; } - private void setVariables( ICVariable[] variables ) { + private void setVariables(ICVariable[] variables) { fVariables = variables; } } |