|
10 | 10 | import java.util.Objects; |
11 | 11 | import java.util.SequencedMap; |
12 | 12 | import java.util.Set; |
| 13 | +import java.util.prefs.BackingStoreException; |
13 | 14 | import java.util.stream.Collectors; |
14 | 15 |
|
15 | 16 | import javafx.beans.InvalidationListener; |
|
45 | 46 | import org.jabref.gui.sidepane.SidePaneType; |
46 | 47 | import org.jabref.gui.specialfields.SpecialFieldsPreferences; |
47 | 48 | import org.jabref.gui.theme.Theme; |
| 49 | +import org.jabref.logic.JabRefException; |
48 | 50 | import org.jabref.logic.bst.BstPreviewLayout; |
49 | 51 | import org.jabref.logic.citationstyle.CSLStyleLoader; |
50 | 52 | import org.jabref.logic.citationstyle.CSLStyleUtils; |
@@ -83,7 +85,6 @@ public class JabRefGuiPreferences extends JabRefCliPreferences implements GuiPre |
83 | 85 |
|
84 | 86 | // Public because needed for pref migration |
85 | 87 | public static final String AUTOCOMPLETER_COMPLETE_FIELDS = "autoCompleteFields"; |
86 | | - public static final String MAIN_FONT_SIZE = "mainFontSize"; |
87 | 88 |
|
88 | 89 | // region Preview - public for pref migrations |
89 | 90 | public static final String PREVIEW_STYLE = "previewStyle"; |
@@ -111,6 +112,18 @@ public class JabRefGuiPreferences extends JabRefCliPreferences implements GuiPre |
111 | 112 |
|
112 | 113 | private static final Logger LOGGER = LoggerFactory.getLogger(JabRefGuiPreferences.class); |
113 | 114 |
|
| 115 | + // region WorkspacePreferences |
| 116 | + private static final String OVERRIDE_DEFAULT_FONT_SIZE = "overrideDefaultFontSize"; |
| 117 | + private static final String MAIN_FONT_SIZE = "mainFontSize"; |
| 118 | + private static final String THEME = "fxTheme"; |
| 119 | + private static final String THEME_SYNC_OS = "themeSyncOs"; |
| 120 | + private static final String OPEN_LAST_EDITED = "openLastEdited"; |
| 121 | + private static final String SHOW_ADVANCED_HINTS = "showAdvancedHints"; |
| 122 | + private static final String CONFIRM_DELETE = "confirmDelete"; |
| 123 | + private static final String CONFIRM_HIDE_TAB_BAR = "confirmHideTabBar"; |
| 124 | + private static final String SELECTED_SLR_CATALOGS = "selectedSlrCatalogs"; |
| 125 | + // endregion |
| 126 | + |
114 | 127 | // region core GUI preferences |
115 | 128 | private static final String MAIN_WINDOW_POS_X = "mainWindowPosX"; |
116 | 129 | private static final String MAIN_WINDOW_POS_Y = "mainWindowPosY"; |
@@ -150,16 +163,6 @@ public class JabRefGuiPreferences extends JabRefCliPreferences implements GuiPre |
150 | 163 | private static final String FILE_BROWSER_COMMAND = "fileBrowserCommand"; |
151 | 164 | // endregion |
152 | 165 |
|
153 | | - // region workspace |
154 | | - private static final String THEME = "fxTheme"; |
155 | | - private static final String THEME_SYNC_OS = "themeSyncOs"; |
156 | | - private static final String OPEN_LAST_EDITED = "openLastEdited"; |
157 | | - private static final String OVERRIDE_DEFAULT_FONT_SIZE = "overrideDefaultFontSize"; |
158 | | - private static final String SHOW_ADVANCED_HINTS = "showAdvancedHints"; |
159 | | - private static final String CONFIRM_DELETE = "confirmDelete"; |
160 | | - private static final String CONFIRM_HIDE_TAB_BAR = "confirmHideTabBar"; |
161 | | - // endregion |
162 | | - |
163 | 166 | private static final String ENTRY_EDITOR_HEIGHT = "entryEditorHeightFX"; |
164 | 167 |
|
165 | 168 | /** |
@@ -196,7 +199,6 @@ public class JabRefGuiPreferences extends JabRefCliPreferences implements GuiPre |
196 | 199 | private static final String SPECIALFIELDSENABLED = "specialFieldsEnabled"; |
197 | 200 | // endregion |
198 | 201 |
|
199 | | - private static final String SELECTED_SLR_CATALOGS = "selectedSlrCatalogs"; |
200 | 202 | private static final String UNLINKED_FILES_SELECTED_EXTENSION = "unlinkedFilesSelectedExtension"; |
201 | 203 | private static final String UNLINKED_FILES_SELECTED_DATE_RANGE = "unlinkedFilesSelectedDateRange"; |
202 | 204 | private static final String UNLINKED_FILES_SELECTED_SORT = "unlinkedFilesSelectedSort"; |
@@ -269,17 +271,6 @@ private JabRefGuiPreferences() { |
269 | 271 | defaults.put(AUTOCOMPLETER_COMPLETE_FIELDS, "author;editor;title;journal;publisher;keywords;crossref;related;entryset"); |
270 | 272 | // endregion |
271 | 273 |
|
272 | | - // region workspace |
273 | | - defaults.put(MAIN_FONT_SIZE, 9); |
274 | | - defaults.put(OVERRIDE_DEFAULT_FONT_SIZE, false); |
275 | | - defaults.put(OPEN_LAST_EDITED, Boolean.TRUE); |
276 | | - defaults.put(THEME, Theme.BASE_CSS); |
277 | | - defaults.put(THEME_SYNC_OS, Boolean.FALSE); |
278 | | - defaults.put(CONFIRM_DELETE, Boolean.TRUE); |
279 | | - defaults.put(CONFIRM_HIDE_TAB_BAR, Boolean.TRUE); |
280 | | - defaults.put(SHOW_ADVANCED_HINTS, Boolean.TRUE); |
281 | | - // endregion |
282 | | - |
283 | 274 | // region unlinkedFilesDialogPreferences |
284 | 275 | defaults.put(UNLINKED_FILES_SELECTED_EXTENSION, StandardFileType.ANY_FILE.getName()); |
285 | 276 | defaults.put(UNLINKED_FILES_SELECTED_DATE_RANGE, DateRange.ALL_TIME.name()); |
@@ -429,6 +420,21 @@ public CopyToPreferences getCopyToPreferences() { |
429 | 420 | return copyToPreferences; |
430 | 421 | } |
431 | 422 |
|
| 423 | + @Override |
| 424 | + public void clear() throws BackingStoreException { |
| 425 | + super.clear(); |
| 426 | + |
| 427 | + getWorkspacePreferences().setAll(WorkspacePreferences.getDefault()); |
| 428 | + } |
| 429 | + |
| 430 | + @Override |
| 431 | + public void importPreferences(Path file) throws JabRefException { |
| 432 | + super.importPreferences(file); |
| 433 | + |
| 434 | + // in case of incomplete or corrupt xml fall back to current preferences |
| 435 | + getWorkspacePreferences().setAll(getWorkspacePreferencesFromLowLevelApi(getWorkspacePreferences())); |
| 436 | + } |
| 437 | + |
432 | 438 | // region EntryEditorPreferences |
433 | 439 | public EntryEditorPreferences getEntryEditorPreferences() { |
434 | 440 | if (entryEditorPreferences != null) { |
@@ -641,42 +647,52 @@ public WorkspacePreferences getWorkspacePreferences() { |
641 | 647 | return workspacePreferences; |
642 | 648 | } |
643 | 649 |
|
644 | | - workspacePreferences = new WorkspacePreferences( |
645 | | - getLanguage(), |
646 | | - getBoolean(OVERRIDE_DEFAULT_FONT_SIZE), |
647 | | - getInt(MAIN_FONT_SIZE), |
648 | | - (Integer) defaults.get(MAIN_FONT_SIZE), |
649 | | - new Theme(get(THEME)), |
650 | | - getBoolean(THEME_SYNC_OS), |
651 | | - getBoolean(OPEN_LAST_EDITED), |
652 | | - getBoolean(SHOW_ADVANCED_HINTS), |
653 | | - getBoolean(WARN_ABOUT_DUPLICATES_IN_INSPECTION), |
654 | | - getBoolean(CONFIRM_DELETE), |
655 | | - getBoolean(CONFIRM_HIDE_TAB_BAR), |
656 | | - getStringList(SELECTED_SLR_CATALOGS)); |
| 650 | + workspacePreferences = getWorkspacePreferencesFromLowLevelApi(WorkspacePreferences.getDefault()); |
657 | 651 |
|
658 | | - EasyBind.listen(workspacePreferences.languageProperty(), (obs, oldValue, newValue) -> { |
| 652 | + EasyBind.listen(workspacePreferences.languageProperty(), (_, oldValue, newValue) -> { |
659 | 653 | put(LANGUAGE, newValue.getId()); |
660 | 654 | if (oldValue != newValue) { |
661 | 655 | setLanguageDependentDefaultValues(); |
662 | 656 | Localization.setLanguage(newValue); |
663 | 657 | } |
664 | 658 | }); |
665 | 659 |
|
666 | | - EasyBind.listen(workspacePreferences.shouldOverrideDefaultFontSizeProperty(), (obs, oldValue, newValue) -> putBoolean(OVERRIDE_DEFAULT_FONT_SIZE, newValue)); |
667 | | - EasyBind.listen(workspacePreferences.mainFontSizeProperty(), (obs, oldValue, newValue) -> putInt(MAIN_FONT_SIZE, newValue)); |
668 | | - EasyBind.listen(workspacePreferences.themeProperty(), (obs, oldValue, newValue) -> put(THEME, newValue.getName())); |
669 | | - EasyBind.listen(workspacePreferences.themeSyncOsProperty(), (obs, oldValue, newValue) -> putBoolean(THEME_SYNC_OS, newValue)); |
670 | | - EasyBind.listen(workspacePreferences.openLastEditedProperty(), (obs, oldValue, newValue) -> putBoolean(OPEN_LAST_EDITED, newValue)); |
671 | | - EasyBind.listen(workspacePreferences.showAdvancedHintsProperty(), (obs, oldValue, newValue) -> putBoolean(SHOW_ADVANCED_HINTS, newValue)); |
672 | | - EasyBind.listen(workspacePreferences.warnAboutDuplicatesInInspectionProperty(), (obs, oldValue, newValue) -> putBoolean(WARN_ABOUT_DUPLICATES_IN_INSPECTION, newValue)); |
673 | | - EasyBind.listen(workspacePreferences.confirmDeleteProperty(), (obs, oldValue, newValue) -> putBoolean(CONFIRM_DELETE, newValue)); |
674 | | - EasyBind.listen(workspacePreferences.hideTabBarProperty(), (obs, oldValue, newValue) -> putBoolean(CONFIRM_HIDE_TAB_BAR, newValue)); |
675 | | - workspacePreferences.getSelectedSlrCatalogs().addListener((ListChangeListener<String>) change -> |
| 660 | + EasyBind.listen(workspacePreferences.shouldOverrideDefaultFontSizeProperty(), (_, _, newValue) -> |
| 661 | + putBoolean(OVERRIDE_DEFAULT_FONT_SIZE, newValue)); |
| 662 | + EasyBind.listen(workspacePreferences.mainFontSizeProperty(), (_, _, newValue) -> |
| 663 | + putInt(MAIN_FONT_SIZE, newValue)); |
| 664 | + EasyBind.listen(workspacePreferences.themeProperty(), (_, _, newValue) -> |
| 665 | + put(THEME, newValue.getName())); |
| 666 | + EasyBind.listen(workspacePreferences.themeSyncOsProperty(), (_, _, newValue) -> |
| 667 | + putBoolean(THEME_SYNC_OS, newValue)); |
| 668 | + EasyBind.listen(workspacePreferences.openLastEditedProperty(), (_, _, newValue) -> |
| 669 | + putBoolean(OPEN_LAST_EDITED, newValue)); |
| 670 | + EasyBind.listen(workspacePreferences.showAdvancedHintsProperty(), (_, _, newValue) -> |
| 671 | + putBoolean(SHOW_ADVANCED_HINTS, newValue)); |
| 672 | + EasyBind.listen(workspacePreferences.confirmDeleteProperty(), (_, _, newValue) -> |
| 673 | + putBoolean(CONFIRM_DELETE, newValue)); |
| 674 | + EasyBind.listen(workspacePreferences.hideTabBarProperty(), (_, _, newValue) -> |
| 675 | + putBoolean(CONFIRM_HIDE_TAB_BAR, newValue)); |
| 676 | + workspacePreferences.getSelectedSlrCatalogs().addListener((ListChangeListener<String>) _ -> |
676 | 677 | putStringList(SELECTED_SLR_CATALOGS, workspacePreferences.getSelectedSlrCatalogs())); |
677 | 678 | return workspacePreferences; |
678 | 679 | } |
679 | 680 |
|
| 681 | + private WorkspacePreferences getWorkspacePreferencesFromLowLevelApi(WorkspacePreferences defaults) { |
| 682 | + return new WorkspacePreferences( |
| 683 | + getLanguage(), |
| 684 | + getBoolean(OVERRIDE_DEFAULT_FONT_SIZE, defaults.shouldOverrideDefaultFontSize()), |
| 685 | + getInt(MAIN_FONT_SIZE, defaults.getMainFontSize()), |
| 686 | + defaults.getDefaultFontSize(), // FixMe |
| 687 | + new Theme(get(THEME, Theme.BASE_CSS)), |
| 688 | + getBoolean(THEME_SYNC_OS, defaults.shouldThemeSyncOs()), |
| 689 | + getBoolean(OPEN_LAST_EDITED, defaults.shouldOpenLastEdited()), |
| 690 | + getBoolean(SHOW_ADVANCED_HINTS, defaults.shouldShowAdvancedHints()), |
| 691 | + getBoolean(CONFIRM_DELETE, defaults.shouldConfirmDelete()), |
| 692 | + getBoolean(CONFIRM_HIDE_TAB_BAR, defaults.shouldHideTabBar()), |
| 693 | + getStringList(SELECTED_SLR_CATALOGS)); |
| 694 | + } |
| 695 | + |
680 | 696 | @Override |
681 | 697 | public UnlinkedFilesDialogPreferences getUnlinkedFilesDialogPreferences() { |
682 | 698 | if (unlinkedFilesDialogPreferences != null) { |
|
0 commit comments