Skip to content

Commit

Permalink
Ask for enable indexing when clicking fulltext search
Browse files Browse the repository at this point in the history
fixes #9491
comment
  • Loading branch information
Siedlerchr committed Sep 29, 2024
1 parent e395853 commit 8a712fe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 23 additions & 6 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 @@ -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();
});

Expand All @@ -254,9 +273,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 +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);
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 8a712fe

Please sign in to comment.