Skip to content

Commit

Permalink
Merge pull request JabRef#10619 from JabRef/fist-attempt-at-8977
Browse files Browse the repository at this point in the history
Prevent the EventBus from triggering searches
  • Loading branch information
Siedlerchr authored Nov 10, 2023
2 parents f4a44ba + d0c8b25 commit a1d783f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 33 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv

### Removed

- We removed duplicate filtering and sorting operations in the MainTable when editing BibEntries. [#10619](https://github.com/JabRef/jabref/pull/10619)




## [5.11] – 2023-10-22

### Added
Expand Down
25 changes: 0 additions & 25 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
import org.jabref.model.entry.BibEntryTypesManager;
import org.jabref.model.entry.LinkedFile;
import org.jabref.model.entry.event.EntriesEventSource;
import org.jabref.model.entry.event.EntryChangedEvent;
import org.jabref.model.entry.event.FieldChangedEvent;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.FieldFactory;
Expand Down Expand Up @@ -156,7 +155,6 @@ public LibraryTab(BibDatabaseContext bibDatabaseContext,
setupMainPanel();
setupAutoCompletion();

this.getDatabase().registerListener(new SearchListener());
this.getDatabase().registerListener(new IndexUpdateListener());
this.getDatabase().registerListener(new EntriesRemovedListener());

Expand Down Expand Up @@ -277,7 +275,6 @@ public void feedData(BibDatabaseContext bibDatabaseContextFromParserResult) {
setupMainPanel();
setupAutoCompletion();

this.getDatabase().registerListener(new SearchListener());
this.getDatabase().registerListener(new EntriesRemovedListener());

// ensure that at each addition of a new entry, the entry is added to the groups interface
Expand Down Expand Up @@ -918,28 +915,6 @@ public void listen(EntriesRemovedEvent entriesRemovedEvent) {
}
}

/**
* Ensures that the results of the current search are updated when a new entry is inserted into the database Actual methods for performing search must run in javafx thread
*/
private class SearchListener {

@Subscribe
public void listen(EntriesAddedEvent addedEntryEvent) {
DefaultTaskExecutor.runInJavaFXThread(() -> frame.getGlobalSearchBar().performSearch());
}

@Subscribe
public void listen(EntryChangedEvent entryChangedEvent) {
DefaultTaskExecutor.runInJavaFXThread(() -> frame.getGlobalSearchBar().performSearch());
}

@Subscribe
public void listen(EntriesRemovedEvent removedEntriesEvent) {
// IMO only used to update the status (found X entries)
DefaultTaskExecutor.runInJavaFXThread(() -> frame.getGlobalSearchBar().performSearch());
}
}

private class IndexUpdateListener {

@Subscribe
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public GlobalSearchBar(JabRefFrame frame, StateManager stateManager, Preferences
this.setSpacing(4.0);
this.setAlignment(Pos.CENTER_LEFT);

Timer searchTask = FxTimer.create(Duration.ofMillis(SEARCH_DELAY), this::performSearch);
Timer searchTask = FxTimer.create(Duration.ofMillis(SEARCH_DELAY), this::updateSearchQuery);
BindingsHelper.bindBidirectional(
stateManager.activeSearchQueryProperty(),
searchField.textProperty(),
Expand Down Expand Up @@ -238,31 +238,31 @@ private void initSearchModifierButtons() {
initSearchModifierButton(regularExpressionButton);
regularExpressionButton.setOnAction(event -> {
searchPreferences.setSearchFlag(SearchRules.SearchFlags.REGULAR_EXPRESSION, regularExpressionButton.isSelected());
performSearch();
updateSearchQuery();
});

caseSensitiveButton.setSelected(searchPreferences.isCaseSensitive());
caseSensitiveButton.setTooltip(new Tooltip(Localization.lang("Case sensitive")));
initSearchModifierButton(caseSensitiveButton);
caseSensitiveButton.setOnAction(event -> {
searchPreferences.setSearchFlag(SearchRules.SearchFlags.CASE_SENSITIVE, caseSensitiveButton.isSelected());
performSearch();
updateSearchQuery();
});

fulltextButton.setSelected(searchPreferences.isFulltext());
fulltextButton.setTooltip(new Tooltip(Localization.lang("Fulltext search")));
initSearchModifierButton(fulltextButton);
fulltextButton.setOnAction(event -> {
searchPreferences.setSearchFlag(SearchRules.SearchFlags.FULLTEXT, fulltextButton.isSelected());
performSearch();
updateSearchQuery();
});

keepSearchString.setSelected(searchPreferences.shouldKeepSearchString());
keepSearchString.setTooltip(new Tooltip(Localization.lang("Keep search string across libraries")));
initSearchModifierButton(keepSearchString);
keepSearchString.setOnAction(evt -> {
searchPreferences.setSearchFlag(SearchRules.SearchFlags.KEEP_SEARCH_STRING, keepSearchString.isSelected());
performSearch();
updateSearchQuery();
});

openGlobalSearchButton.disableProperty().bindBidirectional(globalSearchActive);
Expand All @@ -271,7 +271,7 @@ private void initSearchModifierButtons() {
openGlobalSearchButton.setOnAction(evt -> {
globalSearchActive.setValue(true);
globalSearchResultDialog = new GlobalSearchResultDialog(undoManager);
performSearch();
updateSearchQuery();
dialogService.showCustomDialogAndWait(globalSearchResultDialog);
globalSearchActive.setValue(false);
});
Expand All @@ -298,9 +298,9 @@ public void focus() {
searchField.selectAll();
}

public void performSearch() {
public void updateSearchQuery() {
LOGGER.debug("Flags: {}", searchPreferences.getSearchFlags());
LOGGER.debug("Run search {}", searchField.getText());
LOGGER.debug("Updated search query: {}", searchField.getText());

// An empty search field should cause the search to be cleared.
if (searchField.getText().isEmpty()) {
Expand Down

0 comments on commit a1d783f

Please sign in to comment.