Home » Eclipse Projects » Eclipse 4 » Specify theme-specific preferences via CSS(How to update UI preferences when the user switches to dark theme)
Specify theme-specific preferences via CSS [message #1818562] |
Thu, 19 December 2019 16:44 |
Emmanuel Chebbi Messages: 123 Registered: February 2018 |
Senior Member |
|
|
I am trying to automatically change the colors of my Xtext editor when the user switches to dark mode [1] but did not succeed so far. According to this newsletter [2] it is possible to ask the CSS Engine to automatically updates preferences according to Eclipse IDE's theme but I can't make it work, even on simple use cases.
Here is what I tried:
- Contribute to the org.eclipse.e4.ui.css.swt.theme extension point
<extension
point="org.eclipse.e4.ui.css.swt.theme">
<stylesheet
uri="css/dark-theme.css">
<themeid
refid="org.eclipse.e4.ui.css.theme.e4_dark">
</themeid>
</stylesheet>
</extension>
- Link the following CSS file
IEclipsePreferences#my-custom-preference-node {
preferences:
'myPref=someValue'
}
- Open an Eclipse IDE runtime
- Call the following code:
System.out.println(InstanceScope.INSTANCE.getNode("my.custom.preference.node").get("myPref", "nothing"));
- Switch to dark theme
- Call the code again
Sadly, "nothing" is shown both time, indicating that the preference specified in the CSS file is not used. I tracked down some relevant bugs on Bugzilla [3, 4, 5] but still can't figure out why my experiment doesn't work. So, before I fill a new bug, may some of you know if I am facing a bug, if I made a mistake or if I am expecting a behavior that is actually not handled by the extension point?
Note: I tested on both Eclipse Photon and 2019-12.
[1] https://www.eclipse.org/forums/index.php/t/1101735/
[2] https://www.eclipse.org/community/eclipse_newsletter/2018/june/darktheme.php#guide-for-plug-in-developers-to-contribute-to-the-default-dark-theme
[3] https://bugs.eclipse.org/bugs/show_bug.cgi?id=433475
[4] https://bugs.eclipse.org/bugs/show_bug.cgi?id=436183
[5] https://bugs.eclipse.org/bugs/show_bug.cgi?id=544714
|
|
| | |
Re: Specify theme-specific preferences via CSS [message #1818608 is a reply to message #1818600] |
Fri, 20 December 2019 13:23 |
|
It should work, we have multiple implementations out there, which style different preferences. For example, JDT and EGit uses this also. /org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/preference/EclipsePreferencesHandler.java handles this. Maybe you put a breakpoint in it and can debug it. It may be that we still have a bug but its works for others.
Here is for example the EGit css file.
/* ############################## EGIT preferences ############################## */
/* See bug 466075 about the pseudo-selector ":org-eclipse-egit-ui" */
IEclipsePreferences#org-eclipse-ui-workbench:org-eclipse-egit-ui {
preferences:
'org.eclipse.egit.ui.DiffAddBackgroundColor=11,121,90'
'org.eclipse.egit.ui.DiffAddForegroundColor=216,254,245'
'org.eclipse.egit.ui.DiffHeadlineBackgroundColor=71,71,71'
'org.eclipse.egit.ui.DiffHeadlineForegroundColor=242,242,242'
'org.eclipse.egit.ui.DiffHunkBackgroundColor=53,97,113'
'org.eclipse.egit.ui.DiffHunkForegroundColor=233,242,254'
'org.eclipse.egit.ui.DiffRemoveBackgroundColor=117,2,36'
'org.eclipse.egit.ui.DiffRemoveForegroundColor=255,232,237'
'org.eclipse.egit.ui.IgnoredResourceBackgroundColor=42,42,42'
'org.eclipse.egit.ui.IgnoredResourceForegroundColor=120,120,120'
'org.eclipse.egit.ui.UncommittedChangeBackgroundColor=42,42,42'
'org.eclipse.egit.ui.UncommittedChangeForegroundColor=114,157,186'
}
#org-eclipse-egit-ui-StagingView StyledText,
Form Section LayoutComposite StyledText
{
background-color: #313538;
color: #dddddd;
}
PushResultTable-SpellcheckableMessageAreaExtension StyledText {
background-color: #313538;
color: #dddddd;
}
|
|
| |
Goto Forum:
Current Time: Thu Apr 25 07:29:15 GMT 2024
Powered by FUDForum. Page generated in 0.03492 seconds
|