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

Prevent the EventBus from triggering searches #10619

Merged
merged 13 commits into from
Nov 10, 2023
Merged
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
Loading