Skip to content

Commit

Permalink
Ask for enable indexing when clicking fulltext search (#11854)
Browse files Browse the repository at this point in the history
* Ask for enable indexing when clicking fulltext search

fixes #9491
comment

* only set preferences value

* fix flag

* deselect button if not enabled

* switch to listener

* fix rewrite

* Update src/main/java/org/jabref/gui/search/GlobalSearchBar.java

Co-authored-by: Loay Ghreeb <loayahmed655@gmail.com>

---------

Co-authored-by: Loay Ghreeb <loayahmed655@gmail.com>
  • Loading branch information
Siedlerchr and LoayGhreeb committed Sep 29, 2024
1 parent 8309e65 commit a50cad7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We improved the undo/redo buttons in the main toolbar and main menu to be disabled when there is nothing to undo/redo. [#8807](https://github.com/JabRef/jabref/issues/8807)
- We improved the DOI detection in PDF imports. [#11782](https://github.com/JabRef/jabref/pull/11782)
- We improved the performance when pasting and importing entries in an existing library. [#11843](https://github.com/JabRef/jabref/pull/11843)
- When fulltext search is selected but indexing is deactivated, a dialog is now shown asking if the user wants to enable indexing now [#9491](https://github.com/JabRef/jabref/issues/9491)

### Fixed

Expand Down
41 changes: 34 additions & 7 deletions src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.jabref.architecture.AllowedToUseClassGetResource;
import org.jabref.gui.ClipBoardManager;
import org.jabref.gui.DialogService;
import org.jabref.gui.LibraryTab;
import org.jabref.gui.LibraryTabContainer;
import org.jabref.gui.StateManager;
import org.jabref.gui.autocompleter.AppendPersonNamesStrategy;
Expand All @@ -57,6 +58,7 @@
import org.jabref.gui.util.BindingsHelper;
import org.jabref.gui.util.TooltipTextUtil;
import org.jabref.gui.util.UiTaskExecutor;
import org.jabref.logic.FilePreferences;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.preferences.AutoCompleteFirstNameMode;
import org.jabref.logic.search.SearchDisplayMode;
Expand Down Expand Up @@ -96,6 +98,7 @@ public class GlobalSearchBar extends HBox {
private final DialogService dialogService;
private final BooleanProperty globalSearchActive = new SimpleBooleanProperty(false);
private final BooleanProperty illegalSearch = new SimpleBooleanProperty(false);
private final FilePreferences filePreferences;
private GlobalSearchResultDialog globalSearchResultDialog;
private final SearchType searchType;

Expand All @@ -109,6 +112,7 @@ public GlobalSearchBar(LibraryTabContainer tabContainer,
this.stateManager = stateManager;
this.preferences = preferences;
this.searchPreferences = preferences.getSearchPreferences();
this.filePreferences = preferences.getFilePreferences();
this.undoManager = undoManager;
this.dialogService = dialogService;
this.tabContainer = tabContainer;
Expand Down Expand Up @@ -151,7 +155,10 @@ public GlobalSearchBar(LibraryTabContainer tabContainer,
if (keyBindingRepository.matches(event, KeyBinding.CLEAR_SEARCH)) {
searchField.clear();
if (searchType == SearchType.NORMAL_SEARCH) {
tabContainer.getCurrentLibraryTab().getMainTable().requestFocus();
LibraryTab currentLibraryTab = tabContainer.getCurrentLibraryTab();
if (currentLibraryTab != null) {
currentLibraryTab.getMainTable().requestFocus();
}
}
event.consume();
}
Expand Down Expand Up @@ -231,11 +238,33 @@ public GlobalSearchBar(LibraryTabContainer tabContainer,
}

private void initSearchModifierButtons() {
fulltextButton.setSelected(searchPreferences.isFulltext());
fulltextButton.setTooltip(new Tooltip(Localization.lang("Fulltext search")));
initSearchModifierButton(fulltextButton);

EasyBind.subscribe(filePreferences.fulltextIndexLinkedFilesProperty(), enabled -> {
if (!enabled) {
fulltextButton.setSelected(false);
} else if (searchPreferences.isFulltext()) {
fulltextButton.setSelected(true);
}
});

fulltextButton.selectedProperty().addListener((obs, oldVal, newVal) -> {
searchPreferences.setSearchFlag(SearchFlags.FULLTEXT, newVal);
if (!filePreferences.shouldFulltextIndexLinkedFiles() && newVal) {
boolean enableFulltextSearch = dialogService.showConfirmationDialogAndWait(Localization.lang("Fulltext search"), Localization.lang("Fulltext search requires the setting 'Automatically index all linked files for fulltext search' to be enabled. Do you want to enable indexing now?"), Localization.lang("Enable indexing"), Localization.lang("Keep disabled"));

LibraryTab libraryTab = tabContainer.getCurrentLibraryTab();
if (libraryTab != null && enableFulltextSearch) {
filePreferences.setFulltextIndexLinkedFiles(true);
searchPreferences.setSearchFlag(SearchFlags.FULLTEXT, true);
}
if (!enableFulltextSearch) {
fulltextButton.setSelected(false);
searchPreferences.setSearchFlag(SearchFlags.FULLTEXT, false);
}
} else {
searchPreferences.setSearchFlag(SearchFlags.FULLTEXT, newVal);
}
updateSearchQuery();
});

Expand All @@ -254,9 +283,7 @@ private void initSearchModifierButtons() {
initSearchModifierButton(openGlobalSearchButton);
openGlobalSearchButton.setOnAction(evt -> openGlobalSearchDialog());

searchPreferences.getObservableSearchFlags().addListener((SetChangeListener.Change<? extends SearchFlags> change) -> {
fulltextButton.setSelected(searchPreferences.isFulltext());
});
searchPreferences.getObservableSearchFlags().addListener((SetChangeListener.Change<? extends SearchFlags> change) -> fulltextButton.setSelected(searchPreferences.isFulltext()));
}

public void openGlobalSearchDialog() {
Expand All @@ -268,7 +295,7 @@ public void openGlobalSearchDialog() {
globalSearchResultDialog = new GlobalSearchResultDialog(undoManager, tabContainer);
}
stateManager.activeSearchQuery(SearchType.NORMAL_SEARCH).get().ifPresent(query ->
stateManager.activeSearchQuery(SearchType.GLOBAL_SEARCH).set(Optional.of(query)));
stateManager.activeSearchQuery(SearchType.GLOBAL_SEARCH).set(Optional.of(query)));
updateSearchQuery();
dialogService.showCustomDialogAndWait(globalSearchResultDialog);
globalSearchActive.setValue(false);
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,10 @@ Searching...=Searching...
Finished\ Searching=Finished Searching
Search\ expression=Search expression
Fulltext\ search=Fulltext search

Enable\ indexing=Enable indexing
Fulltext\ search\ requires\ the\ setting\ 'Automatically\ index\ all\ linked\ files\ for\ fulltext\ search'\ to\ be\ enabled.\ Do\ you\ want\ to\ enable\ indexing\ now?=Fulltext search requires the setting 'Automatically index all linked files for fulltext search' to be enabled. Do you want to enable indexing now?

Help\ on\ regular\ expression\ search=Help on regular expression search
Searching\ for\ duplicates...=Searching for duplicates...
Searching\ for\ files=Searching for files
Expand Down

0 comments on commit a50cad7

Please sign in to comment.