Skip to content

Commit

Permalink
Remove global search feature (#4694)
Browse files Browse the repository at this point in the history
* Remove global search feature

* Remove unused code
  • Loading branch information
tobiasdiez committed Apr 2, 2019
1 parent 3ed41ef commit 54892f2
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 872 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
### Removed
- The feature to "mark entries" was removed and merged with the groups functionality. For migration, a group is created for every value of the `__markedentry` field and the entry is added to this group.
- The number column was removed.
- We removed the global search feature.
- We removed the coloring of cells in the maintable according to whether the field is optional/required.
- We removed the feature to find and resolve duplicate BibTeX keys (as this use case is already covered by the integrity check).
- We removed a few commands from the right-click menu that are not needed often and thus don't need to be placed that prominently:
Expand Down Expand Up @@ -146,7 +147,6 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#






## Older versions
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@
import org.jabref.model.entry.specialfields.SpecialField;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.LastFocusedTabPreferences;
import org.jabref.preferences.SearchPreferences;

import com.google.common.eventbus.Subscribe;
import com.jfoenix.controls.JFXSnackbar;
Expand Down Expand Up @@ -270,16 +269,14 @@ private void init() {
// Poor-mans binding to global state
// We need to invoke this in the JavaFX thread as all the listeners sit there
Platform.runLater(() -> Globals.stateManager.activeDatabaseProperty().setValue(Optional.of(currentBasePanel.getBibDatabaseContext())));
if (new SearchPreferences(Globals.prefs).isGlobalSearch()) {
globalSearchBar.performSearch();
} else {
String content = "";
Optional<SearchQuery> currentSearchQuery = currentBasePanel.getCurrentSearchQuery();
if (currentSearchQuery.isPresent()) {
content = currentSearchQuery.get().getQuery();
}
globalSearchBar.setSearchTerm(content);

// Update search query
String content = "";
Optional<SearchQuery> currentSearchQuery = currentBasePanel.getCurrentSearchQuery();
if (currentSearchQuery.isPresent()) {
content = currentSearchQuery.get().getQuery();
}
globalSearchBar.setSearchTerm(content);

currentBasePanel.getPreviewPanel().updateLayout(Globals.prefs.getPreviewPreferences());

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/jabref/gui/icon/IconTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,13 @@ public enum JabRefIcons implements JabRefIcon {
SUCCESS(MaterialDesignIcon.CHECK_CIRCLE),
WARNING(MaterialDesignIcon.ALERT),
ERROR(MaterialDesignIcon.ALERT_CIRCLE),
OPEN_IN_NEW_WINDOW(MaterialDesignIcon.OPEN_IN_NEW), /*css: open-in-new */
CASE_SENSITIVE(MaterialDesignIcon.ALPHABETICAL), /* css: mdi-alphabetical */
REG_EX(MaterialDesignIcon.REGEX), /*css: mdi-regex */
CONSOLE(MaterialDesignIcon.CONSOLE), /*css: console */
FORUM(MaterialDesignIcon.FORUM), /* css: forum */
FACEBOOK(MaterialDesignIcon.FACEBOOK), /* css: facebook */
TWITTER(MaterialDesignIcon.TWITTER), /* css: twitter */
BLOG(MaterialDesignIcon.RSS), /* css: rss */
GLOBAL_SEARCH(MaterialDesignIcon.EARTH), /* css: earth */
DATE_PICKER(MaterialDesignIcon.CALENDAR), /* css: calendar */
DEFAULT_GROUP_ICON_COLORED(MaterialDesignIcon.PLAY),
DEFAULT_GROUP_ICON(MaterialDesignIcon.LABEL_OUTLINE),
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/jabref/gui/keyboard/KeyBinding.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public enum KeyBinding {
FILE_LIST_EDITOR_MOVE_ENTRY_UP("File list editor, move entry up", Localization.lang("File list editor, move entry up"), "ctrl+UP", KeyBindingCategory.VIEW),
FIND_UNLINKED_FILES("Find unlinked files", Localization.lang("Find unlinked files"), "shift+F7", KeyBindingCategory.QUALITY),
FOCUS_ENTRY_TABLE("Focus entry table", Localization.lang("Focus entry table"), "alt+1", KeyBindingCategory.VIEW),
GLOBAL_SEARCH("Search globally", Localization.lang("Search globally"), "ctrl+shift+F", KeyBindingCategory.SEARCH),
HELP("Help", Localization.lang("Help"), "F1", KeyBindingCategory.FILE),
IMPORT_INTO_CURRENT_DATABASE("Import into current library", Localization.lang("Import into current library"), "ctrl+I", KeyBindingCategory.FILE),
IMPORT_INTO_NEW_DATABASE("Import into new library", Localization.lang("Import into new library"), "ctrl+alt+I", KeyBindingCategory.FILE),
Expand Down
124 changes: 2 additions & 122 deletions src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jabref.gui.search;

import java.lang.reflect.Field;
import java.nio.file.Path;
import java.util.Objects;
import java.util.Optional;

Expand All @@ -11,14 +10,12 @@
import javafx.beans.binding.Bindings;
import javafx.css.PseudoClass;
import javafx.event.Event;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.Separator;
import javafx.scene.control.Skin;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleButton;
Expand All @@ -35,7 +32,6 @@

import org.jabref.Globals;
import org.jabref.gui.BasePanel;
import org.jabref.gui.GUIGlobals;
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.autocompleter.AppendPersonNamesStrategy;
import org.jabref.gui.autocompleter.AutoCompleteFirstNameMode;
Expand Down Expand Up @@ -74,23 +70,13 @@ public class GlobalSearchBar extends HBox {
private final TextField searchField = SearchTextField.create();
private final ToggleButton caseSensitive;
private final ToggleButton regularExp;
private final ToggleButton globalSearch;
private final Button searchModeButton = new Button();
private final Label currentResults = new Label("");
private final SearchQueryHighlightObservable searchQueryHighlightObservable = new SearchQueryHighlightObservable();
private final Button openCurrentResultsInDialog = IconTheme.JabRefIcons.OPEN_IN_NEW_WINDOW.asButton();
private SearchWorker searchWorker;
private GlobalSearchWorker globalSearchWorker;

private SearchResultFrame searchResultFrame;

private SearchDisplayMode searchDisplayMode;

/**
* if this flag is set the searchbar won't be selected after the next search
*/
private boolean dontSelectSearchBar;

public GlobalSearchBar(JabRefFrame frame) {
super();
this.frame = Objects.requireNonNull(frame);
Expand All @@ -100,22 +86,11 @@ public GlobalSearchBar(JabRefFrame frame) {
// fits the standard "found x entries"-message thus hinders the searchbar to jump around while searching if the frame width is too small
currentResults.setPrefWidth(150);

globalSearch = IconTheme.JabRefIcons.GLOBAL_SEARCH.asToggleButton();
globalSearch.setSelected(searchPreferences.isGlobalSearch());
globalSearch.setTooltip(new Tooltip(Localization.lang("Search in all open libraries")));


KeyBindingRepository keyBindingRepository = Globals.getKeyPrefs();
searchField.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
Optional<KeyBinding> keyBinding = keyBindingRepository.mapToKeyBinding(event);
if (keyBinding.isPresent()) {
if (keyBinding.get().equals(KeyBinding.GLOBAL_SEARCH)) {
globalSearch.setSelected(true);
searchPreferences.setGlobalSearch(globalSearch.isSelected());
updateOpenCurrentResultsTooltip(globalSearch.isSelected());
focus();
event.consume();
} else if (keyBinding.get().equals(KeyBinding.CLOSE)) {
if (keyBinding.get().equals(KeyBinding.CLOSE)) {
// Clear search and select first entry, if available
clearSearch();
frame.getCurrentBasePanel().getMainTable().getSelectionModel().selectFirst();
Expand All @@ -124,22 +99,6 @@ public GlobalSearchBar(JabRefFrame frame) {
}
});

globalSearch.setOnAction(event -> {
searchPreferences.setGlobalSearch(globalSearch.isSelected());
updateOpenCurrentResultsTooltip(globalSearch.isSelected());
});

//openCurrentResultsInDialog.setDisabledIcon(IconTheme.JabRefIcons.OPEN_IN_NEW_WINDOW.disabled().getSmallIcon());
openCurrentResultsInDialog.setOnAction(event -> {
if (globalSearch.isSelected()) {
performGlobalSearch();
} else {
openLocalFindingsInExternalPanel();
}
});
openCurrentResultsInDialog.setDisable(true);
updateOpenCurrentResultsTooltip(globalSearch.isSelected());

regularExp = IconTheme.JabRefIcons.REG_EX.asToggleButton();
regularExp.setSelected(searchPreferences.isRegularExpression());
regularExp.setTooltip(new Tooltip(Localization.lang("regular expression")));
Expand Down Expand Up @@ -193,64 +152,6 @@ public GlobalSearchBar(JabRefFrame frame) {
this.setAlignment(Pos.CENTER_LEFT);
}

private void performGlobalSearch() {
BasePanel currentBasePanel = frame.getCurrentBasePanel();
if ((currentBasePanel == null) || validateSearchResultFrame(true)) {
return;
}

if (globalSearchWorker != null) {
globalSearchWorker.cancel(true);
}

if (searchField.getText().isEmpty()) {
focus();
return;
}

globalSearchWorker = new GlobalSearchWorker(currentBasePanel.frame(), getSearchQuery());
globalSearchWorker.execute();
}

private void openLocalFindingsInExternalPanel() {
BasePanel currentBasePanel = frame.getCurrentBasePanel();
if ((currentBasePanel == null) || validateSearchResultFrame(false)) {
return;
}

if (searchField.getText().isEmpty()) {
focus();
return;
}

SearchResultFrame searchDialog = new SearchResultFrame(
currentBasePanel.frame(),
Localization.lang("Search results in library %0 for %1",
currentBasePanel.getBibDatabaseContext()
.getDatabasePath()
.map(Path::getFileName)
.map(Path::toString)
.orElse(GUIGlobals.UNTITLED_TITLE),
this.getSearchQuery().localize()), getSearchQuery(), false);
searchDialog.addEntries(currentBasePanel.getDatabase().getEntries(), currentBasePanel);
searchDialog.selectFirstEntry();
searchDialog.setVisible(true);
}

private boolean validateSearchResultFrame(boolean globalSearch) {
if (searchResultFrame != null) {
if ((searchResultFrame.isGlobalSearch() == globalSearch) && isStillValidQuery(searchResultFrame.getSearchQuery())) {
searchResultFrame.focus();
return true;
} else {
searchResultFrame.dispose();
return false;
}
}

return false;
}

private void toggleSearchModeAndSearch() {
int nextSearchMode = (searchDisplayMode.ordinal() + 1) % SearchDisplayMode.values().length;
searchDisplayMode = SearchDisplayMode.values()[nextSearchMode];
Expand Down Expand Up @@ -288,7 +189,6 @@ private void clearSearch() {
currentResults.setText("");
searchField.setText("");
searchQueryHighlightObservable.reset();
openCurrentResultsInDialog.setDisable(true);

Globals.stateManager.clearSearchQuery();
}
Expand Down Expand Up @@ -331,7 +231,6 @@ private void informUserAboutInvalidSearchQuery() {

String illegalSearch = Localization.lang("Search failed: illegal search expression");
currentResults.setText(illegalSearch);
openCurrentResultsInDialog.setDisable(true);
}

public void setAutoCompleter(AutoCompleteSuggestionProvider<Author> searchCompleter) {
Expand Down Expand Up @@ -364,12 +263,6 @@ public SearchQueryHighlightObservable getSearchQueryHighlightObservable() {
return searchQueryHighlightObservable;
}

public boolean isStillValidQuery(SearchQuery query) {
return query.getQuery().equals(this.searchField.getText())
&& (query.isRegularExpression() == regularExp.isSelected())
&& (query.isCaseSensitive() == caseSensitive.isSelected());
}

private SearchQuery getSearchQuery() {
SearchQuery searchQuery = new SearchQuery(this.searchField.getText(), this.caseSensitive.isSelected(), this.regularExp.isSelected());
this.frame.getCurrentBasePanel().setCurrentSearchQuery(searchQuery);
Expand All @@ -396,11 +289,6 @@ public void updateResults(int matched, TextFlow description, boolean grammarBase
tooltip.setGraphic(description);
tooltip.setMaxHeight(10);
searchField.setTooltip(tooltip);
openCurrentResultsInDialog.setDisable(false);
}

public void setSearchResultFrame(SearchResultFrame searchResultFrame) {
this.searchResultFrame = searchResultFrame;
}

public void setSearchTerm(String searchTerm) {
Expand All @@ -411,14 +299,6 @@ public void setSearchTerm(String searchTerm) {
DefaultTaskExecutor.runInJavaFXThread(() -> searchField.setText(searchTerm));
}

private void updateOpenCurrentResultsTooltip(boolean globalSearchEnabled) {
if (globalSearchEnabled) {
openCurrentResultsInDialog.setTooltip(new Tooltip(Localization.lang("Show global search results in a window")));
} else {
openCurrentResultsInDialog.setTooltip(new Tooltip(Localization.lang("Show search results in a window")));
}
}

private class SearchPopupSkin<T> implements Skin<AutoCompletePopup<T>> {

private final AutoCompletePopup<T> control;
Expand All @@ -436,7 +316,7 @@ public SearchPopupSkin(AutoCompletePopup<T> control) {
this.suggestionList.maxWidthProperty().bind(control.maxWidthProperty());
this.suggestionList.minWidthProperty().bind(control.minWidthProperty());

ToolBar toolBar = new ToolBar(openCurrentResultsInDialog, new Separator(Orientation.VERTICAL), globalSearch, regularExp, caseSensitive, searchModeButton);
ToolBar toolBar = new ToolBar(regularExp, caseSensitive, searchModeButton);

this.container = new BorderPane();
this.container.setCenter(suggestionList);
Expand Down
68 changes: 0 additions & 68 deletions src/main/java/org/jabref/gui/search/GlobalSearchWorker.java

This file was deleted.

Loading

0 comments on commit 54892f2

Please sign in to comment.