From f8dbac6a492405a5943ce249880f056fe0ed9ffb Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 10 Feb 2020 21:18:39 +0100 Subject: [PATCH] Disable search when no library is opened (#5923) Fix exception when getSearchResultSize returned null --- src/main/java/org/jabref/gui/StateManager.java | 3 ++- src/main/java/org/jabref/gui/search/GlobalSearchBar.java | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/StateManager.java b/src/main/java/org/jabref/gui/StateManager.java index f9a0076d70f..c09f97244f0 100644 --- a/src/main/java/org/jabref/gui/StateManager.java +++ b/src/main/java/org/jabref/gui/StateManager.java @@ -9,6 +9,7 @@ import javafx.beans.property.IntegerProperty; import javafx.beans.property.ReadOnlyListProperty; import javafx.beans.property.ReadOnlyListWrapper; +import javafx.beans.property.SimpleIntegerProperty; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.collections.ObservableMap; @@ -53,7 +54,7 @@ public void setActiveSearchResultSize(BibDatabaseContext database, IntegerProper } public IntegerProperty getSearchResultSize() { - return searchResultMap.get(activeDatabase.getValue().orElse(new BibDatabaseContext())); + return searchResultMap.getOrDefault(activeDatabase.getValue().orElse(new BibDatabaseContext()), new SimpleIntegerProperty(0)); } public ReadOnlyListProperty activeGroupProperty() { diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index 0c27d0458df..d3d4cc62b42 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -72,6 +72,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.jabref.gui.actions.ActionHelper.needsDatabase; + public class GlobalSearchBar extends HBox { private static final Logger LOGGER = LoggerFactory.getLogger(GlobalSearchBar.class); @@ -99,6 +101,8 @@ public GlobalSearchBar(JabRefFrame frame, StateManager stateManager) { SearchPreferences searchPreferences = new SearchPreferences(Globals.prefs); searchDisplayMode = searchPreferences.getSearchMode(); + + this.searchField.disableProperty().bind(needsDatabase(stateManager).not()); // fits the standard "found x entries"-message thus hinders the searchbar to jump around while searching if the frame width is too small currentResults.setPrefWidth(150);