From a9637f817a769f7400e4deab09155676d7282d61 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sat, 23 Feb 2019 11:49:04 +0100 Subject: [PATCH 1/2] Remove global search feature --- CHANGELOG.md | 2 +- src/main/java/org/jabref/gui/JabRefFrame.java | 17 +- .../java/org/jabref/gui/icon/IconTheme.java | 2 - .../org/jabref/gui/keyboard/KeyBinding.java | 1 - .../jabref/gui/search/GlobalSearchBar.java | 118 +--- .../jabref/gui/search/GlobalSearchWorker.java | 68 -- .../jabref/gui/search/SearchResultFrame.java | 649 ------------------ .../jabref/preferences/SearchPreferences.java | 11 - src/main/resources/l10n/JabRef_en.properties | 7 - 9 files changed, 10 insertions(+), 865 deletions(-) delete mode 100644 src/main/java/org/jabref/gui/search/GlobalSearchWorker.java delete mode 100644 src/main/java/org/jabref/gui/search/SearchResultFrame.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 26e4ebbf307..f42bb73b20b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,6 +102,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 a few commands from the right-click menu that are not needed often and thus don't need to be placed that prominently: - Print entry preview: available through entry preview @@ -137,7 +138,6 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - ## Older versions diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index dbbce3f23b3..95819e3c0ee 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -131,7 +131,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; @@ -272,16 +271,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 currentSearchQuery = currentBasePanel.getCurrentSearchQuery(); - if (currentSearchQuery.isPresent()) { - content = currentSearchQuery.get().getQuery(); - } - globalSearchBar.setSearchTerm(content); + + // Update search query + String content = ""; + Optional currentSearchQuery = currentBasePanel.getCurrentSearchQuery(); + if (currentSearchQuery.isPresent()) { + content = currentSearchQuery.get().getQuery(); } + globalSearchBar.setSearchTerm(content); currentBasePanel.getPreviewPanel().updateLayout(Globals.prefs.getPreviewPreferences()); diff --git a/src/main/java/org/jabref/gui/icon/IconTheme.java b/src/main/java/org/jabref/gui/icon/IconTheme.java index 5c0510f862a..3d7aaaa18a6 100644 --- a/src/main/java/org/jabref/gui/icon/IconTheme.java +++ b/src/main/java/org/jabref/gui/icon/IconTheme.java @@ -280,7 +280,6 @@ 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 */ @@ -288,7 +287,6 @@ public enum JabRefIcons implements JabRefIcon { 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), diff --git a/src/main/java/org/jabref/gui/keyboard/KeyBinding.java b/src/main/java/org/jabref/gui/keyboard/KeyBinding.java index b73fbc6b0c3..4b5734f6293 100644 --- a/src/main/java/org/jabref/gui/keyboard/KeyBinding.java +++ b/src/main/java/org/jabref/gui/keyboard/KeyBinding.java @@ -38,7 +38,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), diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index e0fb4494af1..4f6d390c127 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -1,11 +1,8 @@ package org.jabref.gui.search; import java.lang.reflect.Field; -import java.nio.file.Path; -import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.stream.Collectors; import javafx.animation.KeyFrame; import javafx.animation.KeyValue; @@ -13,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; @@ -37,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; @@ -53,7 +47,6 @@ import org.jabref.logic.search.SearchQuery; import org.jabref.logic.search.SearchQueryHighlightObservable; import org.jabref.model.entry.Author; -import org.jabref.model.entry.BibEntry; import org.jabref.preferences.SearchPreferences; import impl.org.controlsfx.skin.AutoCompletePopup; @@ -77,15 +70,10 @@ 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; @@ -103,22 +91,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 = 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(); @@ -127,22 +104,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"))); @@ -196,66 +157,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); - List entries = currentBasePanel.getDatabase() - .getEntries() - .stream() - .filter(BibEntry::isSearchHit) - .collect(Collectors.toList()); - searchDialog.addEntries(entries, 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]; @@ -293,7 +194,6 @@ private void clearSearch() { currentResults.setText(""); searchField.setText(""); searchQueryHighlightObservable.reset(); - openCurrentResultsInDialog.setDisable(true); Globals.stateManager.clearSearchQuery(); } @@ -336,7 +236,6 @@ private void informUserAboutInvalidSearchQuery() { String illegalSearch = Localization.lang("Search failed: illegal search expression"); currentResults.setText(illegalSearch); - openCurrentResultsInDialog.setDisable(true); } public void setAutoCompleter(AutoCompleteSuggestionProvider searchCompleter) { @@ -401,11 +300,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) { @@ -416,14 +310,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 implements Skin> { private final AutoCompletePopup control; @@ -441,7 +327,7 @@ public SearchPopupSkin(AutoCompletePopup 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); diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchWorker.java b/src/main/java/org/jabref/gui/search/GlobalSearchWorker.java deleted file mode 100644 index bdbd6fe4bba..00000000000 --- a/src/main/java/org/jabref/gui/search/GlobalSearchWorker.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.jabref.gui.search; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.ExecutionException; -import java.util.stream.Collectors; - -import javax.swing.SwingWorker; - -import org.jabref.gui.BasePanel; -import org.jabref.gui.JabRefFrame; -import org.jabref.logic.l10n.Localization; -import org.jabref.logic.search.SearchQuery; -import org.jabref.model.entry.BibEntry; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -class GlobalSearchWorker extends SwingWorker>, Void> { - - private static final Logger LOGGER = LoggerFactory.getLogger(GlobalSearchWorker.class); - - private final JabRefFrame frame; - private final SearchQuery searchQuery; - private final SearchResultFrame dialog; - - public GlobalSearchWorker(JabRefFrame frame, SearchQuery query) { - this.frame = Objects.requireNonNull(frame); - this.searchQuery = Objects.requireNonNull(query); - - dialog = new SearchResultFrame(frame, - Localization.lang("Search results in all libraries for %0", - this.searchQuery.localize()), - searchQuery, true); - frame.getGlobalSearchBar().setSearchResultFrame(dialog); - } - - @Override - protected Map> doInBackground() throws Exception { - Map> matches = new HashMap<>(); - for (BasePanel basePanel : frame.getBasePanelList()) { - matches.put(basePanel, basePanel.getDatabase().getEntries().parallelStream() - .filter(searchQuery::isMatch) - .collect(Collectors.toList())); - } - return matches; - } - - @Override - protected void done() { - if (isCancelled()) { - return; - } - - try { - for (Map.Entry> match : get().entrySet()) { - dialog.addEntries(match.getValue(), match.getKey()); - } - dialog.selectFirstEntry(); - dialog.setVisible(true); - } catch (InterruptedException | ExecutionException e) { - LOGGER.error("something went wrong during the search", e); - } - } - -} diff --git a/src/main/java/org/jabref/gui/search/SearchResultFrame.java b/src/main/java/org/jabref/gui/search/SearchResultFrame.java deleted file mode 100644 index 9977866efad..00000000000 --- a/src/main/java/org/jabref/gui/search/SearchResultFrame.java +++ /dev/null @@ -1,649 +0,0 @@ -package org.jabref.gui.search; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.event.ActionEvent; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.io.IOException; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.InputMap; -import javax.swing.JComponent; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPopupMenu; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTable; -import javax.swing.KeyStroke; -import javax.swing.table.TableColumnModel; - -import javafx.embed.swing.JFXPanel; -import javafx.scene.Scene; - -import org.jabref.Globals; -import org.jabref.gui.BasePanel; -import org.jabref.gui.GUIGlobals; -import org.jabref.gui.JabRefFrame; -import org.jabref.gui.PreviewPanel; -import org.jabref.gui.customjfx.CustomJFXPanel; -import org.jabref.gui.desktop.JabRefDesktop; -import org.jabref.gui.externalfiletype.ExternalFileMenuItem; -import org.jabref.gui.externalfiletype.ExternalFileTypes; -import org.jabref.gui.filelist.FileListEntry; -import org.jabref.gui.filelist.FileListTableModel; -import org.jabref.gui.icon.IconTheme; -import org.jabref.gui.keyboard.KeyBinding; -import org.jabref.gui.maintable.MainTableNameFormatter; -import org.jabref.gui.renderer.GeneralRenderer; -import org.jabref.gui.util.comparator.IconComparator; -import org.jabref.logic.bibtex.comparator.EntryComparator; -import org.jabref.logic.bibtex.comparator.FieldComparator; -import org.jabref.logic.l10n.Localization; -import org.jabref.logic.search.SearchQuery; -import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.FieldName; -import org.jabref.model.entry.FieldProperty; -import org.jabref.model.entry.InternalBibtexFields; -import org.jabref.model.strings.StringUtil; -import org.jabref.preferences.SearchPreferences; - -import ca.odell.glazedlists.BasicEventList; -import ca.odell.glazedlists.EventList; -import ca.odell.glazedlists.SortedList; -import ca.odell.glazedlists.event.ListEvent; -import ca.odell.glazedlists.event.ListEventListener; -import ca.odell.glazedlists.gui.AbstractTableComparatorChooser; -import ca.odell.glazedlists.gui.AdvancedTableFormat; -import ca.odell.glazedlists.swing.DefaultEventSelectionModel; -import ca.odell.glazedlists.swing.DefaultEventTableModel; -import ca.odell.glazedlists.swing.GlazedListsSwing; -import ca.odell.glazedlists.swing.TableComparatorChooser; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Dialog to display search results, potentially from more than one BasePanel, with - * possibility to preview and to locate each entry in the main window. - */ -public class SearchResultFrame { - - private static final String[] FIELDS = new String[] {FieldName.AUTHOR, FieldName.TITLE, FieldName.YEAR, FieldName.JOURNAL}; - private static final int DATABASE_COL = 0; - private static final int FILE_COL = 1; - private static final int URL_COL = 2; - private static final int PAD = 3; - - private static final Logger LOGGER = LoggerFactory.getLogger(SearchResultFrame.class); - - private final JabRefFrame frame; - private JFrame searchResultFrame; - private final JLabel fileLabel = new JLabel(IconTheme.JabRefIcons.FILE.getSmallIcon()); - private final JLabel urlLabel = new JLabel(IconTheme.JabRefIcons.WWW.getSmallIcon()); - - private final JSplitPane contentPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); - - private final EventList entries = new BasicEventList<>(); - - private final Map entryHome = new HashMap<>(); - private DefaultEventTableModel model; - - private SortedList sortedEntries; - private JTable entryTable; - private PreviewPanel preview; - - private final SearchQuery searchQuery; - private final boolean globalSearch; - - public SearchResultFrame(JabRefFrame frame, String title, SearchQuery searchQuery, boolean globalSearch) { - this.frame = Objects.requireNonNull(frame); - this.searchQuery = searchQuery; - this.globalSearch = globalSearch; - frame.getGlobalSearchBar().setSearchResultFrame(this); - init(Objects.requireNonNull(title)); - } - - private void init(String title) { - searchResultFrame = new JFrame(); - searchResultFrame.setTitle(title); - searchResultFrame.setIconImages(IconTheme.getLogoSet()); - - preview = new PreviewPanel(null, null, Globals.getKeyPrefs(), Globals.prefs.getPreviewPreferences(), frame.getDialogService(), ExternalFileTypes.getInstance()); - - sortedEntries = new SortedList<>(entries, new EntryComparator(false, true, FieldName.AUTHOR)); - model = (DefaultEventTableModel) GlazedListsSwing.eventTableModelWithThreadProxyList(sortedEntries, - new EntryTableFormat()); - entryTable = new JTable(model); - - GeneralRenderer renderer = new GeneralRenderer(Color.white); - entryTable.setDefaultRenderer(JLabel.class, renderer); - entryTable.setDefaultRenderer(String.class, renderer); - setWidths(); - TableComparatorChooser tableSorter = TableComparatorChooser.install(entryTable, sortedEntries, - AbstractTableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD); - setupComparatorChooser(tableSorter); - JScrollPane sp = new JScrollPane(entryTable); - - final DefaultEventSelectionModel selectionModel = (DefaultEventSelectionModel) GlazedListsSwing - .eventSelectionModelWithThreadProxyList(sortedEntries); - entryTable.setSelectionModel(selectionModel); - selectionModel.getSelected().addListEventListener(new EntrySelectionListener()); - entryTable.addMouseListener(new TableClickListener()); - - contentPane.setTopComponent(sp); - - JFXPanel container = CustomJFXPanel.wrap(new Scene(preview)); - contentPane.setBottomComponent(container); - - // Key bindings: - AbstractAction closeAction = new AbstractAction() { - - @Override - public void actionPerformed(ActionEvent e) { - dispose(); - } - }; - - ActionMap actionMap = contentPane.getActionMap(); - InputMap inputMap = contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); - inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE), "close"); - inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DATABASE), "close"); - actionMap.put("close", closeAction); - - actionMap = entryTable.getActionMap(); - inputMap = entryTable.getInputMap(); - //Override 'selectNextColumnCell' and 'selectPreviousColumnCell' to move rows instead of cells on TAB - actionMap.put("selectNextColumnCell", new AbstractAction() { - - @Override - public void actionPerformed(ActionEvent e) { - selectNextEntry(); - } - }); - actionMap.put("selectPreviousColumnCell", new AbstractAction() { - - @Override - public void actionPerformed(ActionEvent e) { - selectPreviousEntry(); - } - }); - actionMap.put("selectNextRow", new AbstractAction() { - - @Override - public void actionPerformed(ActionEvent e) { - selectNextEntry(); - } - }); - actionMap.put("selectPreviousRow", new AbstractAction() { - - @Override - public void actionPerformed(ActionEvent e) { - selectPreviousEntry(); - } - }); - - String selectFirst = "selectFirst"; - inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.SELECT_FIRST_ENTRY), selectFirst); - actionMap.put(selectFirst, new AbstractAction() { - - @Override - public void actionPerformed(ActionEvent event) { - selectFirstEntry(); - } - }); - - String selectLast = "selectLast"; - inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.SELECT_LAST_ENTRY), selectLast); - actionMap.put(selectLast, new AbstractAction() { - - @Override - public void actionPerformed(ActionEvent event) { - selectLastEntry(); - } - }); - - actionMap.put("copy", new AbstractAction() { - - @Override - public void actionPerformed(ActionEvent e) { - if (!selectionModel.getSelected().isEmpty()) { - List bes = selectionModel.getSelected(); - try { - Globals.clipboardManager.setContent(bes); - } catch (IOException e1) { - LOGGER.error("Error while serializing entries for clipboard", e1); - } - frame.output(Localization.lang("Copied") + ' ' + (bes.size() > 1 ? bes.size() + " " - + Localization.lang("entries") - : "1 " + Localization.lang("entry") + '.')); - } - } - }); - - // override standard enter-action; enter opens the selected entry - entryTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter"); - actionMap.put("Enter", new AbstractAction() { - - @Override - public void actionPerformed(ActionEvent ae) { - BibEntry entry = sortedEntries.get(entryTable.getSelectedRow()); - selectEntryInBasePanel(entry); - } - }); - - searchResultFrame.addWindowListener(new WindowAdapter() { - - @Override - public void windowOpened(WindowEvent e) { - contentPane.setDividerLocation(0.5f); - } - - @Override - public void windowClosing(WindowEvent event) { - dispose(); - } - }); - - searchResultFrame.getContentPane().add(contentPane, BorderLayout.CENTER); - - // Remember and default to last size: - SearchPreferences searchPreferences = new SearchPreferences(Globals.prefs); - searchResultFrame.setSize(searchPreferences.getSeachDialogWidth(), searchPreferences.getSeachDialogHeight()); - searchResultFrame.setLocation(searchPreferences.getSearchDialogPosX(), searchPreferences.getSearchDialogPosY()); - - searchResultFrame.addComponentListener(new ComponentAdapter() { - - @Override - public void componentResized(ComponentEvent e) { - new SearchPreferences(Globals.prefs) - .setSearchDialogWidth(searchResultFrame.getSize().width) - .setSearchDialogHeight(searchResultFrame.getSize().height); - } - - @Override - public void componentMoved(ComponentEvent e) { - new SearchPreferences(Globals.prefs) - .setSearchDialogPosX(searchResultFrame.getLocation().x) - .setSearchDialogPosY(searchResultFrame.getLocation().y); - } - }); - } - - /** - * Control the visibility of the dialog. - * @param visible true to show dialog, false to hide. - */ - public void setVisible(boolean visible) { - searchResultFrame.setVisible(visible); - } - - public void selectFirstEntry() { - selectEntry(0); - } - - public void selectLastEntry() { - selectEntry(entryTable.getRowCount() - 1); - } - - public void selectPreviousEntry() { - selectEntry(((entryTable.getSelectedRow() - 1) + entryTable.getRowCount()) % entryTable.getRowCount()); - } - - public void selectNextEntry() { - selectEntry((entryTable.getSelectedRow() + 1) % entryTable.getRowCount()); - } - - public void selectEntry(int index) { - if ((index >= 0) && (index < entryTable.getRowCount())) { - entryTable.changeSelection(index, 0, false, false); - } else { - contentPane.setDividerLocation(1.0f); - } - } - - /** - * Set up the comparators for each column, so the user can modify sort order - * by clicking the column labels. - * @param comparatorChooser The comparator chooser controlling the sort order. - */ - private void setupComparatorChooser(TableComparatorChooser comparatorChooser) { - List comparators; - // Icon columns: - for (int i = 0; i < PAD; i++) { - comparators = comparatorChooser.getComparatorsForColumn(i); - comparators.clear(); - if (i == FILE_COL) { - comparators.add(new IconComparator(Collections.singletonList(FieldName.FILE))); - } else if (i == URL_COL) { - comparators.add(new IconComparator(Collections.singletonList(FieldName.URL))); - } else if (i == DATABASE_COL) { - comparators.add((entry1, entry2) -> { - String databaseTitle1 = entryHome.get(entry1).getTabTitle(); - String databaseTitle2 = entryHome.get(entry2).getTabTitle(); - return databaseTitle1.compareTo(databaseTitle2); - }); - } - - } - // Remaining columns: - for (int i = PAD; i < (PAD + FIELDS.length); i++) { - comparators = comparatorChooser.getComparatorsForColumn(i); - comparators.clear(); - comparators.add(new FieldComparator(FIELDS[i - PAD])); - } - - sortedEntries.getReadWriteLock().writeLock().lock(); - comparatorChooser.appendComparator(PAD, 0, false); - sortedEntries.getReadWriteLock().writeLock().unlock(); - - } - - /** - * Set column widths according to which field is shown, and lock icon columns - * to a suitable width. - */ - private void setWidths() { - TableColumnModel cm = entryTable.getColumnModel(); - for (int i = 0; i < (PAD + FIELDS.length); i++) { - switch (i) { - case FILE_COL: - case URL_COL: - cm.getColumn(i).setPreferredWidth(GUIGlobals.WIDTH_ICON_COL); - cm.getColumn(i).setMinWidth(GUIGlobals.WIDTH_ICON_COL); - cm.getColumn(i).setMaxWidth(GUIGlobals.WIDTH_ICON_COL); - break; - case DATABASE_COL: { - Double width = InternalBibtexFields.getFieldLength(FieldName.AUTHOR); - cm.getColumn(i).setPreferredWidth(width.intValue()); - break; - } - default: { - Double width = InternalBibtexFields.getFieldLength(FIELDS[i - PAD]); - cm.getColumn(i).setPreferredWidth(width.intValue()); - break; - } - } - } - } - - /** - * Add a list of entries to the table. - * @param newEntries The list of entries. - * @param panel A reference to the BasePanel where the entries belong. - */ - public void addEntries(List newEntries, BasePanel panel) { - for (BibEntry entry : newEntries) { - addEntry(entry, panel); - } - } - - /** - * Add a single entry to the table. - * @param entry The entry to add. - * @param panel A reference to the BasePanel where the entry belongs. - */ - private void addEntry(BibEntry entry, BasePanel panel) { - entries.add(entry); - entryHome.put(entry, panel); - - if ((preview.getEntry() == null) || !preview.getBasePanel().isPresent()) { - preview.setEntry(entry); - preview.setBasePanel(panel); - preview.setDatabaseContext(panel.getBibDatabaseContext()); - } - } - - private void selectEntryInBasePanel(BibEntry entry) { - BasePanel basePanel = entryHome.get(entry); - frame.showBasePanel(basePanel); - basePanel.requestFocus(); - basePanel.clearAndSelect(entry); - } - - public void dispose() { - frame.getGlobalSearchBar().setSearchResultFrame(null); - searchResultFrame.dispose(); - frame.getGlobalSearchBar().focus(); - } - - public void focus() { - entryTable.requestFocus(); - } - - public SearchQuery getSearchQuery() { - return searchQuery; - } - - public boolean isGlobalSearch() { - return globalSearch; - } - - /** - * Mouse listener for the entry table. Processes icon clicks to open external - * files or urls, as well as the opening of the context menu. - */ - class TableClickListener extends MouseAdapter { - - @Override - public void mouseReleased(MouseEvent e) { - if (e.isPopupTrigger()) { - processPopupTrigger(e); - } - } - - @Override - public void mousePressed(MouseEvent e) { - if (e.isPopupTrigger()) { - processPopupTrigger(e); - return; - } - - // First find the row on which the user has clicked. - final int row = entryTable.rowAtPoint(e.getPoint()); - - // A double click on an entry should highlight the entry in its BasePanel: - if (e.getClickCount() == 2) { - selectEntryInBasePanel(model.getElementAt(row)); - } - } - - @Override - public void mouseClicked(MouseEvent e) { - if (e.isPopupTrigger()) { - processPopupTrigger(e); - return; - } - //if (e.) - final int col = entryTable.columnAtPoint(e.getPoint()); - final int row = entryTable.rowAtPoint(e.getPoint()); - if (col < PAD) { - BibEntry entry = sortedEntries.get(row); - BasePanel p = entryHome.get(entry); - switch (col) { - case FILE_COL: - if (entry.hasField(FieldName.FILE)) { - FileListTableModel tableModel = new FileListTableModel(); - entry.getField(FieldName.FILE).ifPresent(tableModel::setContent); - if (tableModel.getRowCount() == 0) { - return; - } - FileListEntry fl = tableModel.getEntry(0); - (new ExternalFileMenuItem(frame, "", fl.getLink(), null, - p.getBibDatabaseContext(), fl.getType())).actionPerformed(null); - } - break; - case URL_COL: - entry.getField(FieldName.URL).ifPresent(link -> { try { - JabRefDesktop.openExternalViewer(p.getBibDatabaseContext(), link, FieldName.URL); - } catch (IOException ex) { - LOGGER.warn("Could not open viewer", ex); - } - }); - break; - default: - break; - } - } - } - - /** - * If the user has signalled the opening of a context menu, the event - * gets redirected to this method. Here we open a file link menu if the - * user is pointing at a file link icon. Otherwise a general context - * menu should be shown. - * @param e The triggering mouse event. - */ - public void processPopupTrigger(MouseEvent e) { - BibEntry entry = sortedEntries.get(entryTable.rowAtPoint(e.getPoint())); - BasePanel p = entryHome.get(entry); - int col = entryTable.columnAtPoint(e.getPoint()); - JPopupMenu menu = new JPopupMenu(); - int count = 0; - - if (col == FILE_COL) { - // We use a FileListTableModel to parse the field content: - FileListTableModel fileList = new FileListTableModel(); - entry.getField(FieldName.FILE).ifPresent(fileList::setContent); - // If there are one or more links, open the first one: - for (int i = 0; i < fileList.getRowCount(); i++) { - FileListEntry flEntry = fileList.getEntry(i); - String description = flEntry.getDescription(); - if ((description == null) || (description.trim().isEmpty())) { - description = flEntry.getLink(); - } - menu.add(new ExternalFileMenuItem(p.frame(), description, flEntry.getLink(), - flEntry.getType().get().getIcon().getSmallIcon(), p.getBibDatabaseContext(), flEntry.getType())); - count++; - } - - } - - if (count > 0) { - menu.show(entryTable, e.getX(), e.getY()); - } - } - } - - /** - * The listener for the Glazed list monitoring the current selection. - * When selection changes, we need to update the preview panel. - */ - private class EntrySelectionListener implements ListEventListener { - - @Override - public void listChanged(ListEvent listEvent) { - if (listEvent.getSourceList().size() == 1) { - BibEntry entry = listEvent.getSourceList().get(0); - // Find out which BasePanel the selected entry belongs to: - BasePanel basePanel = entryHome.get(entry); - // Update the preview's database context: - preview.setDatabaseContext(basePanel.getBibDatabaseContext()); - // Update the preview's entry: - preview.setEntry(entry); - preview.setBasePanel(entryHome.get(entry)); - preview.setDatabaseContext(entryHome.get(entry).getBibDatabaseContext()); - contentPane.setDividerLocation(0.5f); - } - } - } - - /** - * TableFormat for the table shown in the dialog. Handles the display of entry - * fields and icons for linked files and urls. - */ - private class EntryTableFormat implements AdvancedTableFormat { - - @Override - public int getColumnCount() { - return PAD + FIELDS.length; - } - - @Override - public String getColumnName(int column) { - if (column >= PAD) { - return StringUtil.capitalizeFirst(FIELDS[column - PAD]); - } else if (column == DATABASE_COL) { - return Localization.lang("Library"); - } else { - return ""; - } - } - - @Override - public Object getColumnValue(BibEntry entry, int column) { - if (column < PAD) { - switch (column) { - case DATABASE_COL: - return entryHome.get(entry).getTabTitle(); - case FILE_COL: - if (entry.hasField(FieldName.FILE)) { - FileListTableModel tmpModel = new FileListTableModel(); - entry.getField(FieldName.FILE).ifPresent(tmpModel::setContent); - fileLabel.setToolTipText(tmpModel.getToolTipHTMLRepresentation()); - if (tmpModel.getRowCount() > 0) { - if (tmpModel.getEntry(0).getType().isPresent()) { - fileLabel.setIcon(tmpModel.getEntry(0).getType().get().getIcon().getSmallIcon()); - } else { - fileLabel.setIcon(IconTheme.JabRefIcons.FILE.getSmallIcon()); - } - } - return fileLabel; - } else { - return null; - } - case URL_COL: { - Optional urlField = entry.getField(FieldName.URL); - if (urlField.isPresent()) { - urlLabel.setToolTipText(urlField.get()); - return urlLabel; - } - return null; - } - default: - return null; - } - } else { - String field = FIELDS[column - PAD]; - String fieldContent = entry.getLatexFreeField(field).orElse(""); - - if (InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.PERSON_NAMES)) { - // For name fields, tap into a MainTableFormat instance and use - // the same name formatting as is used in the entry table: - return MainTableNameFormatter.formatName(fieldContent); - } - return fieldContent; - } - } - - @Override - public Class getColumnClass(int i) { - switch (i) { - case FILE_COL: - case URL_COL: - return JLabel.class; - default: - return String.class; - } - } - - @Override - public Comparator getColumnComparator(int i) { - return null; - } - } - -} diff --git a/src/main/java/org/jabref/preferences/SearchPreferences.java b/src/main/java/org/jabref/preferences/SearchPreferences.java index 53452b5d639..78c1ba8aff8 100644 --- a/src/main/java/org/jabref/preferences/SearchPreferences.java +++ b/src/main/java/org/jabref/preferences/SearchPreferences.java @@ -7,7 +7,6 @@ public class SearchPreferences { - private static final String SEARCH_GLOBAL = "searchGlobal"; private static final String SEARCH_DISPLAY_MODE = "searchDisplayMode"; private static final String SEARCH_CASE_SENSITIVE = "caseSensitiveSearch"; private static final String SEARCH_REG_EXP = "regExpSearch"; @@ -25,7 +24,6 @@ public SearchPreferences(JabRefPreferences preferences) { } public static void putDefaults(Map defaults) { - defaults.put(SEARCH_GLOBAL, Boolean.FALSE); defaults.put(SEARCH_DISPLAY_MODE, SearchDisplayMode.FILTER.toString()); defaults.put(SEARCH_CASE_SENSITIVE, Boolean.FALSE); defaults.put(SEARCH_REG_EXP, Boolean.FALSE); @@ -36,15 +34,6 @@ public static void putDefaults(Map defaults) { defaults.put(SEARCH_DIALOG_POS_Y, 0); } - public boolean isGlobalSearch() { - return preferences.getBoolean(SEARCH_GLOBAL); - } - - public SearchPreferences setGlobalSearch(boolean isGlobalSearch) { - preferences.putBoolean(SEARCH_GLOBAL, isGlobalSearch); - return this; - } - public SearchDisplayMode getSearchMode() { try { return SearchDisplayMode.valueOf(preferences.get(SEARCH_DISPLAY_MODE)); diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 352b53bbb83..f7d51441bbd 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -1140,9 +1140,6 @@ Number\ of\ entries\ successfully\ imported=Number of entries successfully impor Import\ canceled\ by\ user=Import canceled by user Error\ while\ fetching\ from\ %0=Error while fetching from %0 -Show\ search\ results\ in\ a\ window=Show search results in a window -Show\ global\ search\ results\ in\ a\ window=Show global search results in a window -Search\ in\ all\ open\ libraries=Search in all open libraries Refuse\ to\ save\ the\ library\ before\ external\ changes\ have\ been\ reviewed.=Refuse to save the library before external changes have been reviewed. Library\ protection=Library protection Unable\ to\ save\ library=Unable to save library @@ -1556,10 +1553,6 @@ should\ contain\ a\ valid\ page\ number\ range=should contain a valid page numbe Filled=Filled Field\ is\ missing=Field is missing Search\ %0=Search %0 - -Search\ results\ in\ all\ libraries\ for\ %0=Search results in all libraries for %0 -Search\ results\ in\ library\ %0\ for\ %1=Search results in library %0 for %1 -Search\ globally=Search globally No\ results\ found.=No results found. Found\ %0\ results.=Found %0 results. plain\ text=plain text From fb60d56bd7873204e147fc45e97577ef94555d33 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 2 Apr 2019 21:52:42 +0200 Subject: [PATCH 2/2] Remove unused code --- .../java/org/jabref/gui/search/GlobalSearchBar.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java index 4f6d390c127..8426b3fb290 100644 --- a/src/main/java/org/jabref/gui/search/GlobalSearchBar.java +++ b/src/main/java/org/jabref/gui/search/GlobalSearchBar.java @@ -77,11 +77,6 @@ public class GlobalSearchBar extends HBox { 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); @@ -268,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);