From a0e103440636272dd3ec170688297e26a66b08d6 Mon Sep 17 00:00:00 2001 From: Eduardo Date: Tue, 25 Jun 2019 14:37:07 -0300 Subject: [PATCH] added a option to allow integer field in edition during check integrity even in Bibtex Mode. fixes #4680 --- CHANGELOG.md | 1 + .../jabref/gui/preferences/GeneralTab.java | 5 +++++ .../logic/integrity/EditionChecker.java | 19 +++++++++++++++++-- .../jabref/preferences/JabRefPreferences.java | 2 ++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bca01e2d50f..39b4f72f619 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We moved the dropdown menu for selecting the push-application from the toolbar into the external application preferences. [#674](https://github.com/JabRef/jabref/issues/674) - We removed the alphabetical ordering of the custom tabs and updated the error message when trying to create a general field with a name containing an illegal character. [#5019](https://github.com/JabRef/jabref/issues/5019) - We added a context menu to the bib(la)tex-source-editor to copy'n'paste. [#5007](https://github.com/JabRef/jabref/pull/5007) +- We added a option to allow integer field in edition during check integrity even in Bibtex Mode. [#4680](https://github.com/JabRef/jabref/issues/4680) ### Fixed diff --git a/src/main/java/org/jabref/gui/preferences/GeneralTab.java b/src/main/java/org/jabref/gui/preferences/GeneralTab.java index 4c76449acdb..49f965b7a2f 100644 --- a/src/main/java/org/jabref/gui/preferences/GeneralTab.java +++ b/src/main/java/org/jabref/gui/preferences/GeneralTab.java @@ -44,6 +44,7 @@ class GeneralTab extends Pane implements PrefsTab { private final CheckBox useTimeStamp; private final CheckBox updateTimeStamp; private final CheckBox overwriteTimeStamp; + private final CheckBox allowEditionInteger; private final TextField defOwnerField; private final GridPane builder = new GridPane(); @@ -80,6 +81,7 @@ public GeneralTab(DialogService dialogService, JabRefPreferences prefs) { inspectionWarnDupli = new CheckBox(Localization.lang("Warn about unresolved duplicates when closing inspection window")); showAdvancedHints = new CheckBox(Localization.lang("Show advanced hints (i.e. helpful tooltips, suggestions and explanation)")); shouldCollectTelemetry = new CheckBox(Localization.lang("Collect and share telemetry data to help improve JabRef.")); + allowEditionInteger = new CheckBox(Localization.lang("Allow edition field Integer when in Bibtex mode")); encodings = new ComboBox<>(FXCollections.observableArrayList(Encodings.ENCODINGS)); Label general = new Label(Localization.lang("General")); @@ -139,6 +141,7 @@ public GeneralTab(DialogService dialogService, JabRefPreferences prefs) { builder.add(biblioBox, 1, 29); builder.add(showAdvancedHints,1,30); + builder.add(allowEditionInteger,1,31); } @Override @@ -169,6 +172,7 @@ public void setValues() { encodings.setValue(prefs.getDefaultEncoding()); languageSelection.setValue(prefs.getLanguage()); showAdvancedHints.setSelected(prefs.getBoolean(JabRefPreferences.SHOW_ADVANCED_HINTS)); + allowEditionInteger.setSelected(prefs.getBoolean(JabRefPreferences.ALLOW_EDITION_INTEGER)); } @Override @@ -187,6 +191,7 @@ public void storeSettings() { } prefs.putBoolean(JabRefPreferences.MEMORY_STICK_MODE, memoryStick.isSelected()); prefs.putBoolean(JabRefPreferences.SHOW_ADVANCED_HINTS, showAdvancedHints.isSelected()); + prefs.putBoolean(JabRefPreferences.ALLOW_EDITION_INTEGER, allowEditionInteger.isSelected()); prefs.putBoolean(JabRefPreferences.CONFIRM_DELETE, confirmDelete.isSelected()); prefs.putBoolean(JabRefPreferences.WARN_ABOUT_DUPLICATES_IN_INSPECTION, inspectionWarnDupli.isSelected()); String owner = defOwnerField.getText().trim(); diff --git a/src/main/java/org/jabref/logic/integrity/EditionChecker.java b/src/main/java/org/jabref/logic/integrity/EditionChecker.java index c382fe7eab1..0da3e05d84c 100644 --- a/src/main/java/org/jabref/logic/integrity/EditionChecker.java +++ b/src/main/java/org/jabref/logic/integrity/EditionChecker.java @@ -5,12 +5,16 @@ import java.util.function.Predicate; import java.util.regex.Pattern; +import org.jabref.Globals; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.strings.StringUtil; +import org.jabref.preferences.JabRefPreferences; + public class EditionChecker implements ValueChecker { + private static final Predicate FIRST_LETTER_CAPITALIZED = Pattern.compile("^[A-Z]").asPredicate(); private static final Predicate ONLY_NUMERALS_OR_LITERALS = Pattern.compile("^([0-9]+|[^0-9].+)$") .asPredicate(); @@ -18,8 +22,11 @@ public class EditionChecker implements ValueChecker { private final BibDatabaseContext bibDatabaseContextEdition; + private final JabRefPreferences prefs; + public EditionChecker(BibDatabaseContext bibDatabaseContext) { + this.prefs = Globals.prefs; this.bibDatabaseContextEdition = Objects.requireNonNull(bibDatabaseContext); } @@ -49,8 +56,16 @@ public Optional checkValue(String value) { } //BibTeX - if (!bibDatabaseContextEdition.isBiblatexMode() && !FIRST_LETTER_CAPITALIZED.test(value.trim())) { - return Optional.of(Localization.lang("should have the first letter capitalized")); + if (!bibDatabaseContextEdition.isBiblatexMode()) { + if(ONLY_NUMERALS_OR_LITERALS.test(value.trim())){ + if(!prefs.getBoolean(JabRefPreferences.ALLOW_EDITION_INTEGER)){ + return Optional.of(Localization.lang("should be a String but received a Integer")); + } + }else{ + if(!FIRST_LETTER_CAPITALIZED.test(value.trim())){ + return Optional.of(Localization.lang("should have the first letter capitalized")); + } + } } return Optional.empty(); diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 253b64cb8e4..ccac1d6507f 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -284,6 +284,7 @@ public class JabRefPreferences implements PreferencesService { public static final String WEB_SEARCH_VISIBLE = "webSearchVisible"; public static final String GROUP_SIDEPANE_VISIBLE = "groupSidepaneVisible"; public static final String ALLOW_FILE_AUTO_OPEN_BROWSE = "allowFileAutoOpenBrowse"; + public static final String ALLOW_EDITION_INTEGER = "allowEditionInteger"; public static final String CUSTOM_TAB_NAME = "customTabName_"; public static final String CUSTOM_TAB_FIELDS = "customTabFields_"; public static final String USE_UNIT_FORMATTER_ON_SEARCH = "useUnitFormatterOnSearch"; @@ -704,6 +705,7 @@ private JabRefPreferences() { defaults.put(EMAIL_SUBJECT, Localization.lang("References")); defaults.put(OPEN_FOLDERS_OF_ATTACHED_FILES, Boolean.FALSE); defaults.put(ALLOW_FILE_AUTO_OPEN_BROWSE, Boolean.TRUE); + defaults.put(ALLOW_EDITION_INTEGER, Boolean.FALSE); defaults.put(WEB_SEARCH_VISIBLE, Boolean.TRUE); defaults.put(GROUP_SIDEPANE_VISIBLE, Boolean.TRUE); defaults.put(SELECTED_FETCHER_INDEX, 0);