Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Searchbar across all bib files instead each having its own #1549

Merged
merged 24 commits into from Sep 11, 2016
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,13 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
## [Unreleased]

### Changed
- Implemented [#825](https://github.com/JabRef/jabref/issues/825): Search Bar across all bib files instead each having its own
- Implemented [#573](https://github.com/JabRef/jabref/issues/573): Add key shortcut for global search (`ctrl+shift+f`, if the searchfield is empty it will be focused instead)
- The search result Window will now show which entry belongs to which bib file
- The search result Window will now remember its location
- The search result Window won't stay on top anymore if the main Window is focused and will be present in the taskbar
- The User can jump from the searchbar to the maintabel with `ctrl + enter`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix typos user, maintable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keyboard shortcuts should be rendered consistenly without space before and after +

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

- Implemented [#573 (comment)](https://github.com/JabRef/jabref/issues/573#issuecomment-232284156): Added shortcut: closing the search result window with `ctrl+w`
- Added integrity check for fields with BibTeX keys, e.g., `crossref` and `related`, to check that the key exists
- [#1496](https://github.com/JabRef/jabref/issues/1496) Keep track of which entry a downloaded file belongs to
- Made it possible to download multiple entries in one action
Expand All @@ -26,6 +33,13 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#

### Fixed
- Fixed selecting an entry out of multiple duplicates
- Fixed [#617](https://github.com/JabRef/jabref/issues/617): `Enter` in global search opens the selected entry & `Enter` in search dialog window opens the selected entry
- Entries in the SearchResultPanel will be shown correctly (Latex to Unicode)
- Suggestions in the autocomplete will be shown correctly (Latex to Unicode)
- Fixed: When searching the first match will be selected if the current selection is no match
- Selecting an entry in the search result Window will now select the correct entry in the bib file
- Entries in the SearchResultDialog are now converted to Unicode
- Suggestions in the autocomplete (search) are now in Unicode
- Fixed NullPointerException when opening search result window for an untitled database
- Fixed entry table traversal with Tab (no column traversal thus no double jump)
- Fixed [#1757](https://github.com/JabRef/jabref/issues/1757): Crash after saving illegal argument in entry editor
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/net/sf/jabref/cli/ArgumentProcessor.java
Expand Up @@ -47,6 +47,7 @@
import net.sf.jabref.model.database.BibDatabaseMode;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.preferences.JabRefPreferences;
import net.sf.jabref.preferences.SearchPreferences;
import net.sf.jabref.shared.prefs.SharedDatabasePreferences;

import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -166,9 +167,10 @@ private boolean exportMatches(List<ParserResult> loaded) {
BibDatabaseContext databaseContext = pr.getDatabaseContext();
BibDatabase dataBase = pr.getDatabase();

SearchPreferences searchPreferences = new SearchPreferences(Globals.prefs);
SearchQuery query = new SearchQuery(searchTerm,
Globals.prefs.getBoolean(JabRefPreferences.SEARCH_CASE_SENSITIVE),
Globals.prefs.getBoolean(JabRefPreferences.SEARCH_REG_EXP));
searchPreferences.isCaseSensitive(),
searchPreferences.isRegularExpression());
List<BibEntry> matches = new DatabaseSearcher(query, dataBase).getMatches();

//export matches
Expand Down
44 changes: 31 additions & 13 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Expand Up @@ -76,7 +76,6 @@
import net.sf.jabref.gui.mergeentries.FetchAndMergeEntry;
import net.sf.jabref.gui.mergeentries.MergeEntriesDialog;
import net.sf.jabref.gui.plaintextimport.TextInputDialog;
import net.sf.jabref.gui.search.SearchBar;
import net.sf.jabref.gui.undo.CountingUndoManager;
import net.sf.jabref.gui.undo.NamedCompound;
import net.sf.jabref.gui.undo.UndoableChangeType;
Expand Down Expand Up @@ -105,6 +104,7 @@
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.layout.Layout;
import net.sf.jabref.logic.layout.LayoutHelper;
import net.sf.jabref.logic.search.SearchQuery;
import net.sf.jabref.logic.util.FileExtensions;
import net.sf.jabref.logic.util.UpdateField;
import net.sf.jabref.logic.util.io.FileBasedLock;
Expand Down Expand Up @@ -203,9 +203,10 @@ public class BasePanel extends JPanel implements ClipboardOwner, FileUpdateListe

private final SidePaneManager sidePaneManager;

private final SearchBar searchBar;
private ContentAutoCompleters autoCompleters;

private SearchQuery currentSearchQuery;


public BasePanel(JabRefFrame frame, BibDatabaseContext bibDatabaseContext) {
Objects.requireNonNull(frame);
Expand All @@ -217,17 +218,16 @@ public BasePanel(JabRefFrame frame, BibDatabaseContext bibDatabaseContext) {
this.frame = frame;
this.tableModel = new MainTableDataModel(getBibDatabaseContext());

searchBar = new SearchBar(this);

setupMainPanel();

setupActions();

Optional<File> file = bibDatabaseContext.getDatabaseFile();
this.getDatabase().registerListener(new SearchListener());

// ensure that at each addition of a new entry, the entry is added to the groups interface
this.bibDatabaseContext.getDatabase().registerListener(new GroupTreeListener());

Optional<File> file = bibDatabaseContext.getDatabaseFile();
if (file.isPresent()) {
// Register so we get notifications about outside changes to the file.
try {
Expand Down Expand Up @@ -517,7 +517,8 @@ public void update() {

actions.put(Actions.MERGE_ENTRIES, (BaseAction) () -> new MergeEntriesDialog(BasePanel.this));

actions.put(Actions.SEARCH, (BaseAction) searchBar::focus);
actions.put(Actions.SEARCH, (BaseAction) frame.getGlobalSearchBar()::focus);
actions.put(Actions.GLOBAL_SEARCH, (BaseAction) frame.getGlobalSearchBar()::performGlobalSearch);

// The action for copying the selected entry's key.
actions.put(Actions.COPY_KEY, (BaseAction) () -> copyKey());
Expand Down Expand Up @@ -1164,11 +1165,6 @@ public BibEntry newEntry(EntryType type) {
return null;
}

public SearchBar getSearchBar() {
return searchBar;
}


private class GroupTreeListener {

private final Runnable task = new Runnable() {
Expand Down Expand Up @@ -1271,6 +1267,21 @@ public void listen(EntryChangedEvent entryChangedEvent) {
}
}

/**
* Ensures that the results of the current search are updated when a new entry is inserted into the database
*/
private class SearchListener {
@Subscribe
public void listen(EntryAddedEvent addedEntryEvent) {
frame.getGlobalSearchBar().performSearch();
}

@Subscribe
public void listen(EntryChangedEvent entryChangedEvent) {
frame.getGlobalSearchBar().performSearch();
}
}


/**
* This method is called from JabRefFrame when the user wants to create a new entry.
Expand Down Expand Up @@ -1475,7 +1486,6 @@ public void setupMainPanel() {

setLayout(new BorderLayout());
removeAll();
add(searchBar, BorderLayout.NORTH);
add(splitPane, BorderLayout.CENTER);

// Set up name autocompleter for search:
Expand Down Expand Up @@ -1509,7 +1519,7 @@ public void setupMainPanel() {
}

public void updateSearchManager() {
searchBar.setAutoCompleter(searchAutoCompleter);
frame.getGlobalSearchBar().setAutoCompleter(searchAutoCompleter);
}

private void instantiateSearchAutoCompleter() {
Expand Down Expand Up @@ -2412,4 +2422,12 @@ public Map<String, EntryEditor> getEntryEditors() {
public BibDatabaseContext getDatabaseContext() {
return bibDatabaseContext;
}

public SearchQuery getCurrentSearchQuery() {
return currentSearchQuery;
}

public void setCurrentSearchQuery(SearchQuery currentSearchQuery) {
this.currentSearchQuery = currentSearchQuery;
}
}
2 changes: 2 additions & 0 deletions src/main/java/net/sf/jabref/gui/IconTheme.java
Expand Up @@ -157,6 +157,8 @@ public enum JabRefIcon {
FORUM("\uf28c"), /* css: forum */
FACEBOOK("\uf20c"), /* css: facebook */
BLOG("\uf46b"), /* css: rss */
GLOBAL_SEARCH_ON("\uF1E7"), /* css: earth */
GLOBAL_SEARCH_OFF("\uF1E8"), /* css: earth-off */
// STILL MISSING:
GROUP_REGULAR("\uF4E6", Color.RED);

Expand Down
54 changes: 39 additions & 15 deletions src/main/java/net/sf/jabref/gui/JabRefFrame.java
Expand Up @@ -3,6 +3,7 @@
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GraphicsEnvironment;
Expand Down Expand Up @@ -103,6 +104,7 @@
import net.sf.jabref.gui.protectedterms.ProtectedTermsDialog;
import net.sf.jabref.gui.push.PushToApplicationButton;
import net.sf.jabref.gui.push.PushToApplications;
import net.sf.jabref.gui.search.GlobalSearchBar;
import net.sf.jabref.gui.util.FocusRequester;
import net.sf.jabref.gui.util.WindowLocation;
import net.sf.jabref.gui.worker.MarkEntriesAction;
Expand All @@ -112,6 +114,7 @@
import net.sf.jabref.logic.importer.ParserResult;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.logging.GuiAppender;
import net.sf.jabref.logic.search.SearchQuery;
import net.sf.jabref.logic.undo.AddUndoableActionEvent;
import net.sf.jabref.logic.undo.UndoChangeEvent;
import net.sf.jabref.logic.undo.UndoRedoEvent;
Expand All @@ -125,6 +128,7 @@
import net.sf.jabref.preferences.HighlightMatchingGroupPreferences;
import net.sf.jabref.preferences.JabRefPreferences;
import net.sf.jabref.preferences.LastFocusedTabPreferences;
import net.sf.jabref.preferences.SearchPreferences;
import net.sf.jabref.specialfields.Printed;
import net.sf.jabref.specialfields.Priority;
import net.sf.jabref.specialfields.Quality;
Expand Down Expand Up @@ -166,6 +170,7 @@ public class JabRefFrame extends JFrame implements OutputPrinter {
private final IntegrityCheckAction checkIntegrity = new IntegrityCheckAction(this);

private final ToolBar tlb = new ToolBar();
private final GlobalSearchBar globalSearchBar = new GlobalSearchBar(this);

private final JMenuBar mb = new JMenuBar();

Expand Down Expand Up @@ -305,6 +310,11 @@ public class JabRefFrame extends JFrame implements OutputPrinter {
Localization.menuTitle("Manage content selectors"));
private final AbstractAction normalSearch = new GeneralAction(Actions.SEARCH, Localization.menuTitle("Search"),
Localization.lang("Search"), Globals.getKeyPrefs().getKey(KeyBinding.SEARCH), IconTheme.JabRefIcon.SEARCH.getIcon());
private final AbstractAction globalSearch = new GeneralAction(Actions.GLOBAL_SEARCH,
Localization.menuTitle("Global Search"),
Localization.lang("Search globally"),
Globals.getKeyPrefs().getKey(KeyBinding.GLOBAL_SEARCH),
IconTheme.JabRefIcon.SEARCH.getIcon());

private final AbstractAction copyKey = new GeneralAction(Actions.COPY_KEY, Localization.menuTitle("Copy BibTeX key"),
Globals.getKeyPrefs().getKey(KeyBinding.COPY_BIBTEX_KEY));
Expand Down Expand Up @@ -633,23 +643,34 @@ public void windowClosing(WindowEvent e) {
tabbedPane.addChangeListener(e -> {
markActiveBasePanel();

BasePanel bp = getCurrentBasePanel();
if (bp == null) {
BasePanel currentBasePanel = getCurrentBasePanel();
if (currentBasePanel == null) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only disables the global search bar when the last database will be closed. But the search bar will be shown when one is starting jabref with no open database.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, I'll fix it quickly


if (new SearchPreferences(Globals.prefs).isGlobalSearch()) {
globalSearchBar.performSearch();
} else {
String content = "";
SearchQuery currentSearchQuery = currentBasePanel.getCurrentSearchQuery();
if (currentSearchQuery != null && !currentSearchQuery.getQuery().trim().isEmpty()) {
content = currentSearchQuery.getQuery();
}
globalSearchBar.setSearchTerm(content, true);
}

groupToggle.setSelected(sidePaneManager.isComponentVisible("groups"));
previewToggle.setSelected(Globals.prefs.getBoolean(JabRefPreferences.PREVIEW_ENABLED));
fetcherToggle.setSelected(sidePaneManager.isComponentVisible(generalFetcher.getTitle()));
Globals.getFocusListener().setFocused(bp.getMainTable());
Globals.getFocusListener().setFocused(currentBasePanel.getMainTable());
setWindowTitle();
editModeAction.initName();
// Update search autocompleter with information for the correct database:
bp.updateSearchManager();
currentBasePanel.updateSearchManager();
// Set correct enabled state for Back and Forward actions:
bp.setBackAndForwardEnabledState();
bp.getUndoManager().postUndoRedoEvent();
new FocusRequester(bp.getMainTable());
currentBasePanel.setBackAndForwardEnabledState();
currentBasePanel.getUndoManager().postUndoRedoEvent();
new FocusRequester(currentBasePanel.getMainTable());
});

//Note: The registration of Apple event is at the end of initialization, because
Expand Down Expand Up @@ -894,9 +915,12 @@ private void initLayout() {
//getContentPane().add(mb);
setJMenuBar(mb);
con.anchor = GridBagConstraints.NORTH;
//con.gridwidth = 1;//GridBagConstraints.REMAINDER;;
gbl.setConstraints(tlb, con);
getContentPane().add(tlb);

JPanel toolbarPanel = new JPanel(new WrapLayout(FlowLayout.LEFT));
toolbarPanel.add(tlb);
toolbarPanel.add(globalSearchBar);
gbl.setConstraints(toolbarPanel, con);
getContentPane().add(toolbarPanel);

Component lim = Box.createGlue();
gbl.setConstraints(lim, con);
Expand Down Expand Up @@ -1479,13 +1503,13 @@ private void createToolBar() {
tlb.addSeparator();

fetcherToggle = new JToggleButton(generalFetcher.getAction());
tlb.addJToogleButton(fetcherToggle);
tlb.addJToggleButton(fetcherToggle);

previewToggle = new JToggleButton(togglePreview);
tlb.addJToogleButton(previewToggle);
tlb.addJToggleButton(previewToggle);

groupToggle = new JToggleButton(toggleGroups);
tlb.addJToogleButton(groupToggle);
tlb.addJToggleButton(groupToggle);

tlb.addSeparator();

Expand All @@ -1509,7 +1533,7 @@ public void output(final String s) {

private void initActions() {
openDatabaseOnlyActions.clear();
openDatabaseOnlyActions.addAll(Arrays.asList(manageSelectors, mergeDatabaseAction, newSubDatabaseAction, save,
openDatabaseOnlyActions.addAll(Arrays.asList(manageSelectors, mergeDatabaseAction, newSubDatabaseAction, save, globalSearch,
saveAs, saveSelectedAs, saveSelectedAsPlain, editModeAction, undo, redo, cut, deleteEntry, copy, paste, mark, markSpecific, unmark,
unmarkAll, rankSubMenu, editEntry, selectAll, copyKey, copyCiteKey, copyKeyAndTitle, editPreamble, editStrings,
toggleGroups, makeKeyAction, normalSearch, generalFetcher.getAction(), mergeEntries, cleanupEntries, exportToClipboard, replaceAll,
Expand Down Expand Up @@ -2280,7 +2304,7 @@ public void addAction(Action a) {
add(b);
}

public void addJToogleButton(JToggleButton button) {
public void addJToggleButton(JToggleButton button) {
button.setText(null);
if (!OS.OS_X) {
button.setMargin(marg);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/sf/jabref/gui/actions/Actions.java
Expand Up @@ -50,6 +50,7 @@ public class Actions {
public static final String SAVE_SELECTED_AS = "saveSelectedAs";
public static final String SAVE_SELECTED_AS_PLAIN = "saveSelectedAsPlain";
public static final String SEARCH = "search";
public static final String GLOBAL_SEARCH = "globalSearch";
public static final String SELECT_ALL = "selectAll";
public static final String SEND_AS_EMAIL = "sendAsEmail";
public static final String SWITCH_PREVIEW = "switchPreview";
Expand Down
Expand Up @@ -279,4 +279,9 @@ public void focusLost(FocusEvent e) {
public void setAutoCompleter(AutoCompleter<E> autoCompleter) {
this.autoCompleter = autoCompleter;
}
}

public void setVisible(boolean visible){
popup.setVisible(visible);
}

}
Expand Up @@ -528,7 +528,7 @@ public Optional<JComponent> getExtra(final FieldEditor editor) {

private void setupSourcePanel() {
source = new JTextAreaWithHighlighting();
panel.getSearchBar().getSearchQueryHighlightObservable().addSearchListener((SearchQueryHighlightListener) source);
panel.frame().getGlobalSearchBar().getSearchQueryHighlightObservable().addSearchListener((SearchQueryHighlightListener) source);

source.setEditable(true);
source.setLineWrap(true);
Expand Down
Expand Up @@ -144,7 +144,7 @@ private void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField
defaultHeight = 0;
} else {
fieldEditor = new TextArea(field, null);
bPanel.getSearchBar().getSearchQueryHighlightObservable().addSearchListener((TextArea) fieldEditor);
bPanel.frame().getGlobalSearchBar().getSearchQueryHighlightObservable().addSearchListener((TextArea) fieldEditor);
defaultHeight = fieldEditor.getPane().getPreferredSize().height;
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/sf/jabref/gui/keyboard/KeyBinding.java
Expand Up @@ -6,6 +6,7 @@ public enum KeyBinding {

ABBREVIATE(
"Abbreviate", Localization.lang("Abbreviate journal names"), "ctrl alt A"),
ACCEPT("Accept", Localization.lang("Accept"), "ctrl ENTER"),
AUTOGENERATE_BIBTEX_KEYS("Autogenerate BibTeX keys", Localization.lang("Autogenerate BibTeX keys"), "ctrl G"),
AUTOMATICALLY_LINK_FILES(
"Automatically link files", Localization.lang("Automatically set file links"), "F7"),
Expand Down Expand Up @@ -38,6 +39,7 @@ public enum KeyBinding {
FIND_UNLINKED_FILES("Find unlinked files", Localization.lang("Find unlinked files"), "shift F7"),
FOCUS_ENTRY_TABLE("Focus entry table", Localization.lang("Focus entry table"), "alt 1"),
FORWARD("Forward", Localization.lang("Forward"), "alt RIGHT"),
GLOBAL_SEARCH("Search globally", Localization.lang("Search globally"), "ctrl shift F"),
HELP("Help", Localization.lang("Help"), "F1"),
IMPORT_INTO_CURRENT_DATABASE("Import into current database", Localization.lang("Import into current database"), "ctrl I"),
IMPORT_INTO_NEW_DATABASE("Import into new database", Localization.lang("Import into new database"), "ctrl alt I"),
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/net/sf/jabref/gui/maintable/MainTable.java
Expand Up @@ -182,6 +182,18 @@ public void actionPerformed(ActionEvent e) {
panel.selectPreviousEntry();
}
});
am.put("selectNextRow", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
panel.selectNextEntry();
}
});
am.put("selectPreviousRow", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
panel.selectPreviousEntry();
}
});
}

public void addSelectionListener(ListEventListener<BibEntry> listener) {
Expand Down