From f402fd2aed97c36d6ef56f6fac4e2e080ae5f2a8 Mon Sep 17 00:00:00 2001 From: Nils Streijffert Date: Wed, 26 Feb 2020 11:45:03 +0100 Subject: [PATCH 01/18] feat/#1 Add CSS file type, add button in preferences to import custom CSS file, started on import functionality --- .../gui/preferences/PreferencesDialog.fxml | 5 ++++ .../preferences/PreferencesDialogView.java | 3 +++ .../PreferencesDialogViewModel.java | 23 +++++++++++++++++++ .../jabref/logic/util/StandardFileType.java | 3 ++- src/main/resources/l10n/JabRef_en.properties | 4 ++++ 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/preferences/PreferencesDialog.fxml b/src/main/java/org/jabref/gui/preferences/PreferencesDialog.fxml index d7ee3befc3e..7d338e58e53 100644 --- a/src/main/java/org/jabref/gui/preferences/PreferencesDialog.fxml +++ b/src/main/java/org/jabref/gui/preferences/PreferencesDialog.fxml @@ -39,6 +39,11 @@ diff --git a/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java b/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java index b40a039ded6..046cd965092 100644 --- a/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java +++ b/src/main/java/org/jabref/gui/preferences/PreferencesDialogView.java @@ -114,4 +114,7 @@ private void savePreferencesAndCloseDialog() { @FXML void resetPreferences() { viewModel.resetPreferences(); } + + @FXML + void importStyle() {viewModel.importCSSFile();} } diff --git a/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java b/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java index 1d2bfb61bc6..0a90a0b4d38 100644 --- a/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/PreferencesDialogViewModel.java @@ -195,4 +195,27 @@ public void setValues() { preferencesTab.setValues(); } } + + public void importCSSFile() { + FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() + .addExtensionFilter(StandardFileType.CSS) + .withDefaultExtension(StandardFileType.CSS) + .withInitialDirectory(preferences.setLastPreferencesExportPath()).build(); + + dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(file -> { + try { + preferences.importPreferences(file); + updateAfterPreferenceChanges(); + + dialogService.showWarningDialogAndWait(Localization.lang("Import CSS"), + Localization.lang("You must restart JabRef for this to come into effect.")); + } catch (JabRefException ex) { + LOGGER.error("Error while importing preferences", ex); + dialogService.showErrorDialogAndWait(Localization.lang("Import CSS"), ex); + } + }); + } + + public void updateCSS() { + } } diff --git a/src/main/java/org/jabref/logic/util/StandardFileType.java b/src/main/java/org/jabref/logic/util/StandardFileType.java index e89aa27982f..b6c83787ea6 100644 --- a/src/main/java/org/jabref/logic/util/StandardFileType.java +++ b/src/main/java/org/jabref/logic/util/StandardFileType.java @@ -38,7 +38,8 @@ public enum StandardFileType implements FileType { XML("xml"), JSON("json"), XMP("xmp"), - ZIP("zip"); + ZIP("zip"), + CSS("css"); private final List extensions; diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 5e1bd848dbd..795f643e6da 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -456,6 +456,10 @@ Importing=Importing Importing\ in\ unknown\ format=Importing in unknown format +Import\ CSS=Import CSS file + +Import\ custom\ CSS\ file=Import custom CSS file + Include\ subgroups\:\ When\ selected,\ view\ entries\ contained\ in\ this\ group\ or\ its\ subgroups=Include subgroups: When selected, view entries contained in this group or its subgroups Independent\ group\:\ When\ selected,\ view\ only\ this\ group's\ entries=Independent group: When selected, view only this group's entries From 7bf2fede2ba484ba81a28f8b20c3c06f27498b0d Mon Sep 17 00:00:00 2001 From: Nils Streijffert Date: Wed, 26 Feb 2020 11:51:32 +0100 Subject: [PATCH 02/18] feat/#1 Change so that the log messages uses format specifiers instead of string concatenation --- src/main/java/org/jabref/gui/util/ThemeLoader.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/gui/util/ThemeLoader.java b/src/main/java/org/jabref/gui/util/ThemeLoader.java index 17065eb74a1..0e5e92b4c24 100644 --- a/src/main/java/org/jabref/gui/util/ThemeLoader.java +++ b/src/main/java/org/jabref/gui/util/ThemeLoader.java @@ -50,7 +50,7 @@ public ThemeLoader(FileUpdateMonitor fileUpdateMonitor, JabRefPreferences jabRef String cssPreferences = jabRefPreferences.get(JabRefPreferences.FX_THEME); if (StringUtil.isNotBlank(cssVmArgument)) { // First priority: VM argument - LOGGER.info("Using css from VM option: " + cssVmArgument); + LOGGER.info("Using css from VM option: {}", cssVmArgument); URL cssVmUrl = null; try { cssVmUrl = Paths.get(cssVmArgument).toUri().toURL(); @@ -62,11 +62,11 @@ public ThemeLoader(FileUpdateMonitor fileUpdateMonitor, JabRefPreferences jabRef // Otherwise load css from preference URL cssResource = JabRefFrame.class.getResource(cssPreferences); if (cssResource != null) { - LOGGER.debug("Using css " + cssResource); + LOGGER.debug("Using css {}", cssResource); additionalCssToLoad = Optional.of(cssResource); } else { additionalCssToLoad = Optional.empty(); - LOGGER.warn("Cannot load css " + cssPreferences); + LOGGER.warn("Cannot load css {}", cssPreferences); } } else { additionalCssToLoad = Optional.empty(); From b27f26da12b86e3656bf2bb7440457c37b0c1177 Mon Sep 17 00:00:00 2001 From: Nils Streijffert Date: Wed, 26 Feb 2020 15:57:30 +0100 Subject: [PATCH 03/18] feat/#1 Add RadioButton for toggling custom theme --- .../org/jabref/gui/preferences/AppearanceTab.fxml | 1 + .../jabref/gui/preferences/AppearanceTabView.java | 3 ++- .../gui/preferences/AppearanceTabViewModel.java | 13 ++++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/preferences/AppearanceTab.fxml b/src/main/java/org/jabref/gui/preferences/AppearanceTab.fxml index ed2f9605c5e..ee90e52a715 100644 --- a/src/main/java/org/jabref/gui/preferences/AppearanceTab.fxml +++ b/src/main/java/org/jabref/gui/preferences/AppearanceTab.fxml @@ -29,4 +29,5 @@