From d0d3d5ec51a4615799ec017d70de75b7dd52a886 Mon Sep 17 00:00:00 2001 From: Evan Pickett Date: Sat, 20 Nov 2021 12:33:34 -0800 Subject: [PATCH 01/18] Clicking a DOI link in the preview pane no longer crashes (#8255) * Fixed DOI link causing exception; now opens in browser * Added to changelog * Fixed checkstyle issue * Removed awt package references * Browser opens with JabrefDesktop * Switched to using LOGGER --- CHANGELOG.md | 1 + .../org/jabref/gui/preview/PreviewViewer.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51958628e8c..fc3dbcaec25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - The default directory of the "LaTeX Citations" tab is now the directory of the currently opened database (and not the directory chosen at the last open file dialog or the last database save) [koppor#538](https://github.com/koppor/jabref/issues/538) - We fixed an issue where right-clicking on a tab and selecting close will close the focused tab even if it is not the tab we right-clicked [#8193](https://github.com/JabRef/jabref/pull/8193) - We fixed an issue where selecting a citation style in the preferences would sometimes produce an exception [#7860](https://github.com/JabRef/jabref/issues/7860) +- We fixed an issue where an exception would occur when clicking on a DOI link in the preview pane [#7706](https://github.com/JabRef/jabref/issues/7706) ### Removed diff --git a/src/main/java/org/jabref/gui/preview/PreviewViewer.java b/src/main/java/org/jabref/gui/preview/PreviewViewer.java index 56e571c3819..96369916d41 100644 --- a/src/main/java/org/jabref/gui/preview/PreviewViewer.java +++ b/src/main/java/org/jabref/gui/preview/PreviewViewer.java @@ -1,5 +1,7 @@ package org.jabref.gui.preview; +import java.io.IOException; +import java.net.MalformedURLException; import java.util.Objects; import java.util.Optional; import java.util.regex.Pattern; @@ -17,6 +19,7 @@ import org.jabref.gui.DialogService; import org.jabref.gui.Globals; import org.jabref.gui.StateManager; +import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.TaskExecutor; import org.jabref.gui.util.Theme; @@ -30,6 +33,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.events.EventTarget; +import org.w3c.dom.html.HTMLAnchorElement; /** * Displays an BibEntry using the given layout format. @@ -137,6 +144,26 @@ public PreviewViewer(BibDatabaseContext database, DialogService dialogService, S registered = true; } highlightSearchPattern(); + + // https://stackoverflow.com/questions/15555510/javafx-stop-opening-url-in-webview-open-in-browser-instead + NodeList anchorList = previewView.getEngine().getDocument().getElementsByTagName("a"); + for (int i = 0; i < anchorList.getLength(); i++) { + Node node = anchorList.item(i); + EventTarget eventTarget = (EventTarget) node; + eventTarget.addEventListener("click", evt -> { + EventTarget target = evt.getCurrentTarget(); + HTMLAnchorElement anchorElement = (HTMLAnchorElement) target; + String href = anchorElement.getHref(); + try { + JabRefDesktop.openBrowser(href); + } catch (MalformedURLException exception) { + LOGGER.error("Invalid URL", exception); + } catch (IOException exception) { + LOGGER.error("Invalid URL Input", exception); + } + evt.preventDefault(); + }, false); + } }); } From 5c96ddf0852dd1968926220d545cdbff36db5af6 Mon Sep 17 00:00:00 2001 From: Christoph Date: Sun, 21 Nov 2021 12:42:31 +0100 Subject: [PATCH 02/18] Fix some fetcher tests (#8258) --- .../jabref/logic/importer/fetcher/ACMPortalFetcherTest.java | 5 ++--- .../java/org/jabref/logic/importer/fetcher/ArXivTest.java | 4 ++-- .../org/jabref/logic/importer/fetcher/IsbnFetcherTest.java | 2 +- .../logic/importer/fetcher/IsbnViaEbookDeFetcherTest.java | 2 +- .../importer/fileformat/PdfMergeMetadataImporterTest.java | 4 +++- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/jabref/logic/importer/fetcher/ACMPortalFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/ACMPortalFetcherTest.java index 4781ab4fb86..b758f7bcc06 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/ACMPortalFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/ACMPortalFetcherTest.java @@ -12,6 +12,7 @@ import org.jabref.model.entry.types.StandardEntryType; import org.jabref.testutils.category.FetcherTest; +import com.google.common.base.Optional; import org.apache.lucene.queryparser.flexible.core.QueryNodeParseException; import org.apache.lucene.queryparser.flexible.core.parser.SyntaxParser; import org.apache.lucene.queryparser.flexible.standard.parser.StandardSyntaxParser; @@ -20,7 +21,6 @@ import static org.jabref.logic.importer.fetcher.transformers.AbstractQueryTransformer.NO_EXPLICIT_FIELD; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; @FetcherTest class ACMPortalFetcherTest { @@ -57,8 +57,7 @@ void searchByQueryFindsEntry() throws Exception { for (BibEntry bibEntry : fetchedEntries) { bibEntry.clearField(StandardField.ABSTRACT); } - assertFalse(fetchedEntries.isEmpty()); - assertEquals(searchEntry, fetchedEntries.get(0)); + assertEquals(Optional.of(searchEntry), fetchedEntries.stream().findFirst()); } @Test diff --git a/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java b/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java index 018262e1fea..52930702d6e 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/ArXivTest.java @@ -98,7 +98,7 @@ void findFullTextByTitle() throws IOException { void findFullTextByTitleWithCurlyBracket() throws IOException { entry.setField(StandardField.TITLE, "Machine versus {Human} {Attention} in {Deep} {Reinforcement} {Learning} {Tasks}"); - assertEquals(Optional.of(new URL("http://arxiv.org/pdf/2010.15942v2")), fetcher.findFullText(entry)); + assertEquals(Optional.of(new URL("http://arxiv.org/pdf/2010.15942v3")), fetcher.findFullText(entry)); } @Test @@ -130,7 +130,7 @@ void findFullTextByTitleWithCurlyBracketAndPartOfAuthor() throws IOException { entry.setField(StandardField.TITLE, "Machine versus {Human} {Attention} in {Deep} {Reinforcement} {Learning} {Tasks}"); entry.setField(StandardField.AUTHOR, "Zhang, Ruohan and Guo"); - assertEquals(Optional.of(new URL("http://arxiv.org/pdf/2010.15942v2")), fetcher.findFullText(entry)); + assertEquals(Optional.of(new URL("http://arxiv.org/pdf/2010.15942v3")), fetcher.findFullText(entry)); } @Test diff --git a/src/test/java/org/jabref/logic/importer/fetcher/IsbnFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/IsbnFetcherTest.java index 61811fc3819..8554135e268 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/IsbnFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/IsbnFetcherTest.java @@ -38,7 +38,7 @@ void setUp() { bibEntry.setField(StandardField.PUBLISHER, "Addison Wesley"); bibEntry.setField(StandardField.YEAR, "2018"); bibEntry.setField(StandardField.AUTHOR, "Bloch, Joshua"); - bibEntry.setField(StandardField.DATE, "2018-01-01"); + bibEntry.setField(StandardField.DATE, "2018-01-31"); bibEntry.setField(new UnknownField("ean"), "9780134685991"); bibEntry.setField(StandardField.ISBN, "0134685997"); bibEntry.setField(StandardField.URL, "https://www.ebook.de/de/product/28983211/joshua_bloch_effective_java.html"); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaEbookDeFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaEbookDeFetcherTest.java index c7b8a551618..86221b56344 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaEbookDeFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaEbookDeFetcherTest.java @@ -29,7 +29,7 @@ public void setUp() { bibEntry.setField(StandardField.PUBLISHER, "Addison Wesley"); bibEntry.setField(StandardField.YEAR, "2018"); bibEntry.setField(StandardField.AUTHOR, "Bloch, Joshua"); - bibEntry.setField(StandardField.DATE, "2018-01-01"); + bibEntry.setField(StandardField.DATE, "2018-01-31"); bibEntry.setField(new UnknownField("ean"), "9780134685991"); bibEntry.setField(StandardField.ISBN, "0134685997"); bibEntry.setField(StandardField.URL, "https://www.ebook.de/de/product/28983211/joshua_bloch_effective_java.html"); diff --git a/src/test/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporterTest.java index 6bbd6f14406..fbf2eb763dd 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporterTest.java @@ -13,6 +13,7 @@ import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.field.UnknownField; import org.jabref.model.entry.types.StandardEntryType; +import org.jabref.testutils.category.FetcherTest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -22,6 +23,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +@FetcherTest class PdfMergeMetadataImporterTest { private PdfMergeMetadataImporter importer; @@ -71,7 +73,7 @@ void importWorksAsExpected() throws Exception { expected.setField(StandardField.DOI, "10.1002/9781118257517"); // From ISBN (contained on first page verbatim bib entry) - expected.setField(StandardField.DATE, "2018-01-01"); + expected.setField(StandardField.DATE, "2018-01-31"); expected.setField(new UnknownField("ean"), "9780134685991"); expected.setField(StandardField.ISBN, "0134685997"); expected.setField(StandardField.URL, "https://www.ebook.de/de/product/28983211/joshua_bloch_effective_java.html"); From 1d66af62ebee7693d15413e450eb37821f2ec0e2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Nov 2021 19:49:35 +0100 Subject: [PATCH 03/18] Bump classgraph from 4.8.130 to 4.8.135 (#8268) Bumps [classgraph](https://github.com/classgraph/classgraph) from 4.8.130 to 4.8.135. - [Release notes](https://github.com/classgraph/classgraph/releases) - [Commits](https://github.com/classgraph/classgraph/compare/classgraph-4.8.130...classgraph-4.8.135) --- updated-dependencies: - dependency-name: io.github.classgraph:classgraph dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 3818d82bb2e..b2b6e74d4fc 100644 --- a/build.gradle +++ b/build.gradle @@ -207,7 +207,7 @@ dependencies { implementation group: 'net.harawata', name: 'appdirs', version: '1.2.1' - testImplementation 'io.github.classgraph:classgraph:4.8.130' + testImplementation 'io.github.classgraph:classgraph:4.8.135' testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1' testImplementation 'org.junit.platform:junit-platform-launcher:1.8.1' From 354c961ddc036dd69dc4c0c74909936b4bfa6f44 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Nov 2021 19:50:18 +0100 Subject: [PATCH 04/18] Bump mockito-core from 4.0.0 to 4.1.0 (#8267) Bumps [mockito-core](https://github.com/mockito/mockito) from 4.0.0 to 4.1.0. - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v4.0.0...v4.1.0) --- updated-dependencies: - dependency-name: org.mockito:mockito-core dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index b2b6e74d4fc..c0137f2ee88 100644 --- a/build.gradle +++ b/build.gradle @@ -214,7 +214,7 @@ dependencies { testImplementation 'net.bytebuddy:byte-buddy-parent:1.12.1' testRuntimeOnly group: 'org.apache.logging.log4j', name: 'log4j-core', version: '3.0.0-SNAPSHOT' testRuntimeOnly group: 'org.apache.logging.log4j', name: 'log4j-jul', version: '3.0.0-SNAPSHOT' - testImplementation 'org.mockito:mockito-core:4.0.0' + testImplementation 'org.mockito:mockito-core:4.1.0' testImplementation 'org.xmlunit:xmlunit-core:2.8.3' testImplementation 'org.xmlunit:xmlunit-matchers:2.8.3' testRuntimeOnly 'com.tngtech.archunit:archunit-junit5-engine:0.22.0' From 66667f3c79484bd2b1a7786e3e91e9ffb330862e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Nov 2021 19:50:29 +0100 Subject: [PATCH 05/18] Bump checkstyle from 9.0.1 to 9.1 (#8266) Bumps [checkstyle](https://github.com/checkstyle/checkstyle) from 9.0.1 to 9.1. - [Release notes](https://github.com/checkstyle/checkstyle/releases) - [Commits](https://github.com/checkstyle/checkstyle/compare/checkstyle-9.0.1...checkstyle-9.1) --- updated-dependencies: - dependency-name: com.puppycrawl.tools:checkstyle dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index c0137f2ee88..ba1c9f958b3 100644 --- a/build.gradle +++ b/build.gradle @@ -223,7 +223,7 @@ dependencies { testImplementation "org.testfx:testfx-junit5:4.0.17-alpha-SNAPSHOT" testImplementation "org.hamcrest:hamcrest-library:2.2" - checkstyle 'com.puppycrawl.tools:checkstyle:9.0.1' + checkstyle 'com.puppycrawl.tools:checkstyle:9.1' xjc group: 'org.glassfish.jaxb', name: 'jaxb-xjc', version: '2.3.3' } From ab13b2a7040b4a4f276efa1af05f6df307f5f249 Mon Sep 17 00:00:00 2001 From: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com> Date: Mon, 22 Nov 2021 19:50:51 +0100 Subject: [PATCH 06/18] Observable Preferences H (WorkingDir, getUser, NameFormatter, Version, SpecialFields) (#8260) * Refactored setWorkingDirectory * Refactored getWorkingDirectory and getUser and fixed minor ide suggestions * Refactored NameFormatterPreferences * Refactored VersionPreferences * Refactored SpecialFieldsPreferences, removed orphaned autosync prefs * Fixed Checkstyle and tests * Fixed l10n * Fixed test --- .../org/jabref/cli/ArgumentProcessor.java | 24 ++-- src/main/java/org/jabref/gui/JabRefFrame.java | 29 ++--- src/main/java/org/jabref/gui/JabRefGUI.java | 4 +- src/main/java/org/jabref/gui/LibraryTab.java | 3 - .../jabref/gui/auximport/FromAuxDialog.java | 2 +- .../gui/copyfiles/CopySingleFileAction.java | 14 +-- .../LatexCitationsTabViewModel.java | 16 +-- .../gui/exporter/SaveDatabaseAction.java | 4 +- .../UnlinkedFilesDialogViewModel.java | 21 ++-- .../gui/fieldeditors/LinkedFilesEditor.java | 2 +- .../LinkedFilesEditorViewModel.java | 2 +- .../gui/groups/GroupDialogViewModel.java | 10 +- .../org/jabref/gui/help/NewVersionDialog.java | 8 +- .../gui/help/SearchForUpdateAction.java | 2 +- .../org/jabref/gui/help/VersionWorker.java | 21 ++-- .../importer/actions/OpenDatabaseAction.java | 6 +- .../LibraryPropertiesDialogViewModel.java | 14 +-- .../gui/linkedfile/AttachFileAction.java | 14 +-- .../linkedfile/LinkedFileEditDialogView.java | 4 +- .../LinkedFilesEditDialogViewModel.java | 16 +-- .../jabref/gui/maintable/RightClickMenu.java | 16 ++- .../StyleSelectDialogViewModel.java | 2 +- .../CustomImporterTabViewModel.java | 2 +- .../linkedfiles/LinkedFilesTabViewModel.java | 18 ++- .../nameformatter/NameFormatterTab.java | 2 +- .../NameFormatterTabViewModel.java | 22 ++-- .../NewProtectedTermsFileDialog.java | 6 +- .../ProtectedTermsTabViewModel.java | 4 +- .../gui/preferences/table/TableTab.fxml | 12 -- .../gui/preferences/table/TableTab.java | 4 - .../preferences/table/TableTabViewModel.java | 37 +----- .../gui/push/AbstractPushToApplication.java | 2 +- .../gui/push/PushToApplicationSettings.java | 6 +- .../java/org/jabref/gui/push/PushToEmacs.java | 2 +- .../jabref/gui/push/PushToEmacsSettings.java | 6 +- .../java/org/jabref/gui/push/PushToLyx.java | 2 +- .../jabref/gui/push/PushToLyxSettings.java | 6 +- .../java/org/jabref/gui/push/PushToVim.java | 2 +- .../jabref/gui/push/PushToVimSettings.java | 6 +- .../shared/SharedDatabaseLoginDialogView.java | 14 +-- .../SharedDatabaseLoginDialogViewModel.java | 53 +++++---- .../gui/slr/ExistingStudySearchAction.java | 4 +- .../SpecialFieldDatabaseChangeListener.java | 35 ------ .../SpecialFieldMenuItemFactory.java | 7 +- .../SpecialFieldsPreferences.java | 27 ++--- .../texparser/ParseLatexDialogViewModel.java | 6 +- .../importer/ImportFormatPreferences.java | 13 +-- .../format/NameFormatterPreferences.java | 25 +++- .../org/jabref/logic/util/io/FileUtil.java | 9 +- .../jabref/preferences/FilePreferences.java | 19 ++- .../jabref/preferences/JabRefPreferences.java | 109 ++++++++---------- .../preferences/PreferencesService.java | 19 --- .../preferences/VersionPreferences.java | 15 ++- src/main/resources/l10n/JabRef_en.properties | 5 - .../gui/exporter/SaveDatabaseActionTest.java | 16 +-- .../gui/groups/GroupDialogViewModelTest.java | 8 +- .../org/jabref/logic/crawler/CrawlerTest.java | 1 - .../StudyDatabaseToFetcherConverterTest.java | 1 - .../logic/crawler/StudyRepositoryTest.java | 1 - 59 files changed, 337 insertions(+), 423 deletions(-) delete mode 100644 src/main/java/org/jabref/gui/specialfields/SpecialFieldDatabaseChangeListener.java diff --git a/src/main/java/org/jabref/cli/ArgumentProcessor.java b/src/main/java/org/jabref/cli/ArgumentProcessor.java index 74b9c84d3c2..37009e28f25 100644 --- a/src/main/java/org/jabref/cli/ArgumentProcessor.java +++ b/src/main/java/org/jabref/cli/ArgumentProcessor.java @@ -310,20 +310,20 @@ private void writeMetadatatoPDFsOfEntry(BibDatabaseContext databaseContext, Stri try { if (writeXMP) { if (xmpPdfExporter.exportToAllFilesOfEntry(databaseContext, encoding, filePreferences, entry, List.of(entry))) { - System.out.println(String.format("Successfully written XMP metadata on at least one linked file of %s", citeKey)); + System.out.printf("Successfully written XMP metadata on at least one linked file of %s%n", citeKey); } else { - System.err.println(String.format("Cannot write XMP metadata on any linked files of %s. Make sure there is at least one linked file and the path is correct.", citeKey)); + System.err.printf("Cannot write XMP metadata on any linked files of %s. Make sure there is at least one linked file and the path is correct.%n", citeKey); } } if (embeddBibfile) { if (embeddedBibFilePdfExporter.exportToAllFilesOfEntry(databaseContext, encoding, filePreferences, entry, List.of(entry))) { - System.out.println(String.format("Successfully embedded metadata on at least one linked file of %s", citeKey)); + System.out.printf("Successfully embedded metadata on at least one linked file of %s%n", citeKey); } else { - System.out.println(String.format("Cannot embedd metadata on any linked files of %s. Make sure there is at least one linked file and the path is correct.", citeKey)); + System.out.printf("Cannot embedd metadata on any linked files of %s. Make sure there is at least one linked file and the path is correct.%n", citeKey); } } } catch (Exception e) { - LOGGER.error(String.format("Failed writing metadata on a linked file of %s.", citeKey)); + LOGGER.error("Failed writing metadata on a linked file of {}.", citeKey); } } @@ -331,7 +331,7 @@ private void writeMetadatatoPdfByCitekey(BibDatabaseContext databaseContext, Bib for (String citeKey : citeKeys) { List bibEntryList = dataBase.getEntriesByCitationKey(citeKey); if (bibEntryList.isEmpty()) { - System.err.println(String.format("Skipped - Cannot find %s in library.", citeKey)); + System.err.printf("Skipped - Cannot find %s in library.%n", citeKey); continue; } for (BibEntry entry : bibEntryList) { @@ -350,25 +350,25 @@ private void writeMetadatatoPdfByFileNames(BibDatabaseContext databaseContext, B try { if (writeXMP) { if (xmpPdfExporter.exportToFileByPath(databaseContext, dataBase, encoding, filePreferences, filePath)) { - System.out.println(String.format("Successfully written XMP metadata of at least one entry to %s", fileName)); + System.out.printf("Successfully written XMP metadata of at least one entry to %s%n", fileName); } else { - System.out.println(String.format("File %s is not linked to any entry in database.", fileName)); + System.out.printf("File %s is not linked to any entry in database.%n", fileName); } } if (embeddBibfile) { if (embeddedBibFilePdfExporter.exportToFileByPath(databaseContext, dataBase, encoding, filePreferences, filePath)) { - System.out.println(String.format("Successfully embedded XMP metadata of at least one entry to %s", fileName)); + System.out.printf("Successfully embedded XMP metadata of at least one entry to %s%n", fileName); } else { - System.out.println(String.format("File %s is not linked to any entry in database.", fileName)); + System.out.printf("File %s is not linked to any entry in database.%n", fileName); } } } catch (IOException e) { LOGGER.error("Error accessing file '{}'.", fileName); } catch (Exception e) { - LOGGER.error(String.format("Error writing entry to %s.", fileName)); + LOGGER.error("Error writing entry to {}.", fileName); } } else { - LOGGER.error(String.format("Skipped - PDF %s does not exist", fileName)); + LOGGER.error("Skipped - PDF {} does not exist", fileName); } } } diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 073371ea4bf..bc911a31ac2 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -754,19 +754,20 @@ private MenuBar createMenu() { factory.createMenuItem(StandardActions.MASS_SET_FIELDS, new MassSetFieldsAction(stateManager, dialogService, undoManager)) ); - if (prefs.getSpecialFieldsPreferences().isSpecialFieldsEnabled()) { - edit.getItems().addAll( - new SeparatorMenuItem(), - // ToDo: SpecialField needs the active BasePanel to mark it as changed. - // Refactor BasePanel, should mark the BibDatabaseContext or the UndoManager as dirty instead! - SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, this, dialogService, prefs, undoManager, stateManager), - SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, this, dialogService, prefs, undoManager, stateManager), - SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, this, dialogService, prefs, undoManager, stateManager), - SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, this, dialogService, prefs, undoManager, stateManager), - SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, this, dialogService, prefs, undoManager, stateManager), - SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, this, dialogService, prefs, undoManager, stateManager) - ); - } + SeparatorMenuItem specialFieldsSeparator = new SeparatorMenuItem(); + specialFieldsSeparator.visibleProperty().bind(prefs.getSpecialFieldsPreferences().specialFieldsEnabledProperty()); + + edit.getItems().addAll( + specialFieldsSeparator, + // ToDo: SpecialField needs the active BasePanel to mark it as changed. + // Refactor BasePanel, should mark the BibDatabaseContext or the UndoManager as dirty instead! + SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, this, dialogService, prefs, undoManager, stateManager), + SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, this, dialogService, prefs, undoManager, stateManager), + SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, this, dialogService, prefs, undoManager, stateManager), + SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, this, dialogService, prefs, undoManager, stateManager), + SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, this, dialogService, prefs, undoManager, stateManager), + SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, this, dialogService, prefs, undoManager, stateManager) + ); // @formatter:off library.getItems().addAll( @@ -1192,7 +1193,7 @@ private Boolean confirmEmptyEntry(LibraryTab libraryTab, BibDatabaseContext cont if (response.isPresent() && response.get().equals(deleteEmptyEntries)) { // The user wants to delete. try { - for (BibEntry currentEntry : new ArrayList(context.getEntries())) { + for (BibEntry currentEntry : new ArrayList<>(context.getEntries())) { if (currentEntry.getFields().isEmpty()) { context.getDatabase().removeEntries(Collections.singletonList(currentEntry)); } diff --git a/src/main/java/org/jabref/gui/JabRefGUI.java b/src/main/java/org/jabref/gui/JabRefGUI.java index c139ae93a26..4edab4cd9ff 100644 --- a/src/main/java/org/jabref/gui/JabRefGUI.java +++ b/src/main/java/org/jabref/gui/JabRefGUI.java @@ -59,9 +59,9 @@ public JabRefGUI(Stage mainStage, List databases, boolean isBlank, openWindow(mainStage); new VersionWorker(Globals.BUILD_INFO.version, - preferencesService.getVersionPreferences().getIgnoredVersion(), mainFrame.getDialogService(), - Globals.TASK_EXECUTOR) + Globals.TASK_EXECUTOR, + preferencesService.getVersionPreferences()) .checkForNewVersionDelayed(); } diff --git a/src/main/java/org/jabref/gui/LibraryTab.java b/src/main/java/org/jabref/gui/LibraryTab.java index 2e75f23a18f..cf5504b591f 100644 --- a/src/main/java/org/jabref/gui/LibraryTab.java +++ b/src/main/java/org/jabref/gui/LibraryTab.java @@ -31,7 +31,6 @@ import org.jabref.gui.importer.actions.OpenDatabaseAction; import org.jabref.gui.maintable.MainTable; import org.jabref.gui.maintable.MainTableDataModel; -import org.jabref.gui.specialfields.SpecialFieldDatabaseChangeListener; import org.jabref.gui.undo.CountingUndoManager; import org.jabref.gui.undo.NamedCompound; import org.jabref.gui.undo.UndoableFieldChange; @@ -465,8 +464,6 @@ public void editEntryAndFocusField(BibEntry entry, Field field) { } private void createMainTable() { - bibDatabaseContext.getDatabase().registerListener(SpecialFieldDatabaseChangeListener.INSTANCE); - mainTable = new MainTable(tableModel, this, bibDatabaseContext, diff --git a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java index 7280deb9819..ae7de0b43e0 100644 --- a/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java +++ b/src/main/java/org/jabref/gui/auximport/FromAuxDialog.java @@ -93,7 +93,7 @@ private void browseButtonClicked() { FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .addExtensionFilter(StandardFileType.AUX) .withDefaultExtension(StandardFileType.AUX) - .withInitialDirectory(preferences.getWorkingDir()).build(); + .withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()).build(); dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(file -> auxFileField.setText(file.toAbsolutePath().toString())); } } diff --git a/src/main/java/org/jabref/gui/copyfiles/CopySingleFileAction.java b/src/main/java/org/jabref/gui/copyfiles/CopySingleFileAction.java index 72ec5c64266..29bc0716b59 100644 --- a/src/main/java/org/jabref/gui/copyfiles/CopySingleFileAction.java +++ b/src/main/java/org/jabref/gui/copyfiles/CopySingleFileAction.java @@ -14,40 +14,40 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.LinkedFile; import org.jabref.model.util.OptionalUtil; -import org.jabref.preferences.PreferencesService; +import org.jabref.preferences.FilePreferences; public class CopySingleFileAction extends SimpleCommand { private final LinkedFile linkedFile; private final DialogService dialogService; private final BibDatabaseContext databaseContext; - private final PreferencesService preferencesService; + private final FilePreferences filePreferences; private final BiFunction resolvePathFilename = (path, file) -> path.resolve(file.getFileName()); - public CopySingleFileAction(LinkedFile linkedFile, DialogService dialogService, BibDatabaseContext databaseContext, PreferencesService preferencesService) { + public CopySingleFileAction(LinkedFile linkedFile, DialogService dialogService, BibDatabaseContext databaseContext, FilePreferences filePreferences) { this.linkedFile = linkedFile; this.dialogService = dialogService; this.databaseContext = databaseContext; - this.preferencesService = preferencesService; + this.filePreferences = filePreferences; this.executable.bind(Bindings.createBooleanBinding( () -> !linkedFile.isOnlineLink() - && linkedFile.findIn(databaseContext, preferencesService.getFilePreferences()).isPresent(), + && linkedFile.findIn(databaseContext, this.filePreferences).isPresent(), linkedFile.linkProperty())); } @Override public void execute() { DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder() - .withInitialDirectory(preferencesService.getWorkingDir()) + .withInitialDirectory(filePreferences.getWorkingDirectory()) .build(); Optional exportPath = dialogService.showDirectorySelectionDialog(dirDialogConfiguration); exportPath.ifPresent(this::copyFileToDestination); } private void copyFileToDestination(Path exportPath) { - Optional fileToExport = linkedFile.findIn(databaseContext, preferencesService.getFilePreferences()); + Optional fileToExport = linkedFile.findIn(databaseContext, filePreferences); Optional newPath = OptionalUtil.combine(Optional.of(exportPath), fileToExport, resolvePathFilename); if (newPath.isPresent()) { diff --git a/src/main/java/org/jabref/gui/entryeditor/LatexCitationsTabViewModel.java b/src/main/java/org/jabref/gui/entryeditor/LatexCitationsTabViewModel.java index 7673eb62d2b..fbfbb5c37e3 100644 --- a/src/main/java/org/jabref/gui/entryeditor/LatexCitationsTabViewModel.java +++ b/src/main/java/org/jabref/gui/entryeditor/LatexCitationsTabViewModel.java @@ -60,14 +60,16 @@ enum Status { private LatexParserResult latexParserResult; private BibEntry currentEntry; - public LatexCitationsTabViewModel(BibDatabaseContext databaseContext, PreferencesService preferencesService, - TaskExecutor taskExecutor, DialogService dialogService) { + public LatexCitationsTabViewModel(BibDatabaseContext databaseContext, + PreferencesService preferencesService, + TaskExecutor taskExecutor, + DialogService dialogService) { this.databaseContext = databaseContext; this.preferencesService = preferencesService; this.taskExecutor = taskExecutor; this.dialogService = dialogService; - this.directory = new SimpleObjectProperty(databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getUser()) - .orElse(FileUtil.getInitialDirectory(databaseContext, preferencesService))); + this.directory = new SimpleObjectProperty<>(databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getFilePreferences().getUser()) + .orElse(FileUtil.getInitialDirectory(databaseContext, preferencesService.getFilePreferences().getWorkingDirectory()))); this.citationList = FXCollections.observableArrayList(); this.status = new SimpleObjectProperty<>(Status.IN_PROGRESS); this.searchError = new SimpleStringProperty(""); @@ -128,8 +130,8 @@ private void cancelSearch() { private Collection searchAndParse(String citeKey) throws IOException { // we need to check whether the user meanwhile set the LaTeX file directory or the database changed locations - Path newDirectory = databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getUser()) - .orElse(FileUtil.getInitialDirectory(databaseContext, preferencesService)); + Path newDirectory = databaseContext.getMetaData().getLatexFileDirectory(preferencesService.getFilePreferences().getUser()) + .orElse(FileUtil.getInitialDirectory(databaseContext, preferencesService.getFilePreferences().getWorkingDirectory())); if (latexParserResult == null || !newDirectory.equals(directory.get())) { directory.set(newDirectory); @@ -170,7 +172,7 @@ public void setLatexDirectory() { .withInitialDirectory(directory.get()).build(); dialogService.showDirectorySelectionDialog(directoryDialogConfiguration).ifPresent(selectedDirectory -> - databaseContext.getMetaData().setLatexFileDirectory(preferencesService.getUser(), selectedDirectory.toAbsolutePath())); + databaseContext.getMetaData().setLatexFileDirectory(preferencesService.getFilePreferences().getUser(), selectedDirectory.toAbsolutePath())); init(currentEntry); } diff --git a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java index 9757b885615..5ae882116e9 100644 --- a/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java +++ b/src/main/java/org/jabref/gui/exporter/SaveDatabaseAction.java @@ -160,10 +160,10 @@ private Optional askForSavePath() { FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .addExtensionFilter(StandardFileType.BIBTEX_DB) .withDefaultExtension(StandardFileType.BIBTEX_DB) - .withInitialDirectory(preferences.getWorkingDir()) + .withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()) .build(); Optional selectedPath = dialogService.showFileSaveDialog(fileDialogConfiguration); - selectedPath.ifPresent(path -> preferences.setWorkingDirectory(path.getParent())); + selectedPath.ifPresent(path -> preferences.getFilePreferences().setWorkingDirectory(path.getParent())); if (selectedPath.isPresent()) { Path savePath = selectedPath.get(); // Workaround for linux systems not adding file extension diff --git a/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModel.java b/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModel.java index 69c62af874a..c516be37f86 100644 --- a/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModel.java +++ b/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModel.java @@ -80,8 +80,13 @@ public class UnlinkedFilesDialogViewModel { private final FunctionBasedValidator scanDirectoryValidator; - public UnlinkedFilesDialogViewModel(DialogService dialogService, ExternalFileTypes externalFileTypes, UndoManager undoManager, - FileUpdateMonitor fileUpdateMonitor, PreferencesService preferences, StateManager stateManager, TaskExecutor taskExecutor) { + public UnlinkedFilesDialogViewModel(DialogService dialogService, + ExternalFileTypes externalFileTypes, + UndoManager undoManager, + FileUpdateMonitor fileUpdateMonitor, + PreferencesService preferences, + StateManager stateManager, + TaskExecutor taskExecutor) { this.preferences = preferences; this.dialogService = dialogService; this.taskExecutor = taskExecutor; @@ -95,9 +100,9 @@ public UnlinkedFilesDialogViewModel(DialogService dialogService, ExternalFileTyp stateManager); this.fileFilterList = FXCollections.observableArrayList( - new FileExtensionViewModel(StandardFileType.ANY_FILE, externalFileTypes), - new FileExtensionViewModel(StandardFileType.BIBTEX_DB, externalFileTypes), - new FileExtensionViewModel(StandardFileType.PDF, externalFileTypes)); + new FileExtensionViewModel(StandardFileType.ANY_FILE, externalFileTypes), + new FileExtensionViewModel(StandardFileType.BIBTEX_DB, externalFileTypes), + new FileExtensionViewModel(StandardFileType.PDF, externalFileTypes)); this.dateFilterList = FXCollections.observableArrayList(DateRange.values()); @@ -175,7 +180,7 @@ public void startExport() { } FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() - .withInitialDirectory(preferences.getWorkingDir()) + .withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()) .addExtensionFilter(StandardFileType.TXT) .withDefaultExtension(StandardFileType.TXT) .build(); @@ -218,12 +223,12 @@ public void cancelTasks() { public void browseFileDirectory() { DirectoryDialogConfiguration directoryDialogConfiguration = new DirectoryDialogConfiguration.Builder() - .withInitialDirectory(preferences.getWorkingDir()).build(); + .withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()).build(); dialogService.showDirectorySelectionDialog(directoryDialogConfiguration) .ifPresent(selectedDirectory -> { directoryPath.setValue(selectedDirectory.toAbsolutePath().toString()); - preferences.setWorkingDirectory(selectedDirectory.toAbsolutePath()); + preferences.getFilePreferences().setWorkingDirectory(selectedDirectory.toAbsolutePath()); }); } diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java index a13eeb6a310..36aba630f54 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java @@ -275,7 +275,7 @@ private ContextMenu createContextMenuForFile(LinkedFileViewModel linkedFile) { factory.createMenuItem(StandardActions.RENAME_FILE_TO_NAME, new ContextAction(StandardActions.RENAME_FILE_TO_NAME, linkedFile, preferencesService)), factory.createMenuItem(StandardActions.MOVE_FILE_TO_FOLDER, new ContextAction(StandardActions.MOVE_FILE_TO_FOLDER, linkedFile, preferencesService)), factory.createMenuItem(StandardActions.MOVE_FILE_TO_FOLDER_AND_RENAME, new ContextAction(StandardActions.MOVE_FILE_TO_FOLDER_AND_RENAME, linkedFile, preferencesService)), - factory.createMenuItem(StandardActions.COPY_FILE_TO_FOLDER, new CopySingleFileAction(linkedFile.getFile(), dialogService, databaseContext, preferencesService)), + factory.createMenuItem(StandardActions.COPY_FILE_TO_FOLDER, new CopySingleFileAction(linkedFile.getFile(), dialogService, databaseContext, preferencesService.getFilePreferences())), factory.createMenuItem(StandardActions.REMOVE_LINK, new ContextAction(StandardActions.REMOVE_LINK, linkedFile, preferencesService)), factory.createMenuItem(StandardActions.DELETE_FILE, new ContextAction(StandardActions.DELETE_FILE, linkedFile, preferencesService)) ); diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java index e3f542e4a95..f9c7f1e67e5 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditorViewModel.java @@ -137,7 +137,7 @@ public ListProperty filesProperty() { public void addNewFile() { Path workingDirectory = databaseContext.getFirstExistingFileDir(preferences.getFilePreferences()) - .orElse(preferences.getWorkingDir()); + .orElse(preferences.getFilePreferences().getWorkingDirectory()); FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .withInitialDirectory(workingDirectory) diff --git a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java index 7714fcdcfa0..522d129bb08 100644 --- a/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java +++ b/src/main/java/org/jabref/gui/groups/GroupDialogViewModel.java @@ -83,7 +83,7 @@ public class GroupDialogViewModel { private final BooleanProperty keywordGroupRegexProperty = new SimpleBooleanProperty(); private final StringProperty searchGroupSearchTermProperty = new SimpleStringProperty(""); - private final ObjectProperty> searchFlagsProperty = new SimpleObjectProperty(EnumSet.noneOf(SearchFlags.class)); + private final ObjectProperty> searchFlagsProperty = new SimpleObjectProperty<>(EnumSet.noneOf(SearchFlags.class)); private final BooleanProperty autoGroupKeywordsOptionProperty = new SimpleBooleanProperty(); private final StringProperty autoGroupKeywordsFieldProperty = new SimpleStringProperty(""); @@ -236,7 +236,7 @@ private void setupValidation() { return false; } return FileUtil.getFileExtension(input) - .map(extension -> extension.toLowerCase().equals("aux")) + .map(extension -> extension.equalsIgnoreCase("aux")) .orElse(false); } }, @@ -273,7 +273,7 @@ private void setupValidation() { * @return an absolute path if LatexFileDirectory exists; otherwise, returns input */ private Path getAbsoluteTexGroupPath(String input) { - Optional latexFileDirectory = currentDatabase.getMetaData().getLatexFileDirectory(preferencesService.getUser()); + Optional latexFileDirectory = currentDatabase.getMetaData().getLatexFileDirectory(preferencesService.getFilePreferences().getUser()); return latexFileDirectory.map(path -> path.resolve(input)).orElse(Path.of(input)); } @@ -436,8 +436,8 @@ public void texGroupBrowse() { .addExtensionFilter(StandardFileType.AUX) .withDefaultExtension(StandardFileType.AUX) .withInitialDirectory(currentDatabase.getMetaData() - .getLatexFileDirectory(preferencesService.getUser()) - .orElse(FileUtil.getInitialDirectory(currentDatabase, preferencesService))).build(); + .getLatexFileDirectory(preferencesService.getFilePreferences().getUser()) + .orElse(FileUtil.getInitialDirectory(currentDatabase, preferencesService.getFilePreferences().getWorkingDirectory()))).build(); dialogService.showFileOpenDialog(fileDialogConfiguration) .ifPresent(file -> texGroupFilePathProperty.setValue( FileUtil.relativize(file.toAbsolutePath(), getFileDirectoriesAsPaths()).toString() diff --git a/src/main/java/org/jabref/gui/help/NewVersionDialog.java b/src/main/java/org/jabref/gui/help/NewVersionDialog.java index 5c61943d2aa..2ab73b250a5 100644 --- a/src/main/java/org/jabref/gui/help/NewVersionDialog.java +++ b/src/main/java/org/jabref/gui/help/NewVersionDialog.java @@ -7,14 +7,12 @@ import javafx.scene.control.Label; import javafx.scene.layout.VBox; -import org.jabref.gui.Globals; import org.jabref.gui.desktop.JabRefDesktop; import org.jabref.gui.util.BaseDialog; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.Version; -import org.jabref.preferences.VersionPreferences; -public class NewVersionDialog extends BaseDialog { +public class NewVersionDialog extends BaseDialog { public NewVersionDialog(Version currentVersion, Version latestVersion) { this.setTitle(Localization.lang("New version available")); @@ -25,11 +23,11 @@ public NewVersionDialog(Version currentVersion, Version latestVersion) { this.getDialogPane().getButtonTypes().addAll(btnIgnoreUpdate, btnDownloadUpdate, btnRemindMeLater); this.setResultConverter(button -> { if (button == btnIgnoreUpdate) { - Globals.prefs.storeVersionPreferences(new VersionPreferences(latestVersion)); + return false; } else if (button == btnDownloadUpdate) { JabRefDesktop.openBrowserShowPopup(Version.JABREF_DOWNLOAD_URL); } - return null; + return true; }); Button defaultButton = (Button) this.getDialogPane().lookupButton(btnDownloadUpdate); defaultButton.setDefaultButton(true); diff --git a/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java b/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java index 5e39a0e6d7c..ddf013c2ded 100644 --- a/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java +++ b/src/main/java/org/jabref/gui/help/SearchForUpdateAction.java @@ -22,7 +22,7 @@ public SearchForUpdateAction(BuildInfo buildInfo, VersionPreferences versionPref @Override public void execute() { - new VersionWorker(buildInfo.version, versionPreferences.getIgnoredVersion(), dialogService, taskExecutor) + new VersionWorker(buildInfo.version, dialogService, taskExecutor, versionPreferences) .checkForNewVersionAsync(); } } diff --git a/src/main/java/org/jabref/gui/help/VersionWorker.java b/src/main/java/org/jabref/gui/help/VersionWorker.java index 139565c9df8..e22ed8aa583 100644 --- a/src/main/java/org/jabref/gui/help/VersionWorker.java +++ b/src/main/java/org/jabref/gui/help/VersionWorker.java @@ -11,6 +11,7 @@ import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.Version; +import org.jabref.preferences.VersionPreferences; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,19 +33,19 @@ public class VersionWorker { */ private final Version installedVersion; - /** - * The version which was previously ignored by the user - */ - private final Version toBeIgnored; - private final DialogService dialogService; private final TaskExecutor taskExecutor; + private final VersionPreferences versionPreferences; - public VersionWorker(Version installedVersion, Version toBeIgnored, DialogService dialogService, TaskExecutor taskExecutor) { + public VersionWorker(Version installedVersion, + + DialogService dialogService, + TaskExecutor taskExecutor, + VersionPreferences versionPreferences) { this.installedVersion = Objects.requireNonNull(installedVersion); - this.toBeIgnored = Objects.requireNonNull(toBeIgnored); this.dialogService = Objects.requireNonNull(dialogService); this.taskExecutor = Objects.requireNonNull(taskExecutor); + this.versionPreferences = versionPreferences; } /** @@ -88,13 +89,15 @@ private void showConnectionError(Exception exception, boolean manualExecution) { */ private void showUpdateInfo(Optional newerVersion, boolean manualExecution) { // no new version could be found, only respect the ignored version on automated version checks - if (!newerVersion.isPresent() || (newerVersion.get().equals(toBeIgnored) && !manualExecution)) { + if (newerVersion.isEmpty() || (newerVersion.get().equals(versionPreferences.getIgnoredVersion()) && !manualExecution)) { if (manualExecution) { dialogService.notify(Localization.lang("JabRef is up-to-date.")); } } else { // notify the user about a newer version - dialogService.showCustomDialogAndWait(new NewVersionDialog(installedVersion, newerVersion.get())); + if (dialogService.showCustomDialogAndWait(new NewVersionDialog(installedVersion, newerVersion.get())).orElse(true)) { + versionPreferences.setIgnoredVersion(newerVersion.get()); + } } } } diff --git a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java index bd1bbee5af4..39b22f76f55 100644 --- a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -94,10 +94,10 @@ public void execute() { */ private Path getInitialDirectory() { if (frame.getBasePanelCount() == 0) { - return preferencesService.getWorkingDir(); + return preferencesService.getFilePreferences().getWorkingDirectory(); } else { Optional databasePath = frame.getCurrentLibraryTab().getBibDatabaseContext().getDatabasePath(); - return databasePath.map(Path::getParent).orElse(preferencesService.getWorkingDir()); + return databasePath.map(Path::getParent).orElse(preferencesService.getFilePreferences().getWorkingDirectory()); } } @@ -181,7 +181,7 @@ private ParserResult loadDatabase(Path file) throws Exception { dialogService.notify(Localization.lang("Opening") + ": '" + file + "'"); - preferencesService.setWorkingDirectory(fileToLoad.getParent()); + preferencesService.getFilePreferences().setWorkingDirectory(fileToLoad.getParent()); if (BackupManager.backupFileDiffers(fileToLoad)) { BackupUIManager.showRestoreBackupDialog(dialogService, fileToLoad); diff --git a/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java b/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java index f3a37a6092d..d07206d881b 100644 --- a/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java +++ b/src/main/java/org/jabref/gui/libraryproperties/LibraryPropertiesDialogViewModel.java @@ -75,7 +75,7 @@ public LibraryPropertiesDialogViewModel(BibDatabaseContext databaseContext, Dial this.initialSaveOrderConfig = initialMetaData.getSaveOrderConfig().orElseGet(preferences::getExportSaveOrder); this.directoryDialogConfiguration = new DirectoryDialogConfiguration.Builder() - .withInitialDirectory(preferences.getWorkingDir()).build(); + .withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()).build(); setValues(); } @@ -88,8 +88,8 @@ void setValues() { selectedEncodingPropety.setValue(initialMetaData.getEncoding().orElse(preferences.getGeneralPreferences().getDefaultEncoding())); selectedDatabaseModeProperty.setValue(initialMetaData.getMode().orElse(BibDatabaseMode.BIBLATEX)); generalFileDirectoryProperty.setValue(initialMetaData.getDefaultFileDirectory().orElse("").trim()); - userSpecificFileDirectoryProperty.setValue(initialMetaData.getUserFileDirectory(preferences.getUser()).orElse("").trim()); - laTexFileDirectoryProperty.setValue(initialMetaData.getLatexFileDirectory(preferences.getUser()).map(Path::toString).orElse("")); + userSpecificFileDirectoryProperty.setValue(initialMetaData.getUserFileDirectory(preferences.getFilePreferences().getUser()).orElse("").trim()); + laTexFileDirectoryProperty.setValue(initialMetaData.getLatexFileDirectory(preferences.getFilePreferences().getUser()).map(Path::toString).orElse("")); libraryProtectedProperty.setValue(initialMetaData.isProtected()); // SaveOrderConfigPanel @@ -134,16 +134,16 @@ void storeSettings() { String userSpecificFileDirectory = userSpecificFileDirectoryProperty.getValue(); if (userSpecificFileDirectory.isEmpty()) { - newMetaData.clearUserFileDirectory(preferences.getUser()); + newMetaData.clearUserFileDirectory(preferences.getFilePreferences().getUser()); } else { - newMetaData.setUserFileDirectory(preferences.getUser(), userSpecificFileDirectory); + newMetaData.setUserFileDirectory(preferences.getFilePreferences().getUser(), userSpecificFileDirectory); } String latexFileDirectory = laTexFileDirectoryProperty.getValue(); if (latexFileDirectory.isEmpty()) { - newMetaData.clearLatexFileDirectory(preferences.getUser()); + newMetaData.clearLatexFileDirectory(preferences.getFilePreferences().getUser()); } else { - newMetaData.setLatexFileDirectory(preferences.getUser(), Path.of(latexFileDirectory)); + newMetaData.setLatexFileDirectory(preferences.getFilePreferences().getUser(), Path.of(latexFileDirectory)); } if (libraryProtectedProperty.getValue()) { diff --git a/src/main/java/org/jabref/gui/linkedfile/AttachFileAction.java b/src/main/java/org/jabref/gui/linkedfile/AttachFileAction.java index a0b6ff4602d..00e0c1f3b4b 100644 --- a/src/main/java/org/jabref/gui/linkedfile/AttachFileAction.java +++ b/src/main/java/org/jabref/gui/linkedfile/AttachFileAction.java @@ -17,23 +17,23 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.LinkedFile; -import org.jabref.preferences.PreferencesService; +import org.jabref.preferences.FilePreferences; public class AttachFileAction extends SimpleCommand { private final LibraryTab libraryTab; private final StateManager stateManager; private final DialogService dialogService; - private final PreferencesService preferencesService; + private final FilePreferences filePreferences; public AttachFileAction(LibraryTab libraryTab, DialogService dialogService, StateManager stateManager, - PreferencesService preferencesService) { + FilePreferences filePreferences) { this.libraryTab = libraryTab; this.stateManager = stateManager; this.dialogService = dialogService; - this.preferencesService = preferencesService; + this.filePreferences = filePreferences; this.executable.bind(ActionHelper.needsEntriesSelected(1, stateManager)); } @@ -54,8 +54,8 @@ public void execute() { BibEntry entry = stateManager.getSelectedEntries().get(0); - Path workingDirectory = databaseContext.getFirstExistingFileDir(preferencesService.getFilePreferences()) - .orElse(preferencesService.getWorkingDir()); + Path workingDirectory = databaseContext.getFirstExistingFileDir(filePreferences) + .orElse(filePreferences.getWorkingDirectory()); FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .withInitialDirectory(workingDirectory) @@ -63,7 +63,7 @@ public void execute() { dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(newFile -> { LinkedFile linkedFile = LinkedFilesEditorViewModel.fromFile(newFile, - databaseContext.getFileDirectories(preferencesService.getFilePreferences()), + databaseContext.getFileDirectories(filePreferences), ExternalFileTypes.getInstance()); LinkedFileEditDialogView dialog = new LinkedFileEditDialogView(linkedFile); diff --git a/src/main/java/org/jabref/gui/linkedfile/LinkedFileEditDialogView.java b/src/main/java/org/jabref/gui/linkedfile/LinkedFileEditDialogView.java index 5ea1e9fb344..b470265e78d 100644 --- a/src/main/java/org/jabref/gui/linkedfile/LinkedFileEditDialogView.java +++ b/src/main/java/org/jabref/gui/linkedfile/LinkedFileEditDialogView.java @@ -32,7 +32,7 @@ public class LinkedFileEditDialogView extends BaseDialog { private LinkedFilesEditDialogViewModel viewModel; private final LinkedFile linkedFile; - private ExternalFileTypes externalFileTypes; + private final ExternalFileTypes externalFileTypes; public LinkedFileEditDialogView(LinkedFile linkedFile) { this.linkedFile = linkedFile; @@ -56,7 +56,7 @@ public LinkedFileEditDialogView(LinkedFile linkedFile) { @FXML private void initialize() { - viewModel = new LinkedFilesEditDialogViewModel(linkedFile, stateManager.getActiveDatabase().get(), dialogService, preferences, externalFileTypes); + viewModel = new LinkedFilesEditDialogViewModel(linkedFile, stateManager.getActiveDatabase().get(), dialogService, preferences.getFilePreferences(), externalFileTypes); fileType.itemsProperty().bindBidirectional(viewModel.externalFileTypeProperty()); description.textProperty().bindBidirectional(viewModel.descriptionProperty()); link.textProperty().bindBidirectional(viewModel.linkProperty()); diff --git a/src/main/java/org/jabref/gui/linkedfile/LinkedFilesEditDialogViewModel.java b/src/main/java/org/jabref/gui/linkedfile/LinkedFilesEditDialogViewModel.java index b69789282f9..2d5175bd3d4 100644 --- a/src/main/java/org/jabref/gui/linkedfile/LinkedFilesEditDialogViewModel.java +++ b/src/main/java/org/jabref/gui/linkedfile/LinkedFilesEditDialogViewModel.java @@ -25,7 +25,7 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.LinkedFile; import org.jabref.model.util.FileHelper; -import org.jabref.preferences.PreferencesService; +import org.jabref.preferences.FilePreferences; import com.tobiasdiez.easybind.EasyBind; import com.tobiasdiez.easybind.optional.ObservableOptionalValue; @@ -40,13 +40,13 @@ public class LinkedFilesEditDialogViewModel extends AbstractViewModel { private final ObservableOptionalValue monadicSelectedExternalFileType; private final BibDatabaseContext database; private final DialogService dialogService; - private final PreferencesService preferences; + private final FilePreferences filePreferences; private final ExternalFileTypes externalFileTypes; - public LinkedFilesEditDialogViewModel(LinkedFile linkedFile, BibDatabaseContext database, DialogService dialogService, PreferencesService preferences, ExternalFileTypes externalFileTypes) { + public LinkedFilesEditDialogViewModel(LinkedFile linkedFile, BibDatabaseContext database, DialogService dialogService, FilePreferences filePreferences, ExternalFileTypes externalFileTypes) { this.database = database; this.dialogService = dialogService; - this.preferences = preferences; + this.filePreferences = filePreferences; this.externalFileTypes = externalFileTypes; allExternalFileTypes.set(FXCollections.observableArrayList(externalFileTypes.getExternalFileTypeSelection())); @@ -71,9 +71,9 @@ private void setExternalFileTypeByExtension(String link) { public void openBrowseDialog() { String fileText = link.get(); - Optional file = FileHelper.find(database, fileText, preferences.getFilePreferences()); + Optional file = FileHelper.find(database, fileText, filePreferences); - Path workingDir = file.orElse(preferences.getWorkingDir()); + Path workingDir = file.orElse(filePreferences.getWorkingDirectory()); String fileName = Path.of(fileText).getFileName().toString(); FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() @@ -83,7 +83,7 @@ public void openBrowseDialog() { dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(path -> { // Store the directory for next time: - preferences.setWorkingDirectory(path); + filePreferences.setWorkingDirectory(path); link.set(relativize(path)); setExternalFileTypeByExtension(link.getValueSafe()); @@ -140,7 +140,7 @@ public LinkedFile getNewLinkedFile() { } private String relativize(Path filePath) { - List fileDirectories = database.getFileDirectories(preferences.getFilePreferences()); + List fileDirectories = database.getFileDirectories(filePreferences); return FileUtil.relativize(filePath, fileDirectories).toString(); } } diff --git a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java index de00201399b..31fd414d1b0 100644 --- a/src/main/java/org/jabref/gui/maintable/RightClickMenu.java +++ b/src/main/java/org/jabref/gui/maintable/RightClickMenu.java @@ -57,18 +57,16 @@ public static ContextMenu create(BibEntryTableViewModel entry, contextMenu.getItems().add(new SeparatorMenuItem()); - if (preferencesService.getSpecialFieldsPreferences().isSpecialFieldsEnabled()) { - contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); - contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); - contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); - contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); - contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); - contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); - } + contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.RANKING, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.RELEVANCE, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.QUALITY, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.getSpecialFieldSingleItem(SpecialField.PRINTED, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.PRIORITY, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); + contextMenu.getItems().add(SpecialFieldMenuItemFactory.createSpecialFieldMenu(SpecialField.READ_STATUS, factory, libraryTab.frame(), dialogService, preferencesService, undoManager, stateManager)); contextMenu.getItems().add(new SeparatorMenuItem()); - contextMenu.getItems().add(factory.createMenuItem(StandardActions.ATTACH_FILE, new AttachFileAction(libraryTab, dialogService, stateManager, preferencesService))); + contextMenu.getItems().add(factory.createMenuItem(StandardActions.ATTACH_FILE, new AttachFileAction(libraryTab, dialogService, stateManager, preferencesService.getFilePreferences()))); contextMenu.getItems().add(factory.createMenuItem(StandardActions.OPEN_FOLDER, new OpenFolderAction(dialogService, stateManager, preferencesService))); contextMenu.getItems().add(factory.createMenuItem(StandardActions.OPEN_EXTERNAL_FILE, new OpenExternalFileAction(dialogService, stateManager, preferencesService))); contextMenu.getItems().add(factory.createMenuItem(StandardActions.OPEN_URL, new OpenUrlAction(dialogService, stateManager, preferencesService))); diff --git a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java index bd307cd93ba..2fccfd5a332 100644 --- a/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java +++ b/src/main/java/org/jabref/gui/openoffice/StyleSelectDialogViewModel.java @@ -62,7 +62,7 @@ public void addStyleFile() { FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .addExtensionFilter(Localization.lang("Style file"), StandardFileType.JSTYLE) .withDefaultExtension(Localization.lang("Style file"), StandardFileType.JSTYLE) - .withInitialDirectory(preferencesService.getWorkingDir()) + .withInitialDirectory(preferencesService.getFilePreferences().getWorkingDirectory()) .build(); Optional path = dialogService.showFileOpenDialog(fileDialogConfiguration); path.map(Path::toAbsolutePath).map(Path::toString).ifPresent(stylePath -> { diff --git a/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java b/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java index 4e0ec263e83..218c76d940a 100644 --- a/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java @@ -84,7 +84,7 @@ public void addImporter() { FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .addExtensionFilter(StandardFileType.CLASS, StandardFileType.JAR, StandardFileType.ZIP) .withDefaultExtension(StandardFileType.CLASS) - .withInitialDirectory(preferences.getWorkingDir()) + .withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()) .build(); Optional selectedFile = dialogService.showFileOpenDialog(fileDialogConfiguration); diff --git a/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTabViewModel.java b/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTabViewModel.java index 783f6069aca..eca825e896f 100644 --- a/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/linkedfiles/LinkedFilesTabViewModel.java @@ -42,15 +42,13 @@ public class LinkedFilesTabViewModel implements PreferenceTabViewModel { private final Validator mainFileDirValidator; private final DialogService dialogService; - private final PreferencesService preferences; private final FilePreferences filePreferences; - private final AutoLinkPreferences initialAutoLinkPreferences; + private final AutoLinkPreferences autoLinkPreferences; public LinkedFilesTabViewModel(DialogService dialogService, PreferencesService preferences) { this.dialogService = dialogService; - this.preferences = preferences; this.filePreferences = preferences.getFilePreferences(); - this.initialAutoLinkPreferences = preferences.getAutoLinkPreferences(); + this.autoLinkPreferences = preferences.getAutoLinkPreferences(); mainFileDirValidator = new FunctionBasedValidator<>( mainFileDirectoryProperty, @@ -82,13 +80,13 @@ public void setValues() { fileDirectoryPatternProperty.setValue(filePreferences.getFileDirectoryPattern()); // Autolink preferences - switch (initialAutoLinkPreferences.getCitationKeyDependency()) { + switch (autoLinkPreferences.getCitationKeyDependency()) { case START -> autolinkFileStartsBibtexProperty.setValue(true); case EXACT -> autolinkFileExactBibtexProperty.setValue(true); case REGEX -> autolinkUseRegexProperty.setValue(true); } - autolinkRegexKeyProperty.setValue(initialAutoLinkPreferences.getRegularExpression()); + autolinkRegexKeyProperty.setValue(autoLinkPreferences.getRegularExpression()); } @Override @@ -102,14 +100,14 @@ public void storeSettings() { // Autolink preferences if (autolinkFileStartsBibtexProperty.getValue()) { - preferences.getAutoLinkPreferences().setCitationKeyDependency(AutoLinkPreferences.CitationKeyDependency.START); + autoLinkPreferences.setCitationKeyDependency(AutoLinkPreferences.CitationKeyDependency.START); } else if (autolinkFileExactBibtexProperty.getValue()) { - preferences.getAutoLinkPreferences().setCitationKeyDependency(AutoLinkPreferences.CitationKeyDependency.EXACT); + autoLinkPreferences.setCitationKeyDependency(AutoLinkPreferences.CitationKeyDependency.EXACT); } else if (autolinkUseRegexProperty.getValue()) { - preferences.getAutoLinkPreferences().setCitationKeyDependency(AutoLinkPreferences.CitationKeyDependency.REGEX); + autoLinkPreferences.setCitationKeyDependency(AutoLinkPreferences.CitationKeyDependency.REGEX); } - preferences.getAutoLinkPreferences().setRegularExpression(autolinkRegexKeyProperty.getValue()); + autoLinkPreferences.setRegularExpression(autolinkRegexKeyProperty.getValue()); } ValidationStatus mainFileDirValidationStatus() { diff --git a/src/main/java/org/jabref/gui/preferences/nameformatter/NameFormatterTab.java b/src/main/java/org/jabref/gui/preferences/nameformatter/NameFormatterTab.java index 997abc78d9b..03038872af2 100644 --- a/src/main/java/org/jabref/gui/preferences/nameformatter/NameFormatterTab.java +++ b/src/main/java/org/jabref/gui/preferences/nameformatter/NameFormatterTab.java @@ -44,7 +44,7 @@ public String getTabName() { } public void initialize() { - this.viewModel = new NameFormatterTabViewModel(dialogService, preferencesService); + this.viewModel = new NameFormatterTabViewModel(preferencesService.getNameFormatterPreferences()); formatterNameColumn.setSortable(true); formatterNameColumn.setReorderable(false); diff --git a/src/main/java/org/jabref/gui/preferences/nameformatter/NameFormatterTabViewModel.java b/src/main/java/org/jabref/gui/preferences/nameformatter/NameFormatterTabViewModel.java index d0463324446..3bcfb75cc5f 100644 --- a/src/main/java/org/jabref/gui/preferences/nameformatter/NameFormatterTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/nameformatter/NameFormatterTabViewModel.java @@ -9,11 +9,9 @@ import javafx.beans.property.StringProperty; import javafx.collections.FXCollections; -import org.jabref.gui.DialogService; import org.jabref.gui.preferences.PreferenceTabViewModel; import org.jabref.logic.layout.format.NameFormatterPreferences; import org.jabref.model.strings.StringUtil; -import org.jabref.preferences.PreferencesService; public class NameFormatterTabViewModel implements PreferenceTabViewModel { @@ -21,21 +19,17 @@ public class NameFormatterTabViewModel implements PreferenceTabViewModel { private final StringProperty addFormatterNameProperty = new SimpleStringProperty(); private final StringProperty addFormatterStringProperty = new SimpleStringProperty(); - private final DialogService dialogService; - private final PreferencesService preferences; - private final NameFormatterPreferences initialNameFormatterPreferences; + private final NameFormatterPreferences nameFormatterPreferences; - NameFormatterTabViewModel(DialogService dialogService, PreferencesService preferences) { - this.dialogService = dialogService; - this.preferences = preferences; - this.initialNameFormatterPreferences = preferences.getNameFormatterPreferences(); + NameFormatterTabViewModel(NameFormatterPreferences preferences) { + this.nameFormatterPreferences = preferences; } @Override public void setValues() { formatterListProperty.clear(); - List names = initialNameFormatterPreferences.getNameFormatterKey(); - List formats = initialNameFormatterPreferences.getNameFormatterValue(); + List names = nameFormatterPreferences.getNameFormatterKey(); + List formats = nameFormatterPreferences.getNameFormatterValue(); for (int i = 0; i < names.size(); i++) { if (i < formats.size()) { @@ -57,10 +51,8 @@ public void storeSettings() { formats.add(formatterListItem.getFormat()); } - NameFormatterPreferences newNameFormatterPreferences = new NameFormatterPreferences( - names, - formats); - preferences.storeNameFormatterPreferences(newNameFormatterPreferences); + nameFormatterPreferences.setNameFormatterKey(names); + nameFormatterPreferences.setNameFormatterValue(formats); } public void addFormatter() { diff --git a/src/main/java/org/jabref/gui/preferences/protectedterms/NewProtectedTermsFileDialog.java b/src/main/java/org/jabref/gui/preferences/protectedterms/NewProtectedTermsFileDialog.java index 679fc56f17a..7802e7fde1b 100644 --- a/src/main/java/org/jabref/gui/preferences/protectedterms/NewProtectedTermsFileDialog.java +++ b/src/main/java/org/jabref/gui/preferences/protectedterms/NewProtectedTermsFileDialog.java @@ -16,14 +16,14 @@ import org.jabref.logic.l10n.Localization; import org.jabref.logic.protectedterms.ProtectedTermsList; import org.jabref.logic.util.StandardFileType; -import org.jabref.preferences.PreferencesService; +import org.jabref.preferences.FilePreferences; public class NewProtectedTermsFileDialog extends BaseDialog { private final TextField newFile = new TextField(); private final DialogService dialogService; - public NewProtectedTermsFileDialog(List termsLists, DialogService dialogService, PreferencesService preferencesService) { + public NewProtectedTermsFileDialog(List termsLists, DialogService dialogService, FilePreferences filePreferences) { this.dialogService = dialogService; this.setTitle(Localization.lang("New protected terms file")); @@ -31,7 +31,7 @@ public NewProtectedTermsFileDialog(List termsLists, FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .addExtensionFilter(Localization.lang("Protected terms file"), StandardFileType.TERMS) .withDefaultExtension(Localization.lang("Protected terms file"), StandardFileType.TERMS) - .withInitialDirectory(preferencesService.getWorkingDir()) + .withInitialDirectory(filePreferences.getWorkingDirectory()) .build(); Button browse = new Button(Localization.lang("Browse")); diff --git a/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTabViewModel.java b/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTabViewModel.java index c3cc950660c..2382ea04263 100644 --- a/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/protectedterms/ProtectedTermsTabViewModel.java @@ -92,7 +92,7 @@ public void addFile() { FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() .addExtensionFilter(Localization.lang("Protected terms file"), StandardFileType.TERMS) .withDefaultExtension(Localization.lang("Protected terms file"), StandardFileType.TERMS) - .withInitialDirectory(preferences.getWorkingDir()) + .withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()) .build(); dialogService.showFileOpenDialog(fileDialogConfiguration) @@ -121,7 +121,7 @@ public void removeList(ProtectedTermsListItemModel itemModel) { } public void createNewFile() { - dialogService.showCustomDialogAndWait(new NewProtectedTermsFileDialog(termsFilesProperty, dialogService, preferences)); + dialogService.showCustomDialogAndWait(new NewProtectedTermsFileDialog(termsFilesProperty, dialogService, preferences.getFilePreferences())); } public void edit(ProtectedTermsListItemModel file) { diff --git a/src/main/java/org/jabref/gui/preferences/table/TableTab.fxml b/src/main/java/org/jabref/gui/preferences/table/TableTab.fxml index c65b263263f..0ff264f489f 100644 --- a/src/main/java/org/jabref/gui/preferences/table/TableTab.fxml +++ b/src/main/java/org/jabref/gui/preferences/table/TableTab.fxml @@ -17,7 +17,6 @@ xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml" fx:controller="org.jabref.gui.preferences.table.TableTab"> - @@ -88,17 +87,6 @@ + + + + + diff --git a/src/main/java/org/jabref/gui/metadata/BibtexStringEditorDialogView.java b/src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesView.java similarity index 54% rename from src/main/java/org/jabref/gui/metadata/BibtexStringEditorDialogView.java rename to src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesView.java index a758ac1a005..ddb97b38184 100644 --- a/src/main/java/org/jabref/gui/metadata/BibtexStringEditorDialogView.java +++ b/src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesView.java @@ -1,4 +1,4 @@ -package org.jabref.gui.metadata; +package org.jabref.gui.libraryproperties.constants; import java.util.Optional; @@ -8,73 +8,64 @@ import javafx.scene.control.Button; import javafx.scene.control.ButtonType; import javafx.scene.control.TableColumn; -import javafx.scene.control.TableColumn.CellEditEvent; import javafx.scene.control.TableView; import javafx.scene.control.Tooltip; import javafx.util.converter.DefaultStringConverter; -import org.jabref.gui.DialogService; import org.jabref.gui.icon.IconTheme; -import org.jabref.gui.util.BaseDialog; +import org.jabref.gui.libraryproperties.AbstractPropertiesTabView; +import org.jabref.gui.libraryproperties.PropertiesTab; import org.jabref.gui.util.ValueTableCellFactory; import org.jabref.gui.util.ViewModelTextFieldTableCellVisualizationFactory; import org.jabref.logic.l10n.Localization; -import org.jabref.model.database.BibDatabase; +import org.jabref.model.database.BibDatabaseContext; +import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.views.ViewLoader; -public class BibtexStringEditorDialogView extends BaseDialog { +public class ConstantsPropertiesView extends AbstractPropertiesTabView implements PropertiesTab { - @FXML private TableView stringsList; - @FXML private TableColumn labelColumn; - @FXML private TableColumn contentColumn; - @FXML private TableColumn actionsColumn; + @FXML private TableView stringsList; + @FXML private TableColumn labelColumn; + @FXML private TableColumn contentColumn; + @FXML private TableColumn actionsColumn; @FXML private Button addStringButton; @FXML private ButtonType saveButton; - private final BibtexStringEditorDialogViewModel viewModel; + @Inject private PreferencesService preferencesService; - @Inject private DialogService dialogService; - - public BibtexStringEditorDialogView(BibDatabase database) { - this.viewModel = new BibtexStringEditorDialogViewModel(database); + public ConstantsPropertiesView(BibDatabaseContext databaseContext) { + this.databaseContext = databaseContext; ViewLoader.view(this) - .load() - .setAsDialogPane(this); - - Button btnSave = (Button) this.getDialogPane().lookupButton(saveButton); - - btnSave.disableProperty().bind(viewModel.validProperty().not()); - - setResultConverter(btn -> { - if (saveButton.equals(btn)) { - viewModel.save(); - } - return null; - }); + .root(this) + .load(); + } - setTitle(Localization.lang("Strings for library")); + @Override + public String getTabName() { + return Localization.lang("Strings constants"); } - @FXML - private void initialize() { + public void initialize() { + this.viewModel = new ConstantsPropertiesViewModel(databaseContext); + addStringButton.setTooltip(new Tooltip(Localization.lang("New string"))); labelColumn.setSortable(true); labelColumn.setReorderable(false); labelColumn.setCellValueFactory(cellData -> cellData.getValue().labelProperty()); - new ViewModelTextFieldTableCellVisualizationFactory() - .withValidation(BibtexStringEditorItemModel::labelValidation) + new ViewModelTextFieldTableCellVisualizationFactory() + .withValidation(ConstantsItemModel::labelValidation) .install(labelColumn, new DefaultStringConverter()); - labelColumn.setOnEditCommit((CellEditEvent cellEvent) -> { + labelColumn.setOnEditCommit((TableColumn.CellEditEvent cellEvent) -> { - BibtexStringEditorItemModel cellItem = cellEvent.getTableView() - .getItems() - .get(cellEvent.getTablePosition().getRow()); + ConstantsItemModel cellItem = cellEvent.getTableView() + .getItems() + .get(cellEvent.getTablePosition().getRow()); - Optional existingItem = viewModel.labelAlreadyExists(cellEvent.getNewValue()); + Optional existingItem = viewModel.labelAlreadyExists(cellEvent.getNewValue()); if (existingItem.isPresent() && !existingItem.get().equals(cellItem)) { dialogService.showErrorDialogAndWait(Localization.lang( @@ -92,16 +83,16 @@ private void initialize() { contentColumn.setSortable(true); contentColumn.setReorderable(false); contentColumn.setCellValueFactory(cellData -> cellData.getValue().contentProperty()); - new ViewModelTextFieldTableCellVisualizationFactory() - .withValidation(BibtexStringEditorItemModel::contentValidation) + new ViewModelTextFieldTableCellVisualizationFactory() + .withValidation(ConstantsItemModel::contentValidation) .install(contentColumn, new DefaultStringConverter()); - contentColumn.setOnEditCommit((CellEditEvent cell) -> + contentColumn.setOnEditCommit((TableColumn.CellEditEvent cell) -> cell.getRowValue().setContent(cell.getNewValue())); actionsColumn.setSortable(false); actionsColumn.setReorderable(false); actionsColumn.setCellValueFactory(cellData -> cellData.getValue().labelProperty()); - new ValueTableCellFactory() + new ValueTableCellFactory() .withGraphic(label -> IconTheme.JabRefIcons.DELETE_ENTRY.getGraphicNode()) .withTooltip(label -> Localization.lang("Remove string %0", label)) .withOnMouseClickedEvent(item -> evt -> diff --git a/src/main/java/org/jabref/gui/metadata/BibtexStringEditorDialogViewModel.java b/src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesViewModel.java similarity index 52% rename from src/main/java/org/jabref/gui/metadata/BibtexStringEditorDialogViewModel.java rename to src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesViewModel.java index 723342b0f0e..4651b14e7e5 100644 --- a/src/main/java/org/jabref/gui/metadata/BibtexStringEditorDialogViewModel.java +++ b/src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesViewModel.java @@ -1,4 +1,4 @@ -package org.jabref.gui.metadata; +package org.jabref.gui.libraryproperties.constants; import java.util.Optional; import java.util.stream.Collectors; @@ -11,76 +11,79 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import org.jabref.gui.AbstractViewModel; import org.jabref.gui.help.HelpAction; +import org.jabref.gui.libraryproperties.PropertiesTabViewModel; import org.jabref.logic.bibtex.comparator.BibtexStringComparator; import org.jabref.logic.help.HelpFile; -import org.jabref.model.database.BibDatabase; +import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibtexString; import com.tobiasdiez.easybind.EasyBind; -public class BibtexStringEditorDialogViewModel extends AbstractViewModel { +public class ConstantsPropertiesViewModel implements PropertiesTabViewModel { + private static final String NEW_STRING_LABEL = "NewString"; // must not contain spaces - private final ListProperty stringsListProperty = + private final ListProperty stringsListProperty = new SimpleListProperty<>(FXCollections.observableArrayList()); - private final BibDatabase bibDatabase; private final BooleanProperty validProperty = new SimpleBooleanProperty(); - public BibtexStringEditorDialogViewModel(BibDatabase bibDatabase) { - this.bibDatabase = bibDatabase; - addAllStringsFromDB(); + private final BibDatabaseContext databaseContext; + + public ConstantsPropertiesViewModel(BibDatabaseContext databaseContext) { + this.databaseContext = databaseContext; ObservableList> allValidProperty = - EasyBind.map(stringsListProperty(), BibtexStringEditorItemModel::combinedValidationValidProperty); + EasyBind.map(stringsListProperty, ConstantsItemModel::combinedValidationValidProperty); validProperty.bind(EasyBind.combine(allValidProperty, stream -> stream.allMatch(valid -> valid))); } - private void addAllStringsFromDB() { - stringsListProperty.addAll(bibDatabase.getStringValues().stream() - .sorted(new BibtexStringComparator(false)) - .map(this::convertFromBibTexString) - .collect(Collectors.toSet())); + @Override + public void setValues() { + stringsListProperty.addAll(databaseContext.getDatabase().getStringValues().stream() + .sorted(new BibtexStringComparator(false)) + .map(this::convertFromBibTexString) + .collect(Collectors.toSet())); } public void addNewString() { - BibtexStringEditorItemModel newItem; + ConstantsItemModel newItem; if (labelAlreadyExists(NEW_STRING_LABEL).isPresent()) { int i = 1; while (labelAlreadyExists(NEW_STRING_LABEL + i).isPresent()) { i++; } - newItem = new BibtexStringEditorItemModel(NEW_STRING_LABEL + i, ""); + newItem = new ConstantsItemModel(NEW_STRING_LABEL + i, ""); } else { - newItem = new BibtexStringEditorItemModel(NEW_STRING_LABEL, ""); + newItem = new ConstantsItemModel(NEW_STRING_LABEL, ""); } stringsListProperty.add(newItem); } - public void removeString(BibtexStringEditorItemModel item) { + public void removeString(ConstantsItemModel item) { stringsListProperty.remove(item); } - private BibtexStringEditorItemModel convertFromBibTexString(BibtexString bibtexString) { - return new BibtexStringEditorItemModel(bibtexString.getName(), bibtexString.getContent()); + private ConstantsItemModel convertFromBibTexString(BibtexString bibtexString) { + return new ConstantsItemModel(bibtexString.getName(), bibtexString.getContent()); } - public void save() { - bibDatabase.setStrings(stringsListProperty.stream() - .map(this::fromBibtexStringViewModel) - .collect(Collectors.toList())); + @Override + public void storeSettings() { + databaseContext.getDatabase().setStrings(stringsListProperty.stream() + .map(this::fromBibtexStringViewModel) + .collect(Collectors.toList())); } - private BibtexString fromBibtexStringViewModel(BibtexStringEditorItemModel viewModel) { + private BibtexString fromBibtexStringViewModel(ConstantsItemModel viewModel) { String label = viewModel.labelProperty().getValue(); String content = viewModel.contentProperty().getValue(); return new BibtexString(label, content); } - public Optional labelAlreadyExists(String label) { + public Optional labelAlreadyExists(String label) { return stringsListProperty.stream() .filter(item -> item.labelProperty().getValue().equals(label)) .findFirst(); @@ -90,7 +93,7 @@ public void openHelpPage() { HelpAction.openHelpPage(HelpFile.STRING_EDITOR); } - public ListProperty stringsListProperty() { + public ListProperty stringsListProperty() { return stringsListProperty; } diff --git a/src/main/java/org/jabref/gui/libraryproperties/general/GeneralProperties.fxml b/src/main/java/org/jabref/gui/libraryproperties/general/GeneralProperties.fxml new file mode 100644 index 00000000000..88f558888b8 --- /dev/null +++ b/src/main/java/org/jabref/gui/libraryproperties/general/GeneralProperties.fxml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +