diff --git a/CHANGELOG.md b/CHANGELOG.md index f98cb2c822c..63843552539 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,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 diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index e57f2e47643..daed3d2fff1 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -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; @@ -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; @@ -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; @@ -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; @@ -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(); } @@ -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(); }); @@ -254,9 +283,7 @@ private void initSearchModifierButtons() { initSearchModifierButton(openGlobalSearchButton); openGlobalSearchButton.setOnAction(evt -> openGlobalSearchDialog()); - searchPreferences.getObservableSearchFlags().addListener((SetChangeListener.Change change) -> { - fulltextButton.setSelected(searchPreferences.isFulltext()); - }); + searchPreferences.getObservableSearchFlags().addListener((SetChangeListener.Change change) -> fulltextButton.setSelected(searchPreferences.isFulltext())); } public void openGlobalSearchDialog() { @@ -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); diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 2ec8827add2..e7703f1bed7 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -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