Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 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 @@ -26,7 +26,7 @@ public class KeywordsEditorViewModel extends AbstractEditorViewModel {
private static final Logger LOGGER = LoggerFactory.getLogger(KeywordsEditorViewModel.class);

private final ListProperty<Keyword> keywordListProperty;
private final Character keywordSeparator;
private final String keywordSeparator;
private final SuggestionProvider<?> suggestionProvider;

public KeywordsEditorViewModel(Field field,
Expand All @@ -49,11 +49,15 @@ public KeywordsEditorViewModel(Field field,
}

private String serializeKeywords(List<Keyword> keywords) {
return KeywordList.serialize(keywords, keywordSeparator);
return KeywordList.serialize(keywords, ',');
}

private List<Keyword> parseKeywords(String newText) {
return KeywordList.parse(newText, keywordSeparator).stream().toList();
for (char d : keywordSeparator.toCharArray()) {
newText = newText.replace(d, ',');
}

return KeywordList.parse(newText, ',').stream().toList();
}

public ListProperty<Keyword> keywordListProperty() {
Expand Down Expand Up @@ -94,7 +98,7 @@ public List<Keyword> getSuggestions(String request) {
return suggestions;
}

public Character getKeywordSeparator() {
public String getKeywordSeparator() {
return keywordSeparator;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.jabref.gui.preferences.entry;

import java.util.function.UnaryOperator;

import javafx.css.PseudoClass;
import javafx.fxml.FXML;
import javafx.scene.Node;
Expand All @@ -10,7 +8,6 @@
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TextFormatter;
import javafx.scene.input.KeyCode;

import org.jabref.gui.actions.ActionFactory;
Expand Down Expand Up @@ -57,15 +54,15 @@ public void initialize() {
keywordSeparator.textProperty().bindBidirectional(viewModel.keywordSeparatorProperty());

// Use TextFormatter to limit the length of the Input of keywordSeparator to 1 character only.
UnaryOperator<TextFormatter.Change> singleCharacterFilter = change -> {
if (change.getControlNewText().length() <= 1) {
return change;
}
return null; // null means the change is rejected
};
TextFormatter<String> formatter = new TextFormatter<>(singleCharacterFilter);

keywordSeparator.setTextFormatter(formatter);
// UnaryOperator<TextFormatter.Change> singleCharacterFilter = change -> {
// if (change.getControlNewText().length() <= 1) {
// return change;
// }
// return null; // null means the change is rejected
// };
// TextFormatter<String> formatter = new TextFormatter<>(singleCharacterFilter);

// keywordSeparator.setTextFormatter(formatter);

resolveStrings.selectedProperty().bindBidirectional(viewModel.resolveStringsProperty());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AutoSetFileLinksUtilTest {
AutoLinkPreferences.CitationKeyDependency.START,
"",
false,
';');
";");
private final BibDatabaseContext databaseContext = mock(BibDatabaseContext.class);
private final BibEntry entry = new BibEntry(StandardEntryType.Article);
private Path path = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public String expand(BibEntry bibentry) {
*/
public String expand(BibEntry bibentry, BibDatabase database) {
Objects.requireNonNull(bibentry);
Character keywordDelimiter = ';';
String keywordDelimiter = ";";
return expand(bibentry, keywordDelimiter, database);
}

Expand All @@ -177,7 +177,7 @@ public String expand(BibEntry bibentry, BibDatabase database) {
* @param database The database to use for string-lookups and cross-refs. May be null.
* @return The expanded pattern. The empty string is returned, if it could not be expanded.
*/
public String expand(BibEntry bibentry, Character keywordDelimiter, BibDatabase database) {
public String expand(BibEntry bibentry, String keywordDelimiter, BibDatabase database) {
Objects.requireNonNull(bibentry);
return expandBrackets(this.pattern, keywordDelimiter, bibentry, database);
}
Expand All @@ -191,7 +191,7 @@ public String expand(BibEntry bibentry, Character keywordDelimiter, BibDatabase
* @param database The database for field resolving. May be null.
* @return The expanded pattern. Not null.
*/
public static String expandBrackets(String pattern, Character keywordDelimiter, BibEntry entry, BibDatabase database) {
public static String expandBrackets(String pattern, String keywordDelimiter, BibEntry entry, BibDatabase database) {
Objects.requireNonNull(pattern);
Objects.requireNonNull(entry);
return expandBrackets(pattern, expandBracketContent(keywordDelimiter, entry, database));
Expand All @@ -206,7 +206,7 @@ public static String expandBrackets(String pattern, Character keywordDelimiter,
* @param database The {@link BibDatabase} for field resolving. May be null.
* @return a function accepting a bracketed expression and returning the result of expanding it
*/
public static Function<String, String> expandBracketContent(Character keywordDelimiter, BibEntry entry, BibDatabase database) {
public static Function<String, String> expandBracketContent(String keywordDelimiter, BibEntry entry, BibDatabase database) {
return (String bracket) -> {
List<String> fieldParts = parseFieldAndModifiers(bracket);
// check whether there is a modifier on the end such as
Expand Down Expand Up @@ -259,7 +259,7 @@ public static String expandBrackets(String pattern, Function<String, String> bra
/**
* Returns the content enclosed between brackets, including enclosed quotes, and excluding the paired enclosing brackets.
* There may be brackets in it.
* Intended to be used by {@link BracketedPattern#expandBrackets(String, Character, BibEntry, BibDatabase)} when a [
* Intended to be used by {@link BracketedPattern#expandBrackets(String, String, BibEntry, BibDatabase)} when a [
* is encountered, and has been consumed, by the {@code StringTokenizer}.
*
* @param pattern pattern used by {@code expandBrackets}, used for logging
Expand Down Expand Up @@ -302,7 +302,7 @@ private static String contentBetweenBrackets(StringTokenizer tokenizer, final St

/**
* Appends the content between, and including, two \" to the provided <code>StringBuilder</code>. Intended to be
* used by {@link BracketedPattern#expandBrackets(String, Character, BibEntry, BibDatabase)} when a \" is
* used by {@link BracketedPattern#expandBrackets(String, String, BibEntry, BibDatabase)} when a \" is
* encountered by the StringTokenizer.
*
* @param stringBuilder the <code>StringBuilder</code> to which tokens will be appended
Expand All @@ -326,7 +326,7 @@ private static void appendQuote(StringBuilder stringBuilder, StringTokenizer tok
* @param database The database to use for field resolving. May be null.
* @return String containing the evaluation result. Empty string if the pattern cannot be resolved.
*/
public static String getFieldValue(BibEntry entry, String pattern, Character keywordDelimiter, BibDatabase database) {
public static String getFieldValue(BibEntry entry, String pattern, String keywordDelimiter, BibDatabase database) {
try {
if (pattern.startsWith("auth") || pattern.startsWith("pureauth")) {
// result the author
Expand Down Expand Up @@ -481,7 +481,15 @@ public static String getFieldValue(BibEntry entry, String pattern, Character key
} else if (pattern.matches("keyword\\d+")) {
// according to LabelPattern.php, it returns keyword number n
int num = Integer.parseInt(pattern.substring(7));
KeywordList separatedKeywords = entry.getResolvedKeywords(keywordDelimiter, database);
// KeywordList separatedKeywords = entry.getResolvedKeywords(keywordDelimiter, database);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented code should be removed as it serves no purpose in understanding the current implementation and clutters the codebase. Git history should be used to track changes.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another instance of commented code that should be removed. Version control systems like Git are designed to maintain code history, making commented-out code unnecessary.


Optional<String> keywordsContent = entry.getResolvedFieldOrAlias(StandardField.KEYWORDS, database);

for (char d : keywordDelimiter.toCharArray()) {
keywordsContent = keywordsContent.map(content -> content.replace(d, ','));
}
KeywordList separatedKeywords = keywordsContent.map(content -> KeywordList.parse(content, ',')).orElse(new KeywordList());

if (separatedKeywords.size() < num) {
// not enough keywords
return "";
Expand All @@ -497,7 +505,14 @@ public static String getFieldValue(BibEntry entry, String pattern, Character key
} else {
num = Integer.MAX_VALUE;
}
KeywordList separatedKeywords = entry.getResolvedKeywords(keywordDelimiter, database);
// KeywordList separatedKeywords = entry.getResolvedKeywords(keywordDelimiter, database);
Optional<String> keywordsContent = entry.getResolvedFieldOrAlias(StandardField.KEYWORDS, database);

for (char d : keywordDelimiter.toCharArray()) {
keywordsContent = keywordsContent.map(content -> content.replace(d, ','));
}
KeywordList separatedKeywords = keywordsContent.map(content -> KeywordList.parse(content, ',')).orElse(new KeywordList());

StringBuilder sb = new StringBuilder();
int i = 0;
for (Keyword keyword : separatedKeywords) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private String createCitationKeyFromPattern(BibEntry entry) {
* @return a cleaned citation key for the given {@link BibEntry}
*/
private Function<String, String> expandBracketContent(BibEntry entry) {
Character keywordDelimiter = citationKeyPatternPreferences.getKeywordDelimiter();
String keywordDelimiter = citationKeyPatternPreferences.getKeywordDelimiter();

return (String bracket) -> {
String expandedPattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public enum KeySuffix {
private final StringProperty unwantedCharacters = new SimpleStringProperty();
private final ObjectProperty<GlobalCitationKeyPatterns> keyPatterns = new SimpleObjectProperty<>();
private final String defaultPattern;
private final ReadOnlyObjectProperty<Character> keywordDelimiter;
private final ReadOnlyObjectProperty<String> keywordDelimiter;

public CitationKeyPatternPreferences(boolean shouldAvoidOverwriteCiteKey,
boolean shouldWarnBeforeOverwriteCiteKey,
Expand All @@ -38,7 +38,7 @@ public CitationKeyPatternPreferences(boolean shouldAvoidOverwriteCiteKey,
String unwantedCharacters,
GlobalCitationKeyPatterns keyPatterns,
String defaultPattern,
ReadOnlyObjectProperty<Character> keywordDelimiter) {
ReadOnlyObjectProperty<String> keywordDelimiter) {

this.shouldAvoidOverwriteCiteKey.set(shouldAvoidOverwriteCiteKey);
this.shouldWarnBeforeOverwriteCiteKey.set(shouldWarnBeforeOverwriteCiteKey);
Expand All @@ -63,7 +63,7 @@ public CitationKeyPatternPreferences(boolean shouldAvoidOverwriteCiteKey,
String unwantedCharacters,
GlobalCitationKeyPatterns keyPatterns,
String defaultPattern,
Character keywordDelimiter) {
String keywordDelimiter) {

this(shouldAvoidOverwriteCiteKey,
shouldWarnBeforeOverwriteCiteKey,
Expand Down Expand Up @@ -177,7 +177,7 @@ public String getDefaultPattern() {
return defaultPattern;
}

public Character getKeywordDelimiter() {
public String getKeywordDelimiter() {
return keywordDelimiter.get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,7 @@ public BibEntryPreferences getBibEntryPreferences() {
}

bibEntryPreferences = new BibEntryPreferences(
get(KEYWORD_SEPARATOR).charAt(0)
get(KEYWORD_SEPARATOR)
);

EasyBind.listen(bibEntryPreferences.keywordSeparatorProperty(), (_, _, newValue) -> put(KEYWORD_SEPARATOR, String.valueOf(newValue)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public enum CitationKeyDependency {
private final ObjectProperty<CitationKeyDependency> citationKeyDependency;
private final StringProperty regularExpression;
private final BooleanProperty askAutoNamingPdfs;
private final ReadOnlyObjectProperty<Character> keywordSeparator;
private final ReadOnlyObjectProperty<String> keywordSeparator;

public AutoLinkPreferences(CitationKeyDependency citationKeyDependency,
String regularExpression,
boolean askAutoNamingPdfs,
ObjectProperty<Character> keywordSeparatorProperty) {
ObjectProperty<String> keywordSeparatorProperty) {
this.citationKeyDependency = new SimpleObjectProperty<>(citationKeyDependency);
this.regularExpression = new SimpleStringProperty(regularExpression);
this.askAutoNamingPdfs = new SimpleBooleanProperty(askAutoNamingPdfs);
Expand All @@ -37,7 +37,7 @@ public AutoLinkPreferences(CitationKeyDependency citationKeyDependency,
public AutoLinkPreferences(CitationKeyDependency citationKeyDependency,
String regularExpression,
boolean askAutoNamingPdfs,
Character keywordSeparator) {
String keywordSeparator) {
this.citationKeyDependency = new SimpleObjectProperty<>(citationKeyDependency);
this.regularExpression = new SimpleStringProperty(regularExpression);
this.askAutoNamingPdfs = new SimpleBooleanProperty(askAutoNamingPdfs);
Expand Down Expand Up @@ -80,7 +80,7 @@ public void setAskAutoNamingPdfs(boolean askAutoNamingPdfs) {
this.askAutoNamingPdfs.set(askAutoNamingPdfs);
}

public Character getKeywordSeparator() {
public String getKeywordSeparator() {
return keywordSeparator.getValue();
}
}
6 changes: 3 additions & 3 deletions jablib/src/main/java/org/jabref/logic/xmp/XmpPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class XmpPreferences {

private final BooleanProperty useXmpPrivacyFilter;
private final ObservableSet<Field> xmpPrivacyFilter;
private final ObjectProperty<Character> keywordSeparator;
private final ObjectProperty<String> keywordSeparator;

public XmpPreferences(boolean useXmpPrivacyFilter, Set<Field> xmpPrivacyFilter, ObjectProperty<Character> keywordSeparator) {
public XmpPreferences(boolean useXmpPrivacyFilter, Set<Field> xmpPrivacyFilter, ObjectProperty<String> keywordSeparator) {
this.useXmpPrivacyFilter = new SimpleBooleanProperty(useXmpPrivacyFilter);
this.xmpPrivacyFilter = FXCollections.observableSet(xmpPrivacyFilter);
this.keywordSeparator = keywordSeparator;
Expand All @@ -38,7 +38,7 @@ public ObservableSet<Field> getXmpPrivacyFilter() {
return xmpPrivacyFilter;
}

public Character getKeywordSeparator() {
public String getKeywordSeparator() {
return keywordSeparator.getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
import javafx.beans.property.SimpleObjectProperty;

public class BibEntryPreferences {
private final ObjectProperty<Character> keywordSeparator;
private final ObjectProperty<String> keywordSeparator;

public BibEntryPreferences(Character keywordSeparator) {
public BibEntryPreferences(String keywordSeparator) {
this.keywordSeparator = new SimpleObjectProperty<>(keywordSeparator);
}

public Character getKeywordSeparator() {
public String getKeywordSeparator() {
return keywordSeparator.get();
}

public ObjectProperty<Character> keywordSeparatorProperty() {
public ObjectProperty<String> keywordSeparatorProperty() {
return keywordSeparator;
}

public void setKeywordSeparator(Character keywordSeparator) {
public void setKeywordSeparator(String keywordSeparator) {
this.keywordSeparator.set(keywordSeparator);
}
}
Loading