Skip to content

Commit cb2e42f

Browse files
committed
Add basic files and settings followed by PR JabRef#9263
- Add "Use System Preference" option under General -> Appearance -> Visual Theme - Add flags to store whether user chose this option - Add SystemThemeDetector.java for auto detect system theme(to do)
1 parent 3702d3a commit cb2e42f

File tree

5 files changed

+52
-7
lines changed

5 files changed

+52
-7
lines changed

src/main/java/org/jabref/gui/preferences/general/GeneralTabViewModel.java

+26-4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ public class GeneralTabViewModel implements PreferenceTabViewModel {
5454
private final ReadOnlyListProperty<ThemeTypes> themesListProperty =
5555
new ReadOnlyListWrapper<>(FXCollections.observableArrayList(ThemeTypes.values()));
5656
private final ObjectProperty<ThemeTypes> selectedThemeProperty = new SimpleObjectProperty<>();
57+
58+
private final BooleanProperty flagWhenAutomaticButtonSelected = new SimpleBooleanProperty();
59+
5760
private final StringProperty customPathToThemeProperty = new SimpleStringProperty();
5861

5962
private final BooleanProperty fontOverrideProperty = new SimpleBooleanProperty();
@@ -125,8 +128,16 @@ public void setValues() {
125128
// The light theme is in fact the absence of any theme modifying 'base.css'. Another embedded theme like
126129
// 'dark.css', stored in the classpath, can be introduced in {@link org.jabref.gui.theme.Theme}.
127130
switch (workspacePreferences.getTheme().getType()) {
128-
case DEFAULT -> selectedThemeProperty.setValue(ThemeTypes.LIGHT);
129-
case EMBEDDED -> selectedThemeProperty.setValue(ThemeTypes.DARK);
131+
case DEFAULT -> {
132+
selectedThemeProperty.setValue(ThemeTypes.LIGHT);
133+
if(workspacePreferences.automaticThemeDetectionFlag().getValue())
134+
selectedThemeProperty.setValue(ThemeTypes.SYNC);
135+
}
136+
case EMBEDDED -> {
137+
selectedThemeProperty.setValue(ThemeTypes.DARK);
138+
if(workspacePreferences.automaticThemeDetectionFlag().getValue())
139+
selectedThemeProperty.setValue(ThemeTypes.SYNC);
140+
}
130141
case CUSTOM -> {
131142
selectedThemeProperty.setValue(ThemeTypes.CUSTOM);
132143
customPathToThemeProperty.setValue(workspacePreferences.getTheme().getName());
@@ -166,8 +177,19 @@ public void storeSettings() {
166177
workspacePreferences.setMainFontSize(Integer.parseInt(fontSizeProperty.getValue()));
167178

168179
switch (selectedThemeProperty.get()) {
169-
case LIGHT -> workspacePreferences.setTheme(Theme.light());
170-
case DARK -> workspacePreferences.setTheme(Theme.dark());
180+
case LIGHT -> {
181+
workspacePreferences.setTheme(Theme.light());
182+
workspacePreferences.setAutomaticThemeDetectionFlag(flagWhenAutomaticButtonSelected.getValue());
183+
}
184+
case DARK -> {
185+
workspacePreferences.setTheme(Theme.dark());
186+
workspacePreferences.setAutomaticThemeDetectionFlag(flagWhenAutomaticButtonSelected.getValue());
187+
}
188+
case SYNC -> {
189+
workspacePreferences.setTheme(Theme.dark());
190+
flagWhenAutomaticButtonSelected.setValue(true);
191+
workspacePreferences.setAutomaticThemeDetectionFlag(flagWhenAutomaticButtonSelected.getValue());
192+
}
171193
case CUSTOM -> workspacePreferences.setTheme(Theme.custom(customPathToThemeProperty.getValue()));
172194
}
173195

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.jabref.gui.theme;
2+
3+
public class SystemThemeDetector {
4+
5+
}

src/main/java/org/jabref/gui/theme/ThemeTypes.java

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public enum ThemeTypes {
66

77
LIGHT(Localization.lang("Light")),
88
DARK(Localization.lang("Dark")),
9+
SYNC(Localization.lang("Use System Preference")),
910
CUSTOM(Localization.lang("Custom..."));
1011

1112
private final String displayName;

src/main/java/org/jabref/preferences/JabRefPreferences.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@ public class JabRefPreferences implements PreferencesService {
417417
// Helper string
418418
private static final String USER_HOME = System.getProperty("user.home");
419419

420+
// System default theme / Auto detect theme constant
421+
private static final String AUTOMATIC_THEME_DETECTION = "automaticThemeDetection";
422+
420423
// Indexes for Strings within stored custom export entries
421424
private static final int EXPORTER_NAME_INDEX = 0;
422425
private static final int EXPORTER_FILENAME_INDEX = 1;
@@ -787,6 +790,8 @@ private JabRefPreferences() {
787790

788791
// set default theme
789792
defaults.put(FX_THEME, Theme.BASE_CSS);
793+
// Set automatic theme detection OFF.
794+
defaults.put(AUTOMATIC_THEME_DETECTION, Boolean.FALSE);
790795
setLanguageDependentDefaultValues();
791796
}
792797

@@ -2086,7 +2091,8 @@ public WorkspacePreferences getWorkspacePreferences() {
20862091
getBoolean(OPEN_LAST_EDITED),
20872092
getBoolean(SHOW_ADVANCED_HINTS),
20882093
getBoolean(WARN_ABOUT_DUPLICATES_IN_INSPECTION),
2089-
getBoolean(CONFIRM_DELETE));
2094+
getBoolean(CONFIRM_DELETE),
2095+
getBoolean(AUTOMATIC_THEME_DETECTION));
20902096

20912097
EasyBind.listen(workspacePreferences.languageProperty(), (obs, oldValue, newValue) -> {
20922098
put(LANGUAGE, newValue.getId());
@@ -2102,7 +2108,7 @@ public WorkspacePreferences getWorkspacePreferences() {
21022108
EasyBind.listen(workspacePreferences.showAdvancedHintsProperty(), (obs, oldValue, newValue) -> putBoolean(SHOW_ADVANCED_HINTS, newValue));
21032109
EasyBind.listen(workspacePreferences.warnAboutDuplicatesInInspectionProperty(), (obs, oldValue, newValue) -> putBoolean(WARN_ABOUT_DUPLICATES_IN_INSPECTION, newValue));
21042110
EasyBind.listen(workspacePreferences.confirmDeleteProperty(), (obs, oldValue, newValue) -> putBoolean(CONFIRM_DELETE, newValue));
2105-
2111+
EasyBind.listen(workspacePreferences.automaticThemeDetectionFlag(), (obs, oldValue, newValue) -> putBoolean(AUTOMATIC_THEME_DETECTION, newValue));
21062112
return workspacePreferences;
21072113
}
21082114

src/main/java/org/jabref/preferences/WorkspacePreferences.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class WorkspacePreferences {
2020
private final BooleanProperty showAdvancedHints;
2121
private final BooleanProperty warnAboutDuplicatesInInspection;
2222
private final BooleanProperty confirmDelete;
23+
private final BooleanProperty automaticThemeDetectionFlag;
2324

2425
public WorkspacePreferences(Language language,
2526
boolean shouldOverrideDefaultFontSize,
@@ -29,7 +30,8 @@ public WorkspacePreferences(Language language,
2930
boolean shouldOpenLastEdited,
3031
boolean showAdvancedHints,
3132
boolean warnAboutDuplicatesInInspection,
32-
boolean confirmDelete) {
33+
boolean confirmDelete,
34+
boolean automaticThemeDetectionFlag) {
3335
this.language = new SimpleObjectProperty<>(language);
3436
this.shouldOverrideDefaultFontSize = new SimpleBooleanProperty(shouldOverrideDefaultFontSize);
3537
this.mainFontSize = new SimpleIntegerProperty(mainFontSize);
@@ -39,6 +41,15 @@ public WorkspacePreferences(Language language,
3941
this.showAdvancedHints = new SimpleBooleanProperty(showAdvancedHints);
4042
this.warnAboutDuplicatesInInspection = new SimpleBooleanProperty(warnAboutDuplicatesInInspection);
4143
this.confirmDelete = new SimpleBooleanProperty(confirmDelete);
44+
this.automaticThemeDetectionFlag = new SimpleBooleanProperty(automaticThemeDetectionFlag);
45+
}
46+
47+
public BooleanProperty automaticThemeDetectionFlag() {
48+
return automaticThemeDetectionFlag;
49+
}
50+
51+
public void setAutomaticThemeDetectionFlag(boolean newValue) {
52+
this.automaticThemeDetectionFlag.setValue(newValue);
4253
}
4354

4455
public Language getLanguage() {

0 commit comments

Comments
 (0)