Skip to content

Commit

Permalink
added a option to allow integer field in edition during check integri…
Browse files Browse the repository at this point in the history
…ty even in Bibtex Mode. fixes JabRef#4680
  • Loading branch information
eboliveira committed Jun 25, 2019
1 parent eb42850 commit a0e1034
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/jabref/gui/preferences/GeneralTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/org/jabref/logic/integrity/EditionChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,28 @@
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<String> FIRST_LETTER_CAPITALIZED = Pattern.compile("^[A-Z]").asPredicate();
private static final Predicate<String> ONLY_NUMERALS_OR_LITERALS = Pattern.compile("^([0-9]+|[^0-9].+)$")
.asPredicate();
private static final String FIRST_EDITION = "1";

private final BibDatabaseContext bibDatabaseContextEdition;

private final JabRefPreferences prefs;


public EditionChecker(BibDatabaseContext bibDatabaseContext) {
this.prefs = Globals.prefs;
this.bibDatabaseContextEdition = Objects.requireNonNull(bibDatabaseContext);
}

Expand Down Expand Up @@ -49,8 +56,16 @@ public Optional<String> 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();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a0e1034

Please sign in to comment.