Skip to content

Commit b93d493

Browse files
committed
Provide Explicit "isDarkTheme" Attribute
Up to now we had some heuristics to check if a theme is a dark theme. This now makes this explicit. - Add attribute to extension point - Fill this attribute for the platforms dark theme - Remove heuristics and now check this explicit flag
1 parent 328646d commit b93d493

File tree

5 files changed

+58
-22
lines changed

5 files changed

+58
-22
lines changed

bundles/org.eclipse.e4.ui.css.swt.theme/schema/org.eclipse.e4.ui.css.swt.theme.exsd

+7
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@
134134
</documentation>
135135
</annotation>
136136
</attribute>
137+
<attribute name="isDarkTheme" type="boolean">
138+
<annotation>
139+
<documentation>
140+
Set this to true if the theme uses dark background.
141+
</documentation>
142+
</annotation>
143+
</attribute>
137144
</complexType>
138145
</element>
139146

bundles/org.eclipse.e4.ui.css.swt.theme/src/org/eclipse/e4/ui/css/swt/internal/theme/Theme.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class Theme implements ITheme {
1919
private String id;
2020
private String label;
2121
private String osVersion;
22+
private String isDark;
2223

2324
public Theme(String id, String label) {
2425
this.id = id;
@@ -43,10 +44,23 @@ public String getOsVersion() {
4344
return this.osVersion;
4445
}
4546

47+
@Override
48+
public boolean IsDark() {
49+
return Boolean.parseBoolean(isDark);
50+
}
51+
52+
public void setIsDark(String isDark) {
53+
if (isDark == null) {
54+
this.isDark = "false";
55+
} else {
56+
this.isDark = isDark;
57+
}
58+
}
59+
4660
@Override
4761
public String toString() {
4862
return "Theme [id=" + id + ", label='" + label + "', osVersion="
49-
+ osVersion + "]";
63+
+ osVersion + " isDark=" + isDark + "]";
5064
}
5165

5266

bundles/org.eclipse.e4.ui.css.swt.theme/src/org/eclipse/e4/ui/css/swt/internal/theme/ThemeEngine.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public ThemeEngine(Display display) {
121121
String id = ce.getAttribute("id");
122122
String os = ce.getAttribute("os");
123123
String version = ce.getAttribute("os_version");
124+
String isDarkTheme = ce.getAttribute("isDarkTheme");
124125

125126
/*
126127
* Code to support e4 dark theme on Mac 10.13 and older. For e4 dark theme on
@@ -154,7 +155,8 @@ public ThemeEngine(Display display) {
154155
basestylesheeturi = "platform:/plugin/" + ce.getContributor().getName() + "/"
155156
+ basestylesheeturi;
156157
}
157-
registerTheme(themeId, label, basestylesheeturi, version);
158+
159+
registerTheme(themeId, label, basestylesheeturi, version, isDarkTheme);
158160

159161
//check for modified files
160162
if (modifiedFiles != null) {
@@ -250,11 +252,11 @@ private boolean isOsVersionMatch(String osVersionList) {
250252
@Override
251253
public synchronized ITheme registerTheme(String id, String label, String basestylesheetURI)
252254
throws IllegalArgumentException {
253-
return registerTheme(id, label, basestylesheetURI, "");
255+
return registerTheme(id, label, basestylesheetURI, "", "");
254256
}
255257

256258
public synchronized ITheme registerTheme(String id, String label,
257-
String basestylesheetURI, String osVersion) throws IllegalArgumentException {
259+
String basestylesheetURI, String osVersion, String isDark) throws IllegalArgumentException {
258260
for (Theme t : themes) {
259261
if (t.getId().equals(id)) {
260262
throw new IllegalArgumentException("A theme with the id '" + id
@@ -265,6 +267,9 @@ public synchronized ITheme registerTheme(String id, String label,
265267
if (osVersion != "") {
266268
theme.setOsVersion(osVersion);
267269
}
270+
if (isDark != "") {
271+
theme.setIsDark(isDark);
272+
}
268273
themes.add(theme);
269274
registerStyle(id, basestylesheetURI, false);
270275
return theme;
@@ -598,7 +603,7 @@ public void restore(String alternateTheme) {
598603
}
599604
}
600605

601-
boolean hasDarkTheme = getThemes().stream().anyMatch(t -> t.getId().startsWith(E4_DARK_THEME_ID));
606+
boolean hasDarkTheme = getThemes().stream().anyMatch(t -> t.IsDark());
602607
boolean overrideWithDarkTheme = false;
603608
if (hasDarkTheme) {
604609
if (prefThemeId != null) {

bundles/org.eclipse.e4.ui.css.swt.theme/src/org/eclipse/e4/ui/css/swt/theme/ITheme.java

+6
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,10 @@ public interface ITheme {
2626
* @return the label
2727
*/
2828
String getLabel();
29+
30+
/**
31+
*
32+
* @return does the theme use a dark background color
33+
*/
34+
boolean IsDark();
2935
}

bundles/org.eclipse.ui.themes/plugin.xml

+21-17
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,33 @@
99
label="%theme.classic">
1010
</theme>
1111
<theme
12-
basestylesheeturi="css/e4-dark_linux.css"
13-
id="org.eclipse.e4.ui.css.theme.e4_dark"
14-
label="%theme.dark"
15-
os="linux">
12+
basestylesheeturi="css/e4-dark_linux.css"
13+
id="org.eclipse.e4.ui.css.theme.e4_dark"
14+
isDarkTheme="true"
15+
label="%theme.dark"
16+
os="linux">
1617
</theme>
1718
<theme
18-
basestylesheeturi="css/e4-dark_win.css"
19-
id="org.eclipse.e4.ui.css.theme.e4_dark"
20-
label="%theme.dark"
21-
os="win32">
19+
basestylesheeturi="css/e4-dark_win.css"
20+
id="org.eclipse.e4.ui.css.theme.e4_dark"
21+
isDarkTheme="true"
22+
label="%theme.dark"
23+
os="win32">
2224
</theme>
2325
<theme
24-
basestylesheeturi="css/e4-dark_mac1013.css"
25-
id="org.eclipse.e4.ui.css.theme.e4_dark"
26-
label="%theme.dark"
27-
os="macosx"
28-
os_version="10.11,10.12,10.13">
26+
basestylesheeturi="css/e4-dark_mac1013.css"
27+
id="org.eclipse.e4.ui.css.theme.e4_dark"
28+
isDarkTheme="true"
29+
label="%theme.dark"
30+
os="macosx"
31+
os_version="10.11,10.12,10.13">
2932
</theme>
3033
<theme
31-
basestylesheeturi="css/e4-dark_mac.css"
32-
id="org.eclipse.e4.ui.css.theme.e4_dark"
33-
label="%theme.dark"
34-
os="macosx">
34+
basestylesheeturi="css/e4-dark_mac.css"
35+
id="org.eclipse.e4.ui.css.theme.e4_dark"
36+
isDarkTheme="true"
37+
label="%theme.dark"
38+
os="macosx">
3539
</theme>
3640
<theme
3741
basestylesheeturi="css/e4_default_gtk.css"

0 commit comments

Comments
 (0)