From 778d495b660ddadf8f1eb8e735577ffac53fb16f Mon Sep 17 00:00:00 2001 From: Songxuan Li Date: Wed, 1 Nov 2023 18:45:19 +1100 Subject: [PATCH] replace "SearchAll" in web search by "Search Selected" see:https://github.com/JabRef/jabref/issues/10556 Implemented "Search Selected". Enabled configuring the catalogs to be searched. Updated menu and other corresponding UI Updated corresponding tests --- CHANGELOG.md | 2 +- .../fetcher/WebSearchPaneViewModel.java | 20 ++++++++++-- .../preferences/websearch/WebSearchTab.fxml | 21 ++++++++++++ .../preferences/websearch/WebSearchTab.java | 30 +++++++++++++++++ .../websearch/WebSearchTabViewModel.java | 32 +++++++++++++++++-- .../logic/importer/ImporterPreferences.java | 17 ++++++++-- .../jabref/logic/importer/WebFetchers.java | 2 +- .../fetcher/CompositeSearchBasedFetcher.java | 23 +++++++++---- .../jabref/preferences/JabRefPreferences.java | 18 ++++++++--- src/main/resources/l10n/JabRef_en.properties | 2 ++ .../ManageStudyDefinitionViewModelTest.java | 2 +- .../StudyCatalogToFetcherConverterTest.java | 1 - .../logic/importer/WebFetchersTest.java | 2 +- .../CompositeSearchBasedFetcherTest.java | 15 ++++++--- 14 files changed, 161 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6060ff558b8f..a35f50868dbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We moved the location of the 'Open only one instance of JabRef' preference option from "Network" to "General". [#9306](https://github.com/JabRef/jabref/issues/9306) - The two previews in the change resolver dialog now have their scrollbars synchronized. [#9576](https://github.com/JabRef/jabref/issues/9576). - We changed the setting of the keyword separator to accept a single character only. [#177](https://github.com/koppor/jabref/issues/177) - +- We replaced "SearchAll" in Web Search by "Search Selected" [#10556](https://github.com/JabRef/jabref/issues/10556) ### Fixed - We fixed an issue where the added protected term has unwanted leading and trailing whitespaces, where the formatted text has unwanted empty brackets and where the word at the cursor in the textbox can be added to the list. [#10415](https://github.com/JabRef/jabref/issues/10415). diff --git a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java index 5634e4e74509..49beb69f81d9 100644 --- a/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java +++ b/src/main/java/org/jabref/gui/importer/fetcher/WebSearchPaneViewModel.java @@ -1,7 +1,10 @@ package org.jabref.gui.importer.fetcher; +import java.util.Comparator; import java.util.Map; +import java.util.Objects; import java.util.SortedSet; +import java.util.TreeSet; import java.util.concurrent.Callable; import javafx.beans.property.ListProperty; @@ -22,6 +25,7 @@ import org.jabref.logic.importer.ParserResult; import org.jabref.logic.importer.SearchBasedFetcher; import org.jabref.logic.importer.WebFetchers; +import org.jabref.logic.importer.fetcher.CompositeSearchBasedFetcher; import org.jabref.logic.l10n.Localization; import org.jabref.model.strings.StringUtil; import org.jabref.model.util.OptionalUtil; @@ -57,9 +61,10 @@ public WebSearchPaneViewModel(PreferencesService preferencesService, DialogServi this.stateManager = stateManager; this.preferencesService = preferencesService; - SortedSet allFetchers = WebFetchers.getSearchBasedFetchers( + SortedSet allFetchers = new TreeSet<>(new CompositeSearchFirstComparator()); + allFetchers.addAll(WebFetchers.getSearchBasedFetchers( preferencesService.getImportFormatPreferences(), - preferencesService.getImporterPreferences()); + preferencesService.getImporterPreferences())); fetchers.setAll(allFetchers); // Choose last-selected fetcher as default @@ -174,3 +179,14 @@ public ValidationStatus queryValidationStatus() { return searchQueryValidator.getValidationStatus(); } } + +class CompositeSearchFirstComparator implements Comparator { + @Override + public int compare(SearchBasedFetcher s1, SearchBasedFetcher s2) { + if (Objects.equals(s1.getName(), CompositeSearchBasedFetcher.FETCHER_NAME)) { + return -1; + } else { + return s1.getName().compareTo(s2.getName()); + } + } +} diff --git a/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTab.fxml b/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTab.fxml index 6bd19f653ca9..99c142efb191 100644 --- a/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTab.fxml +++ b/src/main/java/org/jabref/gui/preferences/websearch/WebSearchTab.fxml @@ -5,6 +5,8 @@ + + @@ -25,6 +27,25 @@ +