Skip to content

Commit

Permalink
Remove unuseful search syntax feedback (#7391)
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikVoigt committed Feb 1, 2021
1 parent 6ace80f commit 66a771c
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ protected Node createContentPane() {
// Create text field for query input
TextField query = SearchTextField.create();
query.getStyleClass().add("searchBar");
query.textProperty().addListener((observable, oldValue, newValue) -> viewModel.validateQueryStringAndGiveColorFeedback(query, newValue));
query.focusedProperty().addListener((observable, oldValue, newValue) -> {
if (newValue) {
viewModel.validateQueryStringAndGiveColorFeedback(query, query.getText());
} else {
viewModel.setPseudoClassToValid(query);
}
});

viewModel.queryProperty().bind(query.textProperty());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.jabref.gui.importer.fetcher;

import java.util.SortedSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javafx.beans.property.ListProperty;
import javafx.beans.property.ObjectProperty;
Expand All @@ -12,9 +10,6 @@
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.css.PseudoClass;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
Expand All @@ -36,8 +31,6 @@ public class WebSearchPaneViewModel {
private final StringProperty query = new SimpleStringProperty();
private final DialogService dialogService;
private final StateManager stateManager;
private final Pattern queryPattern;
private final Pattern laxQueryPattern;

public WebSearchPaneViewModel(PreferencesService preferencesService, DialogService dialogService, StateManager stateManager) {
this.dialogService = dialogService;
Expand All @@ -57,13 +50,6 @@ public WebSearchPaneViewModel(PreferencesService preferencesService, DialogServi
int newIndex = fetchers.indexOf(newFetcher);
preferencesService.storeSidePanePreferences(preferencesService.getSidePanePreferences().withWebSearchFetcherSelected(newIndex));
});

String allowedFields = "((author|abstract|journal|title|year|year-range):\\s?)?";
// Either a single word, or a phrase with quotes, or a year-range
String allowedTermText = "(((\\d{4}-\\d{4})|(\\w+)|(\"\\w+[^\"]*\"))\\s?)+";
queryPattern = Pattern.compile("^(" + allowedFields + allowedTermText + ")+$");
String laxFields = "(\\w+:\\s?)?";
laxQueryPattern = Pattern.compile("^(" + laxFields + allowedTermText + ")+$");
}

public ObservableList<SearchBasedFetcher> getFetchers() {
Expand Down Expand Up @@ -112,41 +98,4 @@ public void search() {
dialog.setTitle(activeFetcher.getName());
dialogService.showCustomDialogAndWait(dialog);
}

public void validateQueryStringAndGiveColorFeedback(TextField querySource, String queryString) {
Matcher queryValidation = queryPattern.matcher(queryString.strip());
if (!queryString.strip().isBlank() && !queryValidation.matches()) {
Matcher laxQueryValidation = laxQueryPattern.matcher(queryString.strip());
if (laxQueryValidation.matches()) {
setPseudoClassToUnsupported(querySource);
querySource.setTooltip(new Tooltip(Localization.lang("This query uses unsupported fields.")));
} else {
setPseudoClassToInvalid(querySource);
querySource.setTooltip(new Tooltip(Localization.lang("This query uses unsupported syntax.")));
}
} else if (containsYearAndYearRange(queryString)) {
setPseudoClassToInvalid(querySource);
querySource.setTooltip(new Tooltip(Localization.lang("The query cannot contain a year and year-range field.")));
} else {
setPseudoClassToValid(querySource);
}
}

private void setPseudoClassToUnsupported(TextField querySource) {
querySource.pseudoClassStateChanged(PseudoClass.getPseudoClass("invalid"), false);
querySource.pseudoClassStateChanged(PseudoClass.getPseudoClass("unsupported"), true);
}

public void setPseudoClassToValid(TextField querySource) {
querySource.pseudoClassStateChanged(PseudoClass.getPseudoClass("invalid"), false);
querySource.pseudoClassStateChanged(PseudoClass.getPseudoClass("unsupported"), false);
}

private void setPseudoClassToInvalid(TextField querySource) {
querySource.pseudoClassStateChanged(PseudoClass.getPseudoClass("invalid"), true);
}

private boolean containsYearAndYearRange(String queryString) {
return queryString.toLowerCase().contains("year:") && queryString.toLowerCase().contains("year-range:");
}
}
3 changes: 0 additions & 3 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2257,9 +2257,6 @@ Remove\ redundant\ spaces=Remove redundant spaces
Replaces\ consecutive\ spaces\ with\ a\ single\ space\ in\ the\ field\ content.=Replaces consecutive spaces with a single space in the field content.
Remove\ digits=Remove digits
Removes\ digits.=Removes digits.
The\ query\ cannot\ contain\ a\ year\ and\ year-range\ field.=The query cannot contain a year and year-range field.
This\ query\ uses\ unsupported\ fields.=This query uses unsupported fields.
This\ query\ uses\ unsupported\ syntax.=This query uses unsupported syntax.
Presets=Presets
Expand Down

0 comments on commit 66a771c

Please sign in to comment.