summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWinndie Lai2012-03-08 18:19:03 (EST)
committer Pawel Piech2012-03-08 18:19:03 (EST)
commit4be0276d23c95deaaedb7ac41e57b8f8c322b7be (patch)
tree38e26b70686a1c55d10a51ef8523990fbd0adc65
parente799de15a0119d7b810899143a2ceb38c0804ef1 (diff)
downloadorg.eclipse.cdt-4be0276d23c95deaaedb7ac41e57b8f8c322b7be.zip
org.eclipse.cdt-4be0276d23c95deaaedb7ac41e57b8f8c322b7be.tar.gz
org.eclipse.cdt-4be0276d23c95deaaedb7ac41e57b8f8c322b7be.tar.bz2
Bug 371012 - Number format pull down menu need to get choices from service or some component instead of hard coding the values
-rw-r--r--dsf/org.eclipse.cdt.dsf.ui/plugin.xml21
-rw-r--r--dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/numberformat/ElementNumberFormatsContribution.java25
-rw-r--r--dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/numberformat/RestoreNumberFormatPreferenceContribution.java66
3 files changed, 104 insertions, 8 deletions
diff --git a/dsf/org.eclipse.cdt.dsf.ui/plugin.xml b/dsf/org.eclipse.cdt.dsf.ui/plugin.xml
index 95ad921..5233cea 100644
--- a/dsf/org.eclipse.cdt.dsf.ui/plugin.xml
+++ b/dsf/org.eclipse.cdt.dsf.ui/plugin.xml
@@ -168,6 +168,13 @@
id="org.eclipse.cdt.dsf.debug.ui.registersNumberFormats"
class="org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.ElementNumberFormatsContribution">
</dynamic>
+ <separator
+ name="numberFormatSep" visible="true">
+ </separator>
+ <dynamic
+ id="org.eclipse.cdt.dsf.debug.ui.restoreNumberFormatPreference"
+ class="org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.RestoreNumberFormatPreferenceContribution">
+ </dynamic>
</menu>
</menuContribution>
@@ -231,6 +238,13 @@
id="org.eclipse.cdt.dsf.debug.ui.variablesNumberFormats"
class="org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.ElementNumberFormatsContribution">
</dynamic>
+ <separator
+ name="numberFormatSep" visible="true">
+ </separator>
+ <dynamic
+ id="org.eclipse.cdt.dsf.debug.ui.restoreNumberFormatPreference"
+ class="org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.RestoreNumberFormatPreferenceContribution">
+ </dynamic>
</menu>
</menuContribution>
@@ -294,6 +308,13 @@
id="org.eclipse.cdt.dsf.debug.ui.expressionNumberFormats"
class="org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.ElementNumberFormatsContribution">
</dynamic>
+ <separator
+ name="numberFormatSep" visible="true">
+ </separator>
+ <dynamic
+ id="org.eclipse.cdt.dsf.debug.ui.restoreNumberFormatPreference"
+ class="org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.RestoreNumberFormatPreferenceContribution">
+ </dynamic>
</menu>
</menuContribution>
</extension>
diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/numberformat/ElementNumberFormatsContribution.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/numberformat/ElementNumberFormatsContribution.java
index 1a58256..73e517a 100644
--- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/numberformat/ElementNumberFormatsContribution.java
+++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/numberformat/ElementNumberFormatsContribution.java
@@ -22,14 +22,15 @@ import org.eclipse.cdt.dsf.ui.viewmodel.IVMContext;
import org.eclipse.cdt.dsf.ui.viewmodel.IVMNode;
import org.eclipse.cdt.dsf.ui.viewmodel.IVMProvider;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
+import org.eclipse.debug.ui.AbstractDebugView;
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.action.Separator;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ITreeSelection;
import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
@@ -43,7 +44,7 @@ import org.eclipse.swt.widgets.MenuItem;
*/
public class ElementNumberFormatsContribution extends NumberFormatsContribution {
- private class SelectFormatAction extends Action {
+ static class SelectFormatAction extends Action {
private final IElementFormatProvider fProvider;
private final IPresentationContext fContext;
private final IVMNode[] fNodes;
@@ -98,8 +99,6 @@ public class ElementNumberFormatsContribution extends NumberFormatsContribution
return NO_ITEMS;
}
IVMProvider provider = VMHandlerUtils.getVMProviderForSelection(selection);
- if (provider instanceof IElementFormatProvider == false) {
- }
if (FORMATS.size() == 0) {
return NO_ITEMS;
}
@@ -108,6 +107,17 @@ public class ElementNumberFormatsContribution extends NumberFormatsContribution
IVMNode[] nodes = new IVMNode[elementPaths.length];
final String[] formats = new String[elementPaths.length];
Object viewerInput = null;
+ if (context.getPart() instanceof AbstractDebugView) {
+ Viewer viewer = ((AbstractDebugView)context.getPart()).getViewer();
+ if (viewer != null) {
+ viewerInput = viewer.getInput();
+ }
+ }
+ // Here we keep using hard-coded formats, which are common formats.
+ // We expect clients may add extra formats before and after these formats.
+ // For details, please refer to 371012.
+ // For now, we do not use vm provider's cache entry to get available formats
+ // because it shows something extra than what we have been expecting. See 371012 comment #2.
final List<SelectFormatAction> actions = new ArrayList<SelectFormatAction>(FORMATS.size());
for (String formatId : FORMATS) {
actions.add(new SelectFormatAction((IElementFormatProvider) provider,
@@ -123,12 +133,14 @@ public class ElementNumberFormatsContribution extends NumberFormatsContribution
} else if (activeFormat != null
&& activeFormat.equals(formats[i]) == false) {
activeFormat = null;
+ break;
}
}
if (activeFormat != null) {
for (int i = 0; i < actions.size(); i++) {
if (activeFormat.equals(actions.get(i).fFormatId)) {
actions.get(i).setChecked(true);
+ break;
}
}
}
@@ -153,13 +165,10 @@ public class ElementNumberFormatsContribution extends NumberFormatsContribution
}
crm.setDoneCount(elementPaths.length);
int count = actions.size();
- IContributionItem[] items = new IContributionItem[count + 2];
+ IContributionItem[] items = new IContributionItem[count];
for (int i = 0; i < actions.size(); i++) {
items[i] = new ActionContributionItem(actions.get(i));
}
- items[count] = new Separator();
- items[count + 1] = new ActionContributionItem(new SelectFormatAction(
- (IElementFormatProvider) provider, context, nodes, viewerInput, elementPaths, null));
return items;
}
}
diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/numberformat/RestoreNumberFormatPreferenceContribution.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/numberformat/RestoreNumberFormatPreferenceContribution.java
new file mode 100644
index 0000000..4b852c7
--- /dev/null
+++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/numberformat/RestoreNumberFormatPreferenceContribution.java
@@ -0,0 +1,66 @@
+/*****************************************************************
+ * Copyright (c) 2012 Texas Instruments 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:
+ * Winnie Lai (Texas Instruments) - Individual Element Number Format (Bug 202556)
+ * Winnie Lai (Texas Instruments) - Allow contributions around number format menu (Bug 371012)
+ *****************************************************************/
+package org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat;
+
+import org.eclipse.cdt.dsf.debug.ui.viewmodel.actions.VMHandlerUtils;
+import org.eclipse.cdt.dsf.ui.viewmodel.IVMContext;
+import org.eclipse.cdt.dsf.ui.viewmodel.IVMNode;
+import org.eclipse.cdt.dsf.ui.viewmodel.IVMProvider;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
+import org.eclipse.debug.ui.AbstractDebugView;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * Dynamic menu contribution that restores the element number format in the current
+ * selection of the view to view's preference.
+ *
+ * We pull 'restore to preference' menu item out from ElementNumberFormatsContribution
+ * so that clients can add extra contribution before or after it. See 371012.
+ * @since 2.3
+ */
+public class RestoreNumberFormatPreferenceContribution extends ElementNumberFormatsContribution {
+ @Override
+ protected IContributionItem[] getContributionItems() {
+ ISelection selection = VMHandlerUtils.getSelection(fServiceLocator);
+ if (selection == null || selection.isEmpty() || selection instanceof ITreeSelection == false) {
+ return new IContributionItem[0];
+ }
+ IVMProvider provider = VMHandlerUtils.getVMProviderForSelection(selection);
+ IPresentationContext context = provider.getPresentationContext();
+ TreePath[] elementPaths = ((ITreeSelection) selection).getPaths();
+ IVMNode[] nodes = new IVMNode[elementPaths.length];
+ Object viewerInput = null;
+ if (context.getPart() instanceof AbstractDebugView) {
+ Viewer viewer = ((AbstractDebugView)context.getPart()).getViewer();
+ if (viewer != null) {
+ viewerInput = viewer.getInput();
+ }
+ }
+ for (int i = 0; i < elementPaths.length; i++) {
+ Object segment = elementPaths[i].getLastSegment();
+ if (segment instanceof IVMContext) {
+ nodes[i] = ((IVMContext) segment).getVMNode();
+ } else {
+ nodes[i] = null;
+ }
+ }
+ IContributionItem[] items = new IContributionItem[1];
+ items[0] = new ActionContributionItem(new SelectFormatAction(
+ (IElementFormatProvider) provider, context, nodes, viewerInput, elementPaths, null));
+ return items;
+ }
+} \ No newline at end of file