Skip to content

Commit

Permalink
Implemented #1034
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Mar 25, 2016
1 parent 27f50f7 commit 2ae8117
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ to [sourceforge feature requests](https://sourceforge.net/p/jabref/features/) by
- Implemented [#462](https://github.com/JabRef/jabref/issues/462): Add new action to open console where opened database file is located. New button, menu entry and shortcut (CTRL+SHIFT+J) for this action have also been added.
- [#957](https://github.com/JabRef/jabref/issues/957) Improved usability of Export save order selection in Preferences and Database Properties
- [#958](https://github.com/JabRef/jabref/issues/958) Adjusted size and changed layout of database dialog

- [#1023](https://github.com/JabRef/jabref/issues/492) ArXiv fetcher now also fetches based on eprint id
- [#1034](https://github.com/JabRef/jabref/issues/1034) Select if the search results should be updated on every pressed key or on enter only

### Fixed
- Fixed [#598](https://github.com/JabRef/jabref/issues/598) and [#402](https://github.com/JabRef/jabref/issues/402): No more issues with invalid icons for ExternalFileTypes in global search or after editing the settings
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/sf/jabref/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public class JabRefPreferences {
public static final String SEARCH_PANE_POS_Y = "searchPanePosY";
public static final String SEARCH_PANE_POS_X = "searchPanePosX";
public static final String SEARCH_REG_EXP = "regExpSearch";
public static final String SEARCH_LIVE = "searchLive";
public static final String EDITOR_EMACS_KEYBINDINGS = "editorEMACSkeyBindings";
public static final String EDITOR_EMACS_KEYBINDINGS_REBIND_CA = "editorEMACSkeyBindingsRebindCA";
public static final String EDITOR_EMACS_KEYBINDINGS_REBIND_CF = "editorEMACSkeyBindingsRebindCF";
Expand Down Expand Up @@ -580,6 +581,7 @@ private JabRefPreferences() {
defaults.put(DEFAULT_AUTO_SORT, Boolean.FALSE);
defaults.put(SEARCH_CASE_SENSITIVE, Boolean.FALSE);
defaults.put(SEARCH_MODE_FILTER, Boolean.TRUE);
defaults.put(SEARCH_LIVE, Boolean.TRUE);

defaults.put(SEARCH_REG_EXP, Boolean.FALSE);
defaults.put(SEARCH_PANE_POS_X, 0);
Expand Down
27 changes: 21 additions & 6 deletions src/main/java/net/sf/jabref/gui/search/SearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class SearchBar extends JPanel {

private final JToggleButton caseSensitive;
private final JToggleButton regularExp;
private final JToggleButton liveSearch;

private final JLabel currentResults = new JLabel("");

Expand All @@ -89,19 +90,27 @@ public SearchBar(BasePanel basePanel) {
caseSensitive = new JToggleButton(IconTheme.JabRefIcon.CASE_SENSITIVE.getSmallIcon(),Globals.prefs.getBoolean(JabRefPreferences.SEARCH_CASE_SENSITIVE));
caseSensitive.setToolTipText(Localization.lang("Case sensitive"));
caseSensitive.addActionListener(e -> {
performSearch();
performSearch(false);
updatePreferences();
});


regularExp = new JToggleButton(IconTheme.JabRefIcon.REG_EX.getSmallIcon(), Globals.prefs.getBoolean(JabRefPreferences.SEARCH_REG_EXP));
regularExp.setToolTipText(Localization.lang("regular expression"));
regularExp.addActionListener(e -> {
performSearch();
performSearch(false);
updatePreferences();
});


liveSearch = new JToggleButton(IconTheme.JabRefIcon.REFRESH.getSmallIcon(),
Globals.prefs.getBoolean(JabRefPreferences.SEARCH_LIVE));
liveSearch.setToolTipText(Localization.lang("Activate search on typing"));
liveSearch.addActionListener(e -> {
performSearch(true); // If we enable live search, update search, if we disable it, do not
updatePreferences();
});

openCurrentResultsInDialog = new JButton(IconTheme.JabRefIcon.OPEN_IN_NEW_WINDOW.getSmallIcon());
openCurrentResultsInDialog.setToolTipText(Localization.lang("Show search results in a window"));
openCurrentResultsInDialog.addActionListener(ae -> {
Expand Down Expand Up @@ -138,6 +147,7 @@ public SearchBar(BasePanel basePanel) {
JToolBar toolBar = new OSXCompatibleToolbar();
toolBar.setFloatable(false);
toolBar.add(clearSearchButton);
toolBar.add(liveSearch);
toolBar.addSeparator();
toolBar.add(regularExp);
toolBar.add(caseSensitive);
Expand Down Expand Up @@ -188,7 +198,7 @@ private void toggleSearchModeAndSearch() {
this.searchMode = searchMode == SearchMode.FILTER ? SearchMode.FLOAT : SearchMode.FILTER;
updatePreferences();
updateSearchModeButtonText();
performSearch();
performSearch(false);
}

private void updateSearchModeButtonText() {
Expand Down Expand Up @@ -221,10 +231,10 @@ public void keyReleased(KeyEvent e) {
searchField.addFocusListener(Globals.focusListener);

// Search if user press enter
searchField.addActionListener(e -> performSearch());
searchField.addActionListener(e -> performSearch(false));

// Subscribe to changes to the text in the search field in order to "live search"
JTextFieldChangeListenerUtil.addChangeListener(searchField, e -> performSearch());
JTextFieldChangeListenerUtil.addChangeListener(searchField, e -> performSearch(true));

return searchField;
}
Expand All @@ -245,6 +255,7 @@ public void updatePreferences() {

Globals.prefs.putBoolean(JabRefPreferences.SEARCH_CASE_SENSITIVE, caseSensitive.isSelected());
Globals.prefs.putBoolean(JabRefPreferences.SEARCH_REG_EXP, regularExp.isSelected());
Globals.prefs.putBoolean(JabRefPreferences.SEARCH_LIVE, liveSearch.isSelected());
}

/**
Expand Down Expand Up @@ -279,7 +290,11 @@ private void clearSearch() {
/**
* Performs a new search based on the current search query.
*/
private void performSearch() {
private void performSearch(boolean checkLiveSearch) {
if (checkLiveSearch && !liveSearch.isSelected()) {
// If we should check if the live search button is selected and it is not, do nothing
return;
}
// An empty search field should cause the search to be cleared.
if (searchField.getText().isEmpty()) {
clearSearch();
Expand Down

0 comments on commit 2ae8117

Please sign in to comment.