1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +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>
This commit is contained in:
Torbjörn Svensson 2022-04-05 14:12:13 +02:00
parent 8c021b181f
commit 8ddef84fe8

View file

@ -35,6 +35,8 @@ 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;
@ -52,13 +54,13 @@ 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;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.themes.ITheme;
/**
* Creates an information control to display an expression in a hover control.
@ -128,6 +130,7 @@ public class ExpressionInformationControlCreator implements IInformationControlC
*/
private Object fVariable;
private IPresentationContext fContext;
private TreeModelViewer fViewer;
private SashForm fSashForm;
private Composite fDetailPaneComposite;
@ -191,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());
}
}
@ -268,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;
@ -292,6 +295,7 @@ public class ExpressionInformationControlCreator implements IInformationControlC
@Override
public void dispose() {
persistSettings(getShell());
fContext.dispose();
super.dispose();
}
@ -342,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();
@ -351,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) {
@ -433,21 +436,8 @@ public class ExpressionInformationControlCreator implements IInformationControlC
fViewer.addViewerUpdateListener(fViewerUpdateListener);
ITheme currentTheme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
ColorRegistry colorRegistry = currentTheme.getColorRegistry();
Color fg = colorRegistry.get(JFacePreferences.INFORMATION_FOREGROUND_COLOR);
if (fg == null) {
fg = getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND);
}
Color bg = colorRegistry.get(JFacePreferences.INFORMATION_BACKGROUND_COLOR);
if (bg == null) {
bg = getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
}
setForegroundColor(fg);
setBackgroundColor(bg);
setForegroundColor(getSystemForegroundColor());
setBackgroundColor(getSystemBackgroundColor());
}
/**
@ -553,7 +543,6 @@ public class ExpressionInformationControlCreator implements IInformationControlC
public void viewerInputComplete(IViewerInputUpdate update) {
fViewer.setInput(fVariable = update.getInputElement());
}
}
protected final boolean fShowDetailPane;
@ -588,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;
}
}