From 3822ee7b43390ed2176705174e929131f5d64ef8 Mon Sep 17 00:00:00 2001 From: Alvaro Sanchez-Leon Date: Sun, 13 Mar 2016 19:08:28 -0400 Subject: [PATCH] Bug 489516 - Traditional mem., choose visibility of the cross ref information This facility is dependent of the issues below. Bug 489512 - Show local variables in the traditional memory render Bug 489513 - Show registers in the traditional memory render Allow the user to choose visibility of the available cross reference information e.g. Variables, Registers In addition to the preferences at a instance level, a global preference is introduced to disable the resolution of additional information altogether. Change-Id: I9f8b9b612ff288b369ba6fca3402c0c911aa5f48 --- .../ui/memory/traditional/Rendering.java | 17 ++- .../traditional/RenderingAddressInfo.java | 128 +++++++++++++++--- .../traditional/TraditionalRendering.java | 30 +++- ...aditionalRenderingPreferenceConstants.java | 4 + ...itionalRenderingPreferenceInitializer.java | 2 + .../TraditionalRenderingPreferencePage.java | 5 + .../TraditionalRendering_messages.properties | 2 + 7 files changed, 165 insertions(+), 23 deletions(-) diff --git a/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/Rendering.java b/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/Rendering.java index 91ea1fc432a..820a90a9ce5 100755 --- a/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/Rendering.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/Rendering.java @@ -39,6 +39,7 @@ import org.eclipse.debug.core.model.MemoryByte; import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; import org.eclipse.debug.internal.ui.views.memory.MemoryViewUtil; import org.eclipse.debug.internal.ui.views.memory.renderings.GoToAddressComposite; +import org.eclipse.jface.action.Action; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.SWT; @@ -2338,9 +2339,23 @@ public class Rendering extends Composite implements IDebugEventSetListener * * @param addTypeHeaders * Indicates if the string shall include a data type name before each list of items of the same - * type e.g. Variables, Regitsters, etc. + * type e.g. Variables, Registers, etc. */ String buildAddressInfoString(BigInteger address, String separator, boolean addTypeHeaders) { return ""; } + + /** + * Returns Dynamic context menu actions to this render, No actions by default + * @since 1.4 + */ + Action[] getDynamicActions() { + return new Action[0]; + } + + /** + * Trigger the resolution of additional address information - No action by default + */ + void resolveAddressInfoForCurrentSelection() {} + } diff --git a/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/RenderingAddressInfo.java b/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/RenderingAddressInfo.java index 1f6abd17e23..95405a0a51d 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/RenderingAddressInfo.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/RenderingAddressInfo.java @@ -30,6 +30,8 @@ import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.contexts.DebugContextEvent; import org.eclipse.debug.ui.contexts.IDebugContextListener; import org.eclipse.debug.ui.contexts.IDebugContextService; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; @@ -57,6 +59,10 @@ public class RenderingAddressInfo extends Rendering * updated each time a context selection change is detected */ private volatile IMemoryBlockAddressInfoItem[] fAddressInfoItems; + + + private final AddressInfoTypeMap fAddressInfoTypeStatusMap = new AddressInfoTypeMap(); + public RenderingAddressInfo(Composite parent, TraditionalRendering renderingParent) { super(parent, renderingParent); @@ -71,10 +77,62 @@ public class RenderingAddressInfo extends Rendering resolveAddressInfoForCurrentSelection(contextService); } + /** + * Keeps a map from information type to its state and to a corresponding Action instance + * needed to update the actual state from UI interactions + */ + class AddressInfoTypeMap extends HashMap { + private static final long serialVersionUID = 1L; + + private final Map fTypeToActionMap = new HashMap<>(); + + public Action getAction(final String infoType) { + if (!containsKey(infoType)) { + if (fTypeToActionMap.containsKey(infoType)) { + // The key status has been removed, clean the action map + fTypeToActionMap.remove(infoType); + } + return null; + } + + Action action = fTypeToActionMap.get(infoType); + if (action != null) { + return action; + } else { + action = new Action(infoType, IAction.AS_CHECK_BOX) { + @Override + public void run() { + put(infoType, Boolean.valueOf(isChecked())); + redrawPanes(); + } + }; + action.setChecked(get(infoType)); + fTypeToActionMap.put(infoType, action); + } + + return action; + } + + @Override + public void clear() { + fTypeToActionMap.clear(); + super.clear(); + } + } + + @Override + void resolveAddressInfoForCurrentSelection() { + IWorkbenchPartSite site = fParent.getMemoryRenderingContainer().getMemoryRenderingSite().getSite(); + IDebugContextService contextService = DebugUITools.getDebugContextManager() + .getContextService(site.getWorkbenchWindow()); + resolveAddressInfoForCurrentSelection(contextService); + } + public void dispose() { fSelectedContext = null; fMapStartAddrToInfoItems.clear(); + fAddressInfoTypeStatusMap.clear(); fAddressInfoItems = null; IWorkbenchPartSite site = fParent.getMemoryRenderingContainer().getMemoryRenderingSite().getSite(); @@ -158,8 +216,8 @@ public class RenderingAddressInfo extends Rendering } private void handleDebugContextChanged(final Object context) { - if (isDisposed() || context == null) { - // Invalid context or Data pane is not visible + if (isDisposed() || context == null || !fParent.isShowCrossRefInfoGlobalPref()) { + // Invalid context or user has chosen not to see additional address information return; } @@ -185,21 +243,33 @@ public class RenderingAddressInfo extends Rendering // If the context is still valid if (getContext().equals(fSelectedContext)) { final IMemoryBlockAddressInfoItem[] addressInfoItems = getAllAddressInfoItems(); - if (!display.isDisposed()) { - display.asyncExec(new Runnable() { - @Override - public void run() { - // The selection has changed, so our Address information may no longer be valid - fAddressInfoItems = addressInfoItems; - fMapStartAddrToInfoItems.clear(); + - if (fBinaryPane.isVisible()) { - redrawPanes(); + if (fParent.isShowCrossRefInfoGlobalPref()) { + final String[] types = getAddressInfoItemTypes(); + + if (!display.isDisposed()) { + display.asyncExec(new Runnable() { + @Override + public void run() { + for (String type : types) { + if (!fAddressInfoTypeStatusMap.containsKey(type)) { + fAddressInfoTypeStatusMap.put(type, Boolean.TRUE); + } + } + + // The selection has changed, so our Address information may no longer be valid + fAddressInfoItems = addressInfoItems; + fMapStartAddrToInfoItems.clear(); + + if (fBinaryPane.isVisible()) { + redrawPanes(); + } + + refreshUpdateListener(addrInfo); } - - refreshUpdateListener(addrInfo); - } - }); + }); + } } } } @@ -256,16 +326,13 @@ public class RenderingAddressInfo extends Rendering @Override public void handleAddressInfoUpdate(EventType type, Object update) { fAddressInfoItems = null; - IWorkbenchPartSite site = fParent.getMemoryRenderingContainer().getMemoryRenderingSite().getSite(); - IDebugContextService contextService = DebugUITools.getDebugContextManager() - .getContextService(site.getWorkbenchWindow()); - resolveAddressInfoForCurrentSelection(contextService); + resolveAddressInfoForCurrentSelection(); } @Override Map> getVisibleValueToAddressInfoItems() { IMemoryBlockAddressInfoItem[] items = fAddressInfoItems; - if (items == null) { + if (items == null || !fParent.isShowCrossRefInfoGlobalPref()) { fMapStartAddrToInfoItems.clear(); return fMapStartAddrToInfoItems; } @@ -302,6 +369,13 @@ public class RenderingAddressInfo extends Rendering BigInteger endAddress = getViewportEndAddressSingleHeight(); for (IMemoryBlockAddressInfoItem item : items) { + // Skip information types not wanted by the user + String itemType = item.getInfoType(); + if (!fAddressInfoTypeStatusMap.containsKey(itemType) + || fAddressInfoTypeStatusMap.get(itemType).equals(Boolean.FALSE)) { + continue; + } + List containers = allValuesMap.get(item.getAddress()); if (containers == null) { containers = new ArrayList<>(); @@ -392,4 +466,18 @@ public class RenderingAddressInfo extends Rendering return (fBinaryPane.fPaneVisible && fMapStartAddrToInfoItems.size() > 0); } + @Override + public Action[] getDynamicActions() { + List actionList = new ArrayList(fAddressInfoTypeStatusMap.size()); + if (getPaneVisible(Rendering.PANE_BINARY)) { + for (final String infoType : fAddressInfoTypeStatusMap.keySet()) { + Action action = fAddressInfoTypeStatusMap.getAction(infoType); + if (action != null) { + actionList.add(action); + } + } + } + + return actionList.toArray(new Action[actionList.size()]); + } } diff --git a/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRendering.java b/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRendering.java index 6695cbcbe9f..c8668add513 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRendering.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRendering.java @@ -645,7 +645,10 @@ public class TraditionalRendering extends AbstractMemoryRendering implements IRe panes[i].setBackground(getColorBackground()); setRenderingPadding(TraditionalRenderingPlugin.getDefault().getPreferenceStore().getString(IDebugUIConstants.PREF_PADDED_STR)); - + if (store.getBoolean(TraditionalRenderingPreferenceConstants.MEM_CROSS_REFERENCE_INFO)) { + fRendering.resolveAddressInfoForCurrentSelection(); + } + fRendering.redrawPanes(); } } @@ -776,7 +779,15 @@ public class TraditionalRendering extends AbstractMemoryRendering implements IRe { return colorTextAlternate; } - + + /** + * @since 1.4 + */ + public boolean isShowCrossRefInfoGlobalPref() { + IPreferenceStore store = TraditionalRenderingPlugin.getDefault().getPreferenceStore(); + return store.getBoolean(TraditionalRenderingPreferenceConstants.MEM_CROSS_REFERENCE_INFO); + } + public void createMenus() { // add the menu to each of the rendering panes @@ -1251,6 +1262,21 @@ public class TraditionalRendering extends AbstractMemoryRendering implements IRe sub.add(displayTextPaneAction); manager.add(sub); + // if there is cross reference info types available + // add Actions to allow the user to toggle the visibility for each of them + if (isShowCrossRefInfoGlobalPref()) { + Action[] dynamicActions = fRendering.getDynamicActions(); + if (dynamicActions != null) { + sub = new MenuManager(TraditionalRenderingMessages + .getString("TraditionalRenderingPreferencePage_ShowCrossRefInfo_Label")); //$NON-NLS-1$ + for (Action action : dynamicActions) { + sub.add(action); + } + + manager.add(sub); + } + } + sub = new MenuManager(TraditionalRenderingMessages .getString("TraditionalRendering.ENDIAN")); //$NON-NLS-1$ sub.add(displayEndianBigAction); diff --git a/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRenderingPreferenceConstants.java b/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRenderingPreferenceConstants.java index 74b844b0e98..8871077e844 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRenderingPreferenceConstants.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRenderingPreferenceConstants.java @@ -62,4 +62,8 @@ public class TraditionalRenderingPreferenceConstants { */ public static final String MEM_MEMORY_SPACE_ID_PREFIX = MEM_COLOR_BACKGROUND + "MemorySpace-"; + /** + * @since 1.4 + */ + public static final String MEM_CROSS_REFERENCE_INFO = "memCrossReferenceInfo"; } diff --git a/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRenderingPreferenceInitializer.java b/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRenderingPreferenceInitializer.java index e36a1ebd8be..b69bd96648c 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRenderingPreferenceInitializer.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRenderingPreferenceInitializer.java @@ -79,6 +79,8 @@ public class TraditionalRenderingPreferenceInitializer extends AbstractPreferenc TraditionalRenderingPreferenceConstants.MEM_EDIT_BUFFER_SAVE_ON_ENTER_ONLY); store.setDefault(TraditionalRenderingPreferenceConstants.MEM_HISTORY_TRAILS_COUNT, "1"); + + store.setDefault(TraditionalRenderingPreferenceConstants.MEM_CROSS_REFERENCE_INFO, true); } } diff --git a/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRenderingPreferencePage.java b/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRenderingPreferencePage.java index b39e97c7294..83fd84d4682 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRenderingPreferencePage.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRenderingPreferencePage.java @@ -113,6 +113,11 @@ public class TraditionalRenderingPreferencePage addField(new ScaleFieldEditor(TraditionalRenderingPreferenceConstants.MEM_HISTORY_TRAILS_COUNT, TraditionalRenderingMessages.getString("TraditionalRenderingPreferencePage_HistoryTrailLevels"), getFieldEditorParent(), 1, 10, 1, 1)); //$NON-NLS-1$ + + addField(new BooleanFieldEditor(TraditionalRenderingPreferenceConstants.MEM_CROSS_REFERENCE_INFO, + TraditionalRenderingMessages + .getString("TraditionalRenderingPreferencePage_ShowCrossRefInfo"), //$NON-NLS-1$ + getFieldEditorParent())); } /* (non-Javadoc) diff --git a/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRendering_messages.properties b/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRendering_messages.properties index 657dffe0dbd..9eeb5ae4491 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRendering_messages.properties +++ b/memory/org.eclipse.cdt.debug.ui.memory.traditional/src/org/eclipse/cdt/debug/ui/memory/traditional/TraditionalRendering_messages.properties @@ -84,6 +84,8 @@ TraditionalRenderingPreferencePage_TextColor=&Text Color: TraditionalRenderingPreferencePage_UseGlobalBackgroundColor=Use Global B&ackground Color TraditionalRenderingPreferencePage_UseGlobalSelectionColor=Use Global Se&lection Color TraditionalRenderingPreferencePage_UseGlobalTextColor=Use Global Te&xt Color +TraditionalRenderingPreferencePage_ShowCrossRefInfo=Show cross reference information +TraditionalRenderingPreferencePage_ShowCrossRefInfo_Label=Cross Reference Information ColorAndEffectFieldEditor.bold=Bold ColorAndEffectFieldEditor.italic=Italic ColorAndEffectFieldEditor.box=Box