1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Bug 579542: [hover] Backport changes from JDT to CDT

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 <torbjorn.svensson@st.com>
(cherry picked from commit 8ddef84fe8)
This commit is contained in:
Torbjörn Svensson 2022-04-05 14:12:13 +02:00
parent 1606bfa130
commit 3475ac77a3

View file

@ -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.AbstractDebugView;
import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jface.dialogs.IDialogSettings; 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.AbstractInformationControl;
import org.eclipse.jface.text.IInformationControl; import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator; 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.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Layout; import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.Tree;
@ -125,6 +130,7 @@ public class ExpressionInformationControlCreator implements IInformationControlC
*/ */
private Object fVariable; private Object fVariable;
private IPresentationContext fContext;
private TreeModelViewer fViewer; private TreeModelViewer fViewer;
private SashForm fSashForm; private SashForm fSashForm;
private Composite fDetailPaneComposite; private Composite fDetailPaneComposite;
@ -188,8 +194,8 @@ public class ExpressionInformationControlCreator implements IInformationControlC
@Override @Override
public void paneChanged(String newPaneID) { public void paneChanged(String newPaneID) {
if (DefaultDetailPane.ID.equals(newPaneID)) { if (DefaultDetailPane.ID.equals(newPaneID)) {
fDetailPane.getCurrentControl() fDetailPane.getCurrentControl().setForeground(getSystemForegroundColor());
.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); fDetailPane.getCurrentControl().setBackground(getSystemBackgroundColor());
} }
} }
@ -265,7 +271,7 @@ public class ExpressionInformationControlCreator implements IInformationControlC
private IDialogSettings getDialogSettings(boolean create) { private IDialogSettings getDialogSettings(boolean create) {
IDialogSettings settings = DsfUIPlugin.getDefault().getDialogSettings(); IDialogSettings settings = DsfUIPlugin.getDefault().getDialogSettings();
IDialogSettings section = settings.getSection(this.getClass().getName()); IDialogSettings section = settings.getSection(this.getClass().getName());
if (section == null & create) { if (section == null && create) {
section = settings.addNewSection(this.getClass().getName()); section = settings.addNewSection(this.getClass().getName());
} }
return section; return section;
@ -289,6 +295,7 @@ public class ExpressionInformationControlCreator implements IInformationControlC
@Override @Override
public void dispose() { public void dispose() {
persistSettings(getShell()); persistSettings(getShell());
fContext.dispose();
super.dispose(); super.dispose();
} }
@ -339,8 +346,7 @@ public class ExpressionInformationControlCreator implements IInformationControlC
// update presentation context // update presentation context
AbstractDebugView view = getViewToEmulate(); AbstractDebugView view = getViewToEmulate();
IPresentationContext context = new ExpressionHoverPresentationContext( fContext = new ExpressionHoverPresentationContext(IDsfDebugUIConstants.ID_EXPRESSION_HOVER);
IDsfDebugUIConstants.ID_EXPRESSION_HOVER);
if (view != null) { if (view != null) {
// copy over properties // copy over properties
IPresentationContext copy = ((TreeModelViewer) view.getViewer()).getPresentationContext(); IPresentationContext copy = ((TreeModelViewer) view.getViewer()).getPresentationContext();
@ -348,14 +354,14 @@ public class ExpressionInformationControlCreator implements IInformationControlC
String[] properties = copy.getProperties(); String[] properties = copy.getProperties();
for (int i = 0; i < properties.length; i++) { for (int i = 0; i < properties.length; i++) {
String key = properties[i]; String key = properties[i];
context.setProperty(key, copy.getProperty(key)); fContext.setProperty(key, copy.getProperty(key));
} }
} catch (NoSuchMethodError e) { } catch (NoSuchMethodError e) {
// ignore // 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); fViewer.setAutoExpandLevel(fExpansionLevel);
if (view != null) { if (view != null) {
@ -430,8 +436,8 @@ public class ExpressionInformationControlCreator implements IInformationControlC
fViewer.addViewerUpdateListener(fViewerUpdateListener); fViewer.addViewerUpdateListener(fViewerUpdateListener);
setForegroundColor(getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); setForegroundColor(getSystemForegroundColor());
setBackgroundColor(getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); setBackgroundColor(getSystemBackgroundColor());
} }
/** /**
@ -537,7 +543,6 @@ public class ExpressionInformationControlCreator implements IInformationControlC
public void viewerInputComplete(IViewerInputUpdate update) { public void viewerInputComplete(IViewerInputUpdate update) {
fViewer.setInput(fVariable = update.getInputElement()); fViewer.setInput(fVariable = update.getInputElement());
} }
} }
protected final boolean fShowDetailPane; protected final boolean fShowDetailPane;
@ -572,4 +577,26 @@ public class ExpressionInformationControlCreator implements IInformationControlC
return new ExpressionInformationControl(parent, false); 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;
}
} }