Skip to content

Commit

Permalink
Disable search when no library is opened (#5923)
Browse files Browse the repository at this point in the history
Fix exception when getSearchResultSize returned null
  • Loading branch information
Siedlerchr authored Feb 10, 2020
1 parent a94add9 commit f8dbac6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/StateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<GroupTreeNode> activeGroupProperty() {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f8dbac6

Please sign in to comment.