Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve search history by attaching change listener #9794

Merged
merged 20 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/main/java/org/jabref/gui/StateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.jabref.gui.util.CustomLocalDragboard;
import org.jabref.gui.util.DialogWindowState;
import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.gui.search.GlobalSearchBar;
import org.jabref.logic.search.SearchQuery;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -216,8 +217,10 @@ public List<String> collectAllDatabasePaths() {
}

public void addSearchHistory(String search) {
searchHistory.remove(search);
searchHistory.add(search);
if (!GlobalSearchBar.searchBoxFocused.get()) {
dkokkotas marked this conversation as resolved.
Show resolved Hide resolved
searchHistory.remove(search);
searchHistory.add(search);
}
}

public ObservableList<String> getWholeSearchHistory() {
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public class GlobalSearchBar extends HBox {
private final DialogService dialogService;

private final BooleanProperty globalSearchActive = new SimpleBooleanProperty(false);
public static final BooleanProperty searchBoxFocused = new SimpleBooleanProperty(false);
dkokkotas marked this conversation as resolved.
Show resolved Hide resolved
private GlobalSearchResultDialog globalSearchResultDialog;

public GlobalSearchBar(JabRefFrame frame, StateManager stateManager, PreferencesService preferencesService, CountingUndoManager undoManager, DialogService dialogService) {
Expand Down Expand Up @@ -307,7 +308,12 @@ public void performSearch() {
informUserAboutInvalidSearchQuery();
return;
}
this.stateManager.addSearchHistory(searchField.textProperty().get());
searchBoxFocused.bind(searchField.focusedProperty());
koppor marked this conversation as resolved.
Show resolved Hide resolved
searchBoxFocused.addListener((observable, oldPropertyValue, newPropertyValue) -> {
if (!(newPropertyValue || searchField.textProperty().get().isEmpty())) {
this.stateManager.addSearchHistory(searchField.textProperty().get());
}
});
stateManager.setSearchQuery(searchQuery);
}

Expand Down