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

Remove unuseful search syntax feedback #7391

Merged
merged 2 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,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 @@ -2264,9 +2264,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