From 8a712fe16edb9a73f1944c1ed3d8ccd7b513fc74 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 29 Sep 2024 20:57:50 +0200 Subject: [PATCH 1/7] Ask for enable indexing when clicking fulltext search fixes https://github.com/JabRef/jabref/issues/9491 comment --- CHANGELOG.md | 1 + .../jabref/gui/search/GlobalSearchBar.java | 29 +++++++++++++++---- src/main/resources/l10n/JabRef_en.properties | 4 +++ 3 files changed, 28 insertions(+), 6 deletions(-) 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..6990db9fd84 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(); } @@ -235,7 +242,19 @@ private void initSearchModifierButtons() { fulltextButton.setTooltip(new Tooltip(Localization.lang("Fulltext search"))); initSearchModifierButton(fulltextButton); 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); + libraryTab.getLuceneManager().rebuildIndex(); + } + if (!enableFulltextSearch) { + fulltextButton.setSelected(false); + } + } + searchPreferences.setSearchFlag(SearchFlags.FULLTEXT, true); updateSearchQuery(); }); @@ -254,9 +273,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 +285,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 From cfbcc3be3372f720f9f78ddf8cbbbb4702228d69 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 29 Sep 2024 22:12:02 +0200 Subject: [PATCH 2/7] only set preferences value --- src/main/java/org/jabref/gui/search/GlobalSearchBar.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index 6990db9fd84..0b28649ea08 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -248,7 +248,6 @@ private void initSearchModifierButtons() { LibraryTab libraryTab = tabContainer.getCurrentLibraryTab(); if (libraryTab != null && enableFulltextSearch) { filePreferences.setFulltextIndexLinkedFiles(true); - libraryTab.getLuceneManager().rebuildIndex(); } if (!enableFulltextSearch) { fulltextButton.setSelected(false); From 457e546c509ed8e1c8c7437b1960a7eba0288428 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 29 Sep 2024 22:26:33 +0200 Subject: [PATCH 3/7] fix flag --- src/main/java/org/jabref/gui/search/GlobalSearchBar.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index 0b28649ea08..28fb36b7a15 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -253,7 +253,7 @@ private void initSearchModifierButtons() { fulltextButton.setSelected(false); } } - searchPreferences.setSearchFlag(SearchFlags.FULLTEXT, true); + searchPreferences.setSearchFlag(SearchFlags.FULLTEXT, newVal); updateSearchQuery(); }); From 2b9b8c46eaa47638ada13e38d85a115f1212083c Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 29 Sep 2024 22:55:52 +0200 Subject: [PATCH 4/7] deselect button if not enabled --- src/main/java/org/jabref/gui/search/GlobalSearchBar.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index 28fb36b7a15..01cd60be86d 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -238,7 +238,7 @@ public GlobalSearchBar(LibraryTabContainer tabContainer, } private void initSearchModifierButtons() { - fulltextButton.setSelected(searchPreferences.isFulltext()); + fulltextButton.setSelected(searchPreferences.isFulltext() && filePreferences.shouldFulltextIndexLinkedFiles()); fulltextButton.setTooltip(new Tooltip(Localization.lang("Fulltext search"))); initSearchModifierButton(fulltextButton); fulltextButton.selectedProperty().addListener((obs, oldVal, newVal) -> { From fa27454682149f03fd685338847f74eeffb59592 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 29 Sep 2024 23:22:55 +0200 Subject: [PATCH 5/7] switch to listener --- .../java/org/jabref/gui/search/GlobalSearchBar.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index 01cd60be86d..71500d0aeb7 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -238,9 +238,17 @@ public GlobalSearchBar(LibraryTabContainer tabContainer, } private void initSearchModifierButtons() { - fulltextButton.setSelected(searchPreferences.isFulltext() && filePreferences.shouldFulltextIndexLinkedFiles()); 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) -> { 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")); From ff14bbcdb9d16aeb4782bd3043fa9ee964ebb1fa Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 29 Sep 2024 23:37:32 +0200 Subject: [PATCH 6/7] fix rewrite --- src/main/java/org/jabref/gui/search/GlobalSearchBar.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index 71500d0aeb7..dc2686c97f2 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -241,7 +241,7 @@ private void initSearchModifierButtons() { fulltextButton.setTooltip(new Tooltip(Localization.lang("Fulltext search"))); initSearchModifierButton(fulltextButton); - EasyBind.subscribe(filePreferences.fulltextIndexLinkedFilesProperty(), (enabled) -> { + EasyBind.subscribe(filePreferences.fulltextIndexLinkedFilesProperty(), enabled -> { if (!enabled) { fulltextButton.setSelected(false); } else if (searchPreferences.isFulltext()) { From 1919d610e652750cafc3011267cb8f81fa20d424 Mon Sep 17 00:00:00 2001 From: Christoph Date: Sun, 29 Sep 2024 23:58:29 +0200 Subject: [PATCH 7/7] Update src/main/java/org/jabref/gui/search/GlobalSearchBar.java Co-authored-by: Loay Ghreeb --- src/main/java/org/jabref/gui/search/GlobalSearchBar.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index dc2686c97f2..daed3d2fff1 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -256,12 +256,15 @@ private void initSearchModifierButtons() { 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); } - searchPreferences.setSearchFlag(SearchFlags.FULLTEXT, newVal); updateSearchQuery(); });