Skip to content

Commit

Permalink
Change based on comment
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Mar 25, 2016
1 parent 64c4348 commit 55fc5f2
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/main/java/net/sf/jabref/gui/search/SearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ 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(false);
performSearch();
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(false);
performSearch();
updatePreferences();
});

Expand All @@ -107,7 +107,7 @@ public SearchBar(BasePanel basePanel) {
Globals.prefs.getBoolean(JabRefPreferences.SEARCH_LIVE));
liveSearch.setToolTipText(Localization.lang("Search on typing"));
liveSearch.addActionListener(e -> {
performSearch(true); // If we enable live search, update search, if we disable it, do not
performSearchIfLive();
updatePreferences();
});

Expand Down Expand Up @@ -198,7 +198,7 @@ private void toggleSearchModeAndSearch() {
this.searchMode = searchMode == SearchMode.FILTER ? SearchMode.FLOAT : SearchMode.FILTER;
updatePreferences();
updateSearchModeButtonText();
performSearch(false);
performSearch();
}

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

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

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

return searchField;
}
Expand Down Expand Up @@ -287,14 +287,20 @@ private void clearSearch() {
searchIcon.setIcon(IconTheme.JabRefIcon.SEARCH.getSmallIcon());
}



/**
* Performs a new search based on the current search query.
* Checks if the search should be "live" and then performs a new search based on the current search query.
*/
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;
private void performSearchIfLive() {
if (liveSearch.isSelected()) {
performSearch();
}
}
/**
* Performs a new search based on the current search query.
*/
private void performSearch() {
// An empty search field should cause the search to be cleared.
if (searchField.getText().isEmpty()) {
clearSearch();
Expand Down

0 comments on commit 55fc5f2

Please sign in to comment.