From 3475ac77a385c500e6847a1cbc743ca8625ae9a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B6rn=20Svensson?= Date: Tue, 5 Apr 2022 14:12:13 +0200 Subject: [PATCH] Bug 579542: [hover] Backport changes from JDT to CDT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Over the years, there have been a few changes to the ExpressionInformationControlCreator class in JDT that was never backported to the CDT version of the class. Below is a list of JDT commit id's for the changes that are ported with this change: * cdcbfc3d91770a370336a7e48fff3e33edcaab39 - Fix bitwise to boolean and * eab4ed938be7938ecd72592249639084638a3933 - Dispose the context * ce04ec5c162ac64796da816f4abfa5f415756382 - Set correct themed colors Contributed by STMicroelectronics Change-Id: Ib4cc1e65c796d811c84859f7ccb05940934e2890 Signed-off-by: Torbjörn Svensson (cherry picked from commit 8ddef84fe8eae2c15e98d710717c9be578c560b4) --- .../ExpressionInformationControlCreator.java | 47 +++++++++++++++---- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/ExpressionInformationControlCreator.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/ExpressionInformationControlCreator.java index 3682639f2ec..55bad139fc7 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/ExpressionInformationControlCreator.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/internal/ui/ExpressionInformationControlCreator.java @@ -33,6 +33,10 @@ import org.eclipse.debug.internal.ui.views.variables.details.IDetailPaneContaine import org.eclipse.debug.ui.AbstractDebugView; import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.preference.JFacePreferences; +import org.eclipse.jface.resource.ColorRegistry; +import org.eclipse.jface.resource.JFaceColors; +import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.text.AbstractInformationControl; import org.eclipse.jface.text.IInformationControl; import org.eclipse.jface.text.IInformationControlCreator; @@ -50,6 +54,7 @@ import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Layout; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Tree; @@ -125,6 +130,7 @@ public class ExpressionInformationControlCreator implements IInformationControlC */ private Object fVariable; + private IPresentationContext fContext; private TreeModelViewer fViewer; private SashForm fSashForm; private Composite fDetailPaneComposite; @@ -188,8 +194,8 @@ public class ExpressionInformationControlCreator implements IInformationControlC @Override public void paneChanged(String newPaneID) { if (DefaultDetailPane.ID.equals(newPaneID)) { - fDetailPane.getCurrentControl() - .setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + fDetailPane.getCurrentControl().setForeground(getSystemForegroundColor()); + fDetailPane.getCurrentControl().setBackground(getSystemBackgroundColor()); } } @@ -265,7 +271,7 @@ public class ExpressionInformationControlCreator implements IInformationControlC private IDialogSettings getDialogSettings(boolean create) { IDialogSettings settings = DsfUIPlugin.getDefault().getDialogSettings(); IDialogSettings section = settings.getSection(this.getClass().getName()); - if (section == null & create) { + if (section == null && create) { section = settings.addNewSection(this.getClass().getName()); } return section; @@ -289,6 +295,7 @@ public class ExpressionInformationControlCreator implements IInformationControlC @Override public void dispose() { persistSettings(getShell()); + fContext.dispose(); super.dispose(); } @@ -339,8 +346,7 @@ public class ExpressionInformationControlCreator implements IInformationControlC // update presentation context AbstractDebugView view = getViewToEmulate(); - IPresentationContext context = new ExpressionHoverPresentationContext( - IDsfDebugUIConstants.ID_EXPRESSION_HOVER); + fContext = new ExpressionHoverPresentationContext(IDsfDebugUIConstants.ID_EXPRESSION_HOVER); if (view != null) { // copy over properties IPresentationContext copy = ((TreeModelViewer) view.getViewer()).getPresentationContext(); @@ -348,14 +354,14 @@ public class ExpressionInformationControlCreator implements IInformationControlC String[] properties = copy.getProperties(); for (int i = 0; i < properties.length; i++) { String key = properties[i]; - context.setProperty(key, copy.getProperty(key)); + fContext.setProperty(key, copy.getProperty(key)); } } catch (NoSuchMethodError e) { // ignore } } - fViewer = new TreeModelViewer(fSashForm, SWT.MULTI | SWT.VIRTUAL | SWT.FULL_SELECTION, context); + fViewer = new TreeModelViewer(fSashForm, SWT.MULTI | SWT.VIRTUAL | SWT.FULL_SELECTION, fContext); fViewer.setAutoExpandLevel(fExpansionLevel); if (view != null) { @@ -430,8 +436,8 @@ public class ExpressionInformationControlCreator implements IInformationControlC fViewer.addViewerUpdateListener(fViewerUpdateListener); - setForegroundColor(getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); - setBackgroundColor(getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + setForegroundColor(getSystemForegroundColor()); + setBackgroundColor(getSystemBackgroundColor()); } /** @@ -537,7 +543,6 @@ public class ExpressionInformationControlCreator implements IInformationControlC public void viewerInputComplete(IViewerInputUpdate update) { fViewer.setInput(fVariable = update.getInputElement()); } - } protected final boolean fShowDetailPane; @@ -572,4 +577,26 @@ public class ExpressionInformationControlCreator implements IInformationControlC return new ExpressionInformationControl(parent, false); } + private static Color getSystemForegroundColor() { + ColorRegistry colorRegistry = JFaceResources.getColorRegistry(); + Color foreground = colorRegistry.get(JFacePreferences.INFORMATION_FOREGROUND_COLOR); + + if (foreground == null) { + return JFaceColors.getInformationViewerForegroundColor(Display.getDefault()); + } + + return foreground; + } + + public static Color getSystemBackgroundColor() { + ColorRegistry colorRegistry = JFaceResources.getColorRegistry(); + Color background = colorRegistry.get(JFacePreferences.INFORMATION_BACKGROUND_COLOR); + + if (background == null) { + return JFaceColors.getInformationViewerBackgroundColor(Display.getDefault()); + } + + return background; + } + }