Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into multiline
Browse files Browse the repository at this point in the history
* upstream/master:
  Backward compatibility for 4.3.1 (#6296)
  Fix Export to clipboard Dialog icon (#6345)
  Refactor EntryEditorPreferences (#6245)
  • Loading branch information
Siedlerchr committed Apr 27, 2020
2 parents 7d21e06 + d7a57b8 commit 1dc4fc5
Show file tree
Hide file tree
Showing 23 changed files with 594 additions and 389 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where citation styles except the default "Preview" could not be used. [#56220](https://github.com/JabRef/jabref/issues/5622)
- We fixed an issue where a warning was displayed when the title content is made up of two sentences. [#5832](https://github.com/JabRef/jabref/issues/5832)
- We fixed an issue where an exception was thrown when adding a save action without a selected formatter in the library properties [#6069](https://github.com/JabRef/jabref/issues/6069)
- We fixed an issue where JabRef's icon was missing in the Export to clipboard Dialog. [#6286](https://github.com/JabRef/jabref/issues/6286)
- We fixed an issue when an "Abstract field" was duplicating text, when importing from RIS file (Neurons) [#6065](https://github.com/JabRef/jabref/issues/6065)


### Removed

- Ampersands are no longer escaped by default in the `bib` file. If you want to keep the current behaviour, you can use the new "Escape Ampersands" formatter as a save action. [#5869](https://github.com/JabRef/jabref/issues/5869)
Expand Down
Binary file added JabRef-downgrade-regpatch.reg
Binary file not shown.
1 change: 1 addition & 0 deletions src/main/java/org/jabref/gui/JabRefDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public static String shortenDialogMessage(String dialogMessage) {
@Override
public <T> Optional<T> showChoiceDialogAndWait(String title, String content, String okButtonLabel, T defaultChoice, Collection<T> choices) {
ChoiceDialog<T> choiceDialog = new ChoiceDialog<>(defaultChoice, choices);
((Stage) choiceDialog.getDialogPane().getScene().getWindow()).getIcons().add(IconTheme.getJabRefImageFX());
ButtonType okButtonType = new ButtonType(okButtonLabel, ButtonBar.ButtonData.OK_DONE);
choiceDialog.getDialogPane().getButtonTypes().setAll(ButtonType.CANCEL, okButtonType);
choiceDialog.setHeaderText(title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,24 @@

public class AutoCompletePreferences {

private boolean shouldAutoComplete;
private AutoCompleteFirstNameMode firstNameMode;
private boolean onlyCompleteLastFirst;
private boolean onlyCompleteFirstLast;
private Set<Field> completeFields;
public enum NameFormat {
LAST_FIRST, FIRST_LAST, BOTH
}

private final boolean shouldAutoComplete;
private final AutoCompleteFirstNameMode firstNameMode;
private final NameFormat nameFormat;
private final Set<Field> completeFields;
private final JournalAbbreviationPreferences journalAbbreviationPreferences;

public AutoCompletePreferences(boolean shouldAutoComplete, AutoCompleteFirstNameMode firstNameMode, boolean onlyCompleteLastFirst, boolean onlyCompleteFirstLast, Set<Field> completeFields, JournalAbbreviationPreferences journalAbbreviationPreferences) {
public AutoCompletePreferences(boolean shouldAutoComplete, AutoCompleteFirstNameMode firstNameMode, NameFormat nameFormat, Set<Field> completeFields, JournalAbbreviationPreferences journalAbbreviationPreferences) {
this.shouldAutoComplete = shouldAutoComplete;
this.firstNameMode = firstNameMode;
this.onlyCompleteLastFirst = onlyCompleteLastFirst;
this.onlyCompleteFirstLast = onlyCompleteFirstLast;
this.nameFormat = nameFormat;
this.completeFields = completeFields;
this.journalAbbreviationPreferences = journalAbbreviationPreferences;
}

public void setShouldAutoComplete(boolean shouldAutoComplete) {
this.shouldAutoComplete = shouldAutoComplete;
}

public boolean shouldAutoComplete() {
return shouldAutoComplete;
}
Expand All @@ -39,25 +37,7 @@ public AutoCompleteFirstNameMode getFirstNameMode() {
return firstNameMode;
}

public void setFirstNameMode(AutoCompleteFirstNameMode firstNameMode) {
this.firstNameMode = firstNameMode;
}

public boolean getOnlyCompleteLastFirst() {
return onlyCompleteLastFirst;
}

public void setOnlyCompleteLastFirst(boolean onlyCompleteLastFirst) {
this.onlyCompleteLastFirst = onlyCompleteLastFirst;
}

public boolean getOnlyCompleteFirstLast() {
return onlyCompleteFirstLast;
}

public void setOnlyCompleteFirstLast(boolean onlyCompleteFirstLast) {
this.onlyCompleteFirstLast = onlyCompleteFirstLast;
}
public NameFormat getNameFormat() { return nameFormat; }

/**
* Returns the list of fields for which autocomplete is enabled
Expand All @@ -67,14 +47,6 @@ public Set<Field> getCompleteFields() {
return completeFields;
}

public void setCompleteFields(Set<Field> completeFields) {
this.completeFields = completeFields;
}

public void setCompleteNames(String input) {
setCompleteFields(FieldFactory.parseFieldList(input));
}

public String getCompleteNamesAsString() {
return FieldFactory.serializeFieldsList(completeFields);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@ public PersonNameStringConverter(boolean autoCompFF, boolean autoCompLF, AutoCom
}

public PersonNameStringConverter(AutoCompletePreferences preferences) {
if (preferences.getOnlyCompleteFirstLast()) {
autoCompFF = true;
autoCompLF = false;
} else if (preferences.getOnlyCompleteLastFirst()) {
autoCompFF = false;
autoCompLF = true;
} else {
autoCompFF = true;
autoCompLF = true;
switch (preferences.getNameFormat()) {
case FIRST_LAST:
autoCompFF = true;
autoCompLF = false;
break;
case LAST_FIRST:
autoCompFF = false;
autoCompLF = true;
break;
default:
case BOTH:
autoCompFF = true;
autoCompLF = true;
break;
}

autoCompleteFirstNameMode = preferences.getFirstNameMode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,36 @@

import org.jabref.gui.DialogService;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.entryeditor.EntryEditorPreferences;
import org.jabref.gui.undo.UndoableKeyChange;
import org.jabref.logic.bibtexkeypattern.BibtexKeyGenerator;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.preferences.PreferencesService;

public class GenerateBibtexKeySingleAction extends SimpleCommand {

private DialogService dialogService;
private BibDatabaseContext databaseContext;
private EntryEditorPreferences preferences;
private BibEntry entry;
private UndoManager undoManager;
private final DialogService dialogService;
private final BibDatabaseContext databaseContext;
private final PreferencesService preferencesService;
private final BibEntry entry;
private final UndoManager undoManager;

public GenerateBibtexKeySingleAction(BibEntry entry, BibDatabaseContext databaseContext, DialogService dialogService, EntryEditorPreferences preferences, UndoManager undoManager) {
public GenerateBibtexKeySingleAction(BibEntry entry, BibDatabaseContext databaseContext, DialogService dialogService, PreferencesService preferencesService, UndoManager undoManager) {
this.entry = entry;
this.databaseContext = databaseContext;
this.dialogService = dialogService;
this.preferences = preferences;
this.preferencesService = preferencesService;
this.undoManager = undoManager;

if (preferences.avoidOverwritingCiteKey()) {
// Only make command executable if cite key is empty
if (preferencesService.getBibtexKeyPatternPreferences().avoidOverwritingCiteKey()) {
this.executable.bind(entry.getCiteKeyBinding().isNull());
}
}

@Override
public void execute() {
if (!entry.hasCiteKey() || GenerateBibtexKeyAction.confirmOverwriteKeys(dialogService)) {
new BibtexKeyGenerator(databaseContext, preferences.getBibtexKeyPatternPreferences())
new BibtexKeyGenerator(databaseContext, preferencesService.getBibtexKeyPatternPreferences())
.generateAndSetKey(entry)
.ifPresent(change -> undoManager.addEdit(new UndoableKeyChange(change)));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jabref.gui.customizefields;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

Expand All @@ -11,7 +12,6 @@
import org.jabref.logic.l10n.Localization;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.FieldFactory;
import org.jabref.preferences.JabRefPreferences;
import org.jabref.preferences.PreferencesService;

public class CustomizeGeneralFieldsDialogViewModel {
Expand All @@ -23,13 +23,16 @@ public class CustomizeGeneralFieldsDialogViewModel {
public CustomizeGeneralFieldsDialogViewModel(DialogService dialogService, PreferencesService preferences) {
this.dialogService = dialogService;
this.preferences = preferences;
setInitialFieldsText();

// Using stored custom values or, if they do not exist, default values
setFieldsText(preferences.getEntryEditorTabList());
}

private void setInitialFieldsText() {
private void setFieldsText(Map<String, Set<Field>> tabNamesAndFields) {
StringBuilder sb = new StringBuilder();

for (Map.Entry<String, Set<Field>> tab : preferences.getEntryEditorTabList().entrySet()) {
// Fill with customized vars
for (Map.Entry<String, Set<Field>> tab : tabNamesAndFields.entrySet()) {
sb.append(tab.getKey());
sb.append(':');
sb.append(FieldFactory.serializeFieldsList(tab.getValue()));
Expand All @@ -43,48 +46,35 @@ public StringProperty fieldsTextProperty() {
}

public void saveFields() {
Map<String, Set<Field>> customTabsMap = new LinkedHashMap<>();
String[] lines = fieldsText.get().split("\n");
int i = 0;
for (; i < lines.length; i++) {
String[] parts = lines[i].split(":");

for (String line : lines) {
String[] parts = line.split(":");
if (parts.length != 2) {
// Report error and exit.
String field = Localization.lang("field");
String title = Localization.lang("Error");
String content = Localization.lang("Each line must be of the following form") + " '" +
Localization.lang("Tabname") + ':' + field + "1;" + field + "2;...;" + field + "N'";
dialogService.showInformationDialogAndWait(title, content);
dialogService.showInformationDialogAndWait(
Localization.lang("Error"),
Localization.lang("Each line must be of the following form: 'tab:field1;field2;...;fieldN'."));
return;
}

String testString = BibtexKeyGenerator.cleanKey(parts[1], preferences.getEnforceLegalKeys());
if (!testString.equals(parts[1]) || (parts[1].indexOf('&') >= 0)) {
String title = Localization.lang("Error");
String content = Localization.lang("Field names are not allowed to contain white space or the following "
+ "characters")
+ ": # { } ( ) ~ , ^ & - \" ' ` ʹ \\";
dialogService.showInformationDialogAndWait(title, content);
dialogService.showInformationDialogAndWait(
Localization.lang("Error"),
Localization.lang("Field names are not allowed to contain white spaces or certain characters (%0).",
"# { } ( ) ~ , ^ & - \" ' ` ʹ \\"));
return;
}
preferences.setCustomTabsNameAndFields(parts[0], parts[1], i);

customTabsMap.put(parts[0], FieldFactory.parseFieldList(parts[1]));
}
preferences.purgeSeries(JabRefPreferences.CUSTOM_TAB_NAME, i);
preferences.purgeSeries(JabRefPreferences.CUSTOM_TAB_FIELDS, i);
preferences.updateEntryEditorTabList();

preferences.storeEntryEditorTabList(customTabsMap);
}

public void resetFields() {

StringBuilder sb = new StringBuilder();
Map<String, String> customTabNamesFields = preferences.getCustomTabsNamesAndFields();
for (Map.Entry<String, String> entry : customTabNamesFields.entrySet()) {
sb.append(entry.getKey());
sb.append(':');
sb.append(entry.getValue());
sb.append('\n');
}
fieldsText.set(sb.toString());

// Using default values
setFieldsText(preferences.getDefaultTabNamesAndFields());
}
}
20 changes: 13 additions & 7 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public EntryEditor(BasePanel panel, ExternalFileTypes externalFileTypes) {
*/
private void setupKeyBindings() {
this.addEventHandler(KeyEvent.KEY_PRESSED, event -> {
Optional<KeyBinding> keyBinding = entryEditorPreferences.getKeyBindings().mapToKeyBinding(event);
Optional<KeyBinding> keyBinding = Globals.getKeyPrefs().mapToKeyBinding(event);
if (keyBinding.isPresent()) {
switch (keyBinding.get()) {
case ENTRY_EDITOR_NEXT_PANEL:
Expand Down Expand Up @@ -202,7 +202,7 @@ private void deleteEntry() {
@FXML
void generateCiteKeyButton() {
GenerateBibtexKeySingleAction action = new GenerateBibtexKeySingleAction(getEntry(), databaseContext,
dialogService, entryEditorPreferences, undoManager);
dialogService, preferencesService, undoManager);
action.execute();
}

Expand All @@ -229,7 +229,7 @@ private List<EntryEditorTab> createTabs() {
entryEditorTabs.add(new DeprecatedFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationLoader));

// Other fields
entryEditorTabs.add(new OtherFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, entryEditorPreferences.getCustomTabFieldNames(), dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationLoader));
entryEditorTabs.add(new OtherFieldsTab(databaseContext, panel.getSuggestionProviders(), undoManager, dialogService, Globals.prefs, Globals.entryTypesManager, ExternalFileTypes.getInstance(), Globals.TASK_EXECUTOR, Globals.journalAbbreviationLoader));

// General fields from preferences
for (Map.Entry<String, Set<Field>> tab : entryEditorPreferences.getEntryEditorTabList().entrySet()) {
Expand All @@ -242,9 +242,15 @@ private List<EntryEditorTab> createTabs() {
entryEditorTabs.add(new RelatedArticlesTab(this, entryEditorPreferences, dialogService));

// Source tab
sourceTab = new SourceTab(databaseContext, undoManager,
entryEditorPreferences.getFieldWriterPreferences(),
entryEditorPreferences.getImportFormatPreferences(), fileMonitor, dialogService, stateManager, Globals.getKeyPrefs());
sourceTab = new SourceTab(
databaseContext,
undoManager,
preferencesService.getFieldWriterPreferences(),
preferencesService.getImportFormatPreferences(),
fileMonitor,
dialogService,
stateManager,
Globals.getKeyPrefs());
entryEditorTabs.add(sourceTab);

// LaTeX citations tab
Expand Down Expand Up @@ -335,7 +341,7 @@ private void setupToolBar() {

// Add menu for fetching bibliographic information
ContextMenu fetcherMenu = new ContextMenu();
for (EntryBasedFetcher fetcher : WebFetchers.getEntryBasedFetchers(entryEditorPreferences.getImportFormatPreferences())) {
for (EntryBasedFetcher fetcher : WebFetchers.getEntryBasedFetchers(preferencesService.getImportFormatPreferences())) {
MenuItem fetcherMenuItem = new MenuItem(fetcher.getName());
fetcherMenuItem.setOnAction(event -> fetchAndMerge(fetcher));
fetcherMenu.getItems().add(fetcherMenuItem);
Expand Down
Loading

0 comments on commit 1dc4fc5

Please sign in to comment.