1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 14:12:10 +02:00

Bug 371012 - Number format pull down menu need to get choices from service or some component instead of hard coding the values

This commit is contained in:
Winndie Lai 2012-03-08 15:19:03 -08:00 committed by Pawel Piech
parent e799de15a0
commit 4be0276d23
3 changed files with 104 additions and 8 deletions

View file

@ -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>

View file

@ -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;
}
}

View file

@ -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;
}
}