Skip to content

Commit

Permalink
Switch colors of search icon for the two search modes (#3871)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenhard authored and koppor committed Apr 12, 2018
1 parent 184a459 commit be91964
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ The new default removes the linked file from the entry instead of deleting the f
- We fixed the name of the group editing window to "Add group" instead of "Edit Group" when adding a new group. [koppor#277](https://github.com/koppor/jabref/issues/277)
- We fixed the `pureauth` [BibTeX key generator pattern](https://help.jabref.org/en/BibtexKeyPatterns) to just return the author if no author, but an editor is present.
- We fixed an issue where the "Copy linked files" dialog produced an error when the entry had no file [#3818](https://github.com/JabRef/jabref/issues/3818)
- We fixed the coloring of the search box icon in case a user switches to advanced search mode [#3870](https://github.com/JabRef/jabref/issues/3870)
- We fixed an issue where pressing <kbd>del</kbd> in the `file` field would trigger the delete dialog a second file, if the first file is deleted [#3926](https://github.com/JabRef/jabref/issues/3926)

### Removed
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/gui/search/GlobalSearchBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,11 @@ public void performSearch() {
searchWorker.cancel(true);
}

// An empty search field should cause the search to be cleared.
// An empty search field should cause the search to be cleared
if (searchField.getText().isEmpty()) {
clearSearch(currentBasePanel);
// also make sure the search icon has the standard color
searchIcon.setIcon(IconTheme.JabRefIcon.SEARCH.getIcon());
return;
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/jabref/logic/search/SearchQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ private String getLocalizedRegularExpressionDescription() {
}
}

/**
* Tests if the query is an advanced search query described as described in the help
*
* @return true if the query is an advanced search query
*/
public boolean isGrammarBasedSearch() {
return rule instanceof GrammarBasedSearchRule;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

/**
* The search query must be specified in an expression that is acceptable by the Search.g4 grammar.
*
* This class implements the "Advanced Search Mode" described in the help
*/
public class GrammarBasedSearchRule implements SearchRule {

Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/jabref/model/search/rules/SearchRules.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package org.jabref.model.search.rules;

import org.jabref.model.strings.StringUtil;
import java.util.regex.Pattern;

public class SearchRules {


private static final Pattern SIMPLE_EXPRESSION = Pattern.compile("[^\\p{Punct}]*");

private SearchRules() {
}

/**
* Returns the appropriate search rule that fits best to the given parameter.
*/
public static SearchRule getSearchRuleByQuery(String query, boolean caseSensitive, boolean regex) {
if (StringUtil.isBlank(query)) {
if (isSimpleQuery(query)) {
return new ContainBasedSearchRule(caseSensitive);
}

Expand All @@ -25,6 +28,10 @@ public static SearchRule getSearchRuleByQuery(String query, boolean caseSensitiv
}
}

private static boolean isSimpleQuery(String query) {
return SIMPLE_EXPRESSION.matcher(query).matches();
}

private static SearchRule getSearchRule(boolean caseSensitive, boolean regex) {
if (regex) {
return new RegexBasedSearchRule(caseSensitive);
Expand Down
17 changes: 13 additions & 4 deletions src/test/java/org/jabref/logic/search/SearchQueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public void testToString() {

@Test
public void testIsContainsBasedSearch() {
assertFalse(new SearchQuery("asdf", true, false).isContainsBasedSearch());
assertFalse(new SearchQuery("asdf", true, true).isContainsBasedSearch());
assertTrue(new SearchQuery("asdf", true, false).isContainsBasedSearch());
assertTrue(new SearchQuery("asdf", true, true).isContainsBasedSearch());
assertFalse(new SearchQuery("author=asdf", true, false).isContainsBasedSearch());
}

@Test
public void testIsGrammarBasedSearch() {
assertTrue(new SearchQuery("asdf", true, false).isGrammarBasedSearch());
assertTrue(new SearchQuery("asdf", true, true).isGrammarBasedSearch());
assertFalse(new SearchQuery("asdf", true, false).isGrammarBasedSearch());
assertFalse(new SearchQuery("asdf", true, true).isGrammarBasedSearch());
assertTrue(new SearchQuery("author=asdf", true, false).isGrammarBasedSearch());
}

Expand Down Expand Up @@ -186,4 +186,13 @@ public void isMatchedForNormalAndFieldBasedSearchMixed() {

}

@Test
public void testSimpleTerm() {
String query = "progress";

SearchQuery result = new SearchQuery(query, false, false);

assertFalse(result.isGrammarBasedSearch());
}

}

0 comments on commit be91964

Please sign in to comment.