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

Change default behavior of resolve bibtex strings #8382

Merged
merged 33 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e69c84f
Change default behavior of resolve bibtex strings
Siedlerchr Jan 3, 2022
ae29ece
Merge remote-tracking branch 'upstream/main' into stringResolving
Siedlerchr Jan 4, 2022
30e6b54
Renaming of fields
Siedlerchr Jan 4, 2022
56f2f8a
fix prefs, remove migration
Siedlerchr Jan 4, 2022
fa84969
Fix gui properties and l10n
Siedlerchr Jan 4, 2022
ef2c916
adjust defaults, fix bst tests
Siedlerchr Jan 6, 2022
ba865d2
remove obsolete test
Siedlerchr Jan 6, 2022
8b2f76f
fix checkstyle
Siedlerchr Jan 6, 2022
7975ea4
fix another test
Siedlerchr Jan 6, 2022
adbb12d
fix comment
Siedlerchr Jan 7, 2022
3c81834
Fix typos
koppor Jan 7, 2022
d3ba9a1
Merge branch 'main' of github.com:JabRef/jabref into stringResolving
Siedlerchr Jan 8, 2022
3e264ef
Merge branch 'stringResolving' of github.com:JabRef/jabref into strin…
Siedlerchr Jan 8, 2022
df38fe9
add institution
Siedlerchr Jan 8, 2022
4dd29d3
Sort fields alphabetically
koppor Jan 9, 2022
3d54f61
Group prefernces at "File": BibTeX strings, Loading, Saving
koppor Jan 9, 2022
ce0a098
Merge branch 'main' into stringResolving
Siedlerchr Jan 9, 2022
adae72a
Remove unused imports
koppor Jan 9, 2022
83438f2
Add ADR-0024
koppor Jan 9, 2022
ec82fbb
Add test for comment field
Siedlerchr Jan 9, 2022
48dbc3a
Merge remote-tracking branch 'upstream/main' into stringResolving
Siedlerchr Jan 9, 2022
00ae093
fix tests
Siedlerchr Jan 9, 2022
97e6bb2
Fix markdown in ADR-0024
koppor Jan 9, 2022
2922009
ADR-0024: Fix filename and addr to adr.md
koppor Jan 9, 2022
ab7f578
ADR-0019: Fix typo
koppor Jan 9, 2022
fb4e8f9
Merge remote-tracking branch 'origin/main' into stringResolving
koppor Jan 9, 2022
3395f56
Remove obsolete empty line
koppor Jan 9, 2022
895d210
Introduce BIBTEX_STRING_START_END_SYMBOL and remove negation
koppor Jan 9, 2022
21ab02f
Remove deprecated constructor FieldWriterPreferences()
koppor Jan 9, 2022
242a203
Fix test on Windows (CRLF issue)
koppor Jan 9, 2022
beda8ab
Add missing context information
koppor Jan 9, 2022
6c56ad4
Add more tests
koppor Jan 9, 2022
1f38378
Fix negation
koppor Jan 9, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
### Changed

- We integrated the external file types dialog directly inside the preferences. [#8341](https://github.com/JabRef/jabref/pull/8341)
- We inverted the logic for resolving [BibTeX strings](https://docs.jabref.org/advanced/strings). This helps to keep `#` chars. By default String resolving is only activated for a couple of standard fields. The list of fields can be modified in the preferences. [#7010](https://github.com/JabRef/jabref/issues/7010), [#7102](https://github.com/JabRef/jabref/issues/7012), [#8303](https://github.com/JabRef/jabref/issues/8303)
- We moved the search box in preview preferences closer to the available citation styles list. [#8370](https://github.com/JabRef/jabref/pull/8370)
- Changing the preference to show the preview panel as a separate tab now has effect without restarting JabRef. [#8370](https://github.com/JabRef/jabref/pull/8370)
- We enabled switching themes in JabRef without the need to restart JabRef. [#7335](https://github.com/JabRef/jabref/pull/7335)

### Fixed

- We fixed an issue where `#`chars in certain fields would be interpreted as BibTeX strings [#7010](https://github.com/JabRef/jabref/issues/7010), [#7102](https://github.com/JabRef/jabref/issues/7012), [#8303](https://github.com/JabRef/jabref/issues/8303)
- We fixed an issue where clicking on "Accept changes" in the merge dialog would lead to an exception [forum#2418](https://discourse.jabref.org/t/the-library-has-been-modified-by-another-program/2418/8)
- We fixed an issue where clicking on headings in the entry preview could lead to an exception. [#8292](https://github.com/JabRef/jabref/issues/8292)
- We fixed an issue where IntegrityCheck used the system's character encoding instead of the one set by the library or in preferences [#8022](https://github.com/JabRef/jabref/issues/8022)
Expand Down
28 changes: 19 additions & 9 deletions src/main/java/org/jabref/gui/preferences/file/FileTab.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,41 @@
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<?import javafx.scene.control.Separator?>
<fx:root spacing="10.0" type="VBox"
xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml"
fx:controller="org.jabref.gui.preferences.file.FileTab">
<Label text="%File" styleClass="titleHeader"/>

<Label styleClass="sectionHeader" text="%String constants"/>
<fx:define>
<ToggleGroup fx:id="stringsResolveToggleGroup"/>
</fx:define>
<HBox alignment="CENTER_LEFT" spacing="10.0">
<RadioButton fx:id="resolveStrings" text="%Resolve BibTeX strings for the following fields"
toggleGroup="$stringsResolveToggleGroup"/>
<TextField fx:id="resolveStringsForFields" HBox.hgrow="ALWAYS"/>
</HBox>
<RadioButton fx:id="doNotResolveStrings" text="%Do not resolve BibTeX strings"
koppor marked this conversation as resolved.
Show resolved Hide resolved
toggleGroup="$stringsResolveToggleGroup"/>

<Label styleClass="sectionHeader" text="%Loading"/>

<CheckBox fx:id="openLastStartup" text="%Open last edited libraries at startup"/>

<Label styleClass="sectionHeader" text="%Saving"/>

<HBox alignment="CENTER_LEFT" spacing="10.0">
<Label text="%Do not wrap the following fields when saving"/>
<TextField fx:id="noWrapFiles" HBox.hgrow="ALWAYS"/>
</HBox>
<RadioButton fx:id="resolveStringsBibTex" text="%Resolve strings for standard BibTeX fields only"
toggleGroup="$stringsResolveToggleGroup"/>
<HBox alignment="CENTER_LEFT" spacing="10.0">
<RadioButton fx:id="resolveStringsAll" text="%Resolve strings for all fields except"
toggleGroup="$stringsResolveToggleGroup"/>
<TextField fx:id="resolveStringsExcept" HBox.hgrow="ALWAYS"/>
</HBox>
<CheckBox fx:id="alwaysReformatBib" text="%Always reformat BIB file on save and export"/>

<Label styleClass="sectionHeader" text="%Autosave"/>
<HBox alignment="CENTER_LEFT" spacing="10.0">
<CheckBox fx:id="autosaveLocalLibraries" text="%Autosave local libraries"/>
<Button fx:id="autosaveLocalLibrariesHelp"/>
</HBox>

<CheckBox fx:id="alwaysReformatBib" text="%Always reformat BIB file on save and export"/>


</fx:root>
17 changes: 9 additions & 8 deletions src/main/java/org/jabref/gui/preferences/file/FileTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public class FileTab extends AbstractPreferenceTabView<FileTabViewModel> impleme

@FXML private CheckBox openLastStartup;
@FXML private TextField noWrapFiles;
@FXML private RadioButton resolveStringsBibTex;
@FXML private RadioButton resolveStringsAll;
@FXML private TextField resolveStringsExcept;
@FXML private RadioButton doNotResolveStrings;
@FXML private RadioButton resolveStrings;
@FXML private TextField resolveStringsForFields;
@FXML private CheckBox alwaysReformatBib;

@FXML private CheckBox autosaveLocalLibraries;
Expand All @@ -39,12 +39,13 @@ public void initialize() {
this.viewModel = new FileTabViewModel(preferencesService);
openLastStartup.selectedProperty().bindBidirectional(viewModel.openLastStartupProperty());
noWrapFiles.textProperty().bindBidirectional(viewModel.noWrapFilesProperty());
resolveStringsBibTex.selectedProperty().bindBidirectional(viewModel.resolveStringsBibTexProperty());
resolveStringsAll.selectedProperty().bindBidirectional(viewModel.resolveStringsAllProperty());
resolveStringsExcept.textProperty().bindBidirectional(viewModel.resolveStringsExceptProperty());
resolveStringsExcept.disableProperty().bind(resolveStringsAll.selectedProperty().not());
alwaysReformatBib.selectedProperty().bindBidirectional(viewModel.alwaysReformatBibProperty());

doNotResolveStrings.selectedProperty().bindBidirectional(viewModel.doNotResolveStringsProperty());
resolveStrings.selectedProperty().bindBidirectional(viewModel.resolveStringsProperty());
resolveStringsForFields.textProperty().bindBidirectional(viewModel.resolveStringsForFieldsProperty());
resolveStringsForFields.disableProperty().bind(doNotResolveStrings.selectedProperty());

alwaysReformatBib.selectedProperty().bindBidirectional(viewModel.alwaysReformatBibProperty());
autosaveLocalLibraries.selectedProperty().bindBidirectional(viewModel.autosaveLocalLibrariesProperty());

ActionFactory actionFactory = new ActionFactory(Globals.getKeyPrefs());
Expand Down
31 changes: 14 additions & 17 deletions src/main/java/org/jabref/gui/preferences/file/FileTabViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class FileTabViewModel implements PreferenceTabViewModel {

private final BooleanProperty openLastStartupProperty = new SimpleBooleanProperty();
private final StringProperty noWrapFilesProperty = new SimpleStringProperty("");
private final BooleanProperty resolveStringsBibTexProperty = new SimpleBooleanProperty();
private final BooleanProperty resolveStringsAllProperty = new SimpleBooleanProperty();
private final StringProperty resolveStringsExceptProperty = new SimpleStringProperty("");
private final BooleanProperty doNotResolveStringsProperty = new SimpleBooleanProperty();
private final BooleanProperty resolveStringsProperty = new SimpleBooleanProperty();
private final StringProperty resolveStringsForFieldsProperty = new SimpleStringProperty("");
private final BooleanProperty alwaysReformatBibProperty = new SimpleBooleanProperty();
private final BooleanProperty autosaveLocalLibraries = new SimpleBooleanProperty();

Expand All @@ -30,25 +30,22 @@ public class FileTabViewModel implements PreferenceTabViewModel {
@Override
public void setValues() {
openLastStartupProperty.setValue(preferences.shouldOpenLastFilesOnStartup());

noWrapFilesProperty.setValue(importExportPreferences.getNonWrappableFields());
resolveStringsAllProperty.setValue(importExportPreferences.shouldResolveStringsForAllStrings()); // Flipped around
resolveStringsBibTexProperty.setValue(importExportPreferences.shouldResolveStringsForStandardBibtexFields());
resolveStringsExceptProperty.setValue(importExportPreferences.getNonResolvableFields());

doNotResolveStringsProperty.setValue(importExportPreferences.doNotResolveStrings());
resolveStringsProperty.setValue(!importExportPreferences.doNotResolveStrings());
resolveStringsForFieldsProperty.setValue(importExportPreferences.getResolvableFields());
alwaysReformatBibProperty.setValue(importExportPreferences.shouldAlwaysReformatOnSave());

autosaveLocalLibraries.setValue(preferences.shouldAutosave());
}

@Override
public void storeSettings() {
preferences.storeOpenLastFilesOnStartup(openLastStartupProperty.getValue());

importExportPreferences.setDoNotResolveStrings(doNotResolveStringsProperty.getValue());
importExportPreferences.setNonWrappableFields(noWrapFilesProperty.getValue().trim());
importExportPreferences.setResolveStringsForStandardBibtexFields(resolveStringsBibTexProperty.getValue());
importExportPreferences.setResolveStringsForAllStrings(resolveStringsAllProperty.getValue());
importExportPreferences.setNonResolvableFields(resolveStringsExceptProperty.getValue().trim());
importExportPreferences.setResolvableFields(resolveStringsForFieldsProperty.getValue().trim());
importExportPreferences.setAlwaysReformatOnSave(alwaysReformatBibProperty.getValue());

preferences.storeShouldAutosave(autosaveLocalLibraries.getValue());
Expand All @@ -66,16 +63,16 @@ public StringProperty noWrapFilesProperty() {
return noWrapFilesProperty;
}

public BooleanProperty resolveStringsBibTexProperty() {
return resolveStringsBibTexProperty;
public BooleanProperty doNotResolveStringsProperty() {
return doNotResolveStringsProperty;
}

public BooleanProperty resolveStringsAllProperty() {
return resolveStringsAllProperty;
public BooleanProperty resolveStringsProperty() {
return resolveStringsProperty;
}

public StringProperty resolveStringsExceptProperty() {
return resolveStringsExceptProperty;
public StringProperty resolveStringsForFieldsProperty() {
return resolveStringsForFieldsProperty;
}

public BooleanProperty alwaysReformatBibProperty() {
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/org/jabref/logic/bibtex/FieldWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import org.jabref.logic.util.OS;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.InternalField;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.strings.StringUtil;

import org.slf4j.Logger;
Expand Down Expand Up @@ -165,13 +163,11 @@ private String formatAndResolveStrings(String content, Field field) throws Inval
}

private boolean shouldResolveStrings(Field field) {
if (preferences.isResolveStringsAllFields()) {
// Resolve strings for all fields except some:
return !preferences.getDoNotResolveStringsFor().contains(field);
} else {
// Default operation - we only resolve strings for standard fields:
return field instanceof StandardField || InternalField.BIBTEX_STRING.equals(field);
if (!preferences.isDoNotResolveStrings()) {
// Resolve strings for the list of fields only
return preferences.getResolveStringsForFields().contains(field);
}
return false;
}

private String formatWithoutResolvingStrings(String content, Field field) throws InvalidFieldValueException {
Expand Down
26 changes: 14 additions & 12 deletions src/main/java/org/jabref/logic/bibtex/FieldWriterPreferences.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
package org.jabref.logic.bibtex;

import java.util.Collections;
import java.util.List;

import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.StandardField;

public class FieldWriterPreferences {

private final boolean resolveStringsAllFields;
private final List<Field> doNotResolveStringsFor;
private final boolean doNotResolveStrings;
private final List<Field> resolveStringsForFields;
private final int lineLength = 65; // Constant
private final FieldContentFormatterPreferences fieldContentFormatterPreferences;

public FieldWriterPreferences(boolean resolveStringsAllFields, List<Field> doNotResolveStringsFor,
public FieldWriterPreferences(boolean doNotResolveFields, List<Field> resolveStringsForFields,
FieldContentFormatterPreferences fieldContentFormatterPreferences) {
this.resolveStringsAllFields = resolveStringsAllFields;
this.doNotResolveStringsFor = doNotResolveStringsFor;
this.doNotResolveStrings = doNotResolveFields;
this.resolveStringsForFields = resolveStringsForFields;
this.fieldContentFormatterPreferences = fieldContentFormatterPreferences;
}

/**
* ONLY USE IN TEST: ONLY resolves BibTex String for the Field Month
* Creates an instance with default values (not obeying any user preferences). This constructor should be used with
* caution. The other constructor has to be preferred.
* @deprecated
*/
@Deprecated
public FieldWriterPreferences() {
// This constructor is only to allow an empty constructor in SavePreferences
this(true, Collections.emptyList(), new FieldContentFormatterPreferences());
this(false, List.of(StandardField.MONTH), new FieldContentFormatterPreferences());
}

public boolean isResolveStringsAllFields() {
return resolveStringsAllFields;
public boolean isDoNotResolveStrings() {
return doNotResolveStrings;
}

public List<Field> getDoNotResolveStringsFor() {
return doNotResolveStringsFor;
public List<Field> getResolveStringsForFields() {
return resolveStringsForFields;
}

public int getLineLength() {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/logic/bst/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jabref.logic.bibtex.FieldContentFormatterPreferences;
import org.jabref.logic.bibtex.FieldWriter;
import org.jabref.logic.bibtex.FieldWriterPreferences;
import org.jabref.logic.bibtex.InvalidFieldValueException;
Expand Down Expand Up @@ -927,7 +928,7 @@ public String run(Collection<BibEntry> bibEntries, BibDatabase bibDatabase) {
* @param bibDatabase
*/
private void read(BibDatabase bibDatabase) {
FieldWriter fieldWriter = new FieldWriter(new FieldWriterPreferences());
FieldWriter fieldWriter = new FieldWriter(new FieldWriterPreferences(false, List.of(StandardField.MONTH), new FieldContentFormatterPreferences()));
for (BstEntry e : entries) {
for (Map.Entry<String, String> mEntry : e.fields.entrySet()) {
Field field = FieldFactory.parseField(mEntry.getKey());
Expand Down
53 changes: 20 additions & 33 deletions src/main/java/org/jabref/preferences/ImportExportPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,25 @@
import javafx.beans.property.StringProperty;

public class ImportExportPreferences {

private final StringProperty nonWrappableFields;
private final BooleanProperty resolveStringsForStandardBibtexFields;
private final BooleanProperty resolveStringsForAllStrings;
private final StringProperty nonResolvableFields;
private final BooleanProperty doNotResolveStrings;
private final StringProperty resolvableFields;
private final BooleanProperty alwaysReformatOnSave;
private final ObjectProperty<Path> importWorkingDirectory;
private final StringProperty lastExportExtension;
private final ObjectProperty<Path> exportWorkingDirectory;

public ImportExportPreferences(String nonWrappableFields,
boolean resolveStringsForStandardBibtexFields,
boolean resolveStringsForAllStrings,
String nonResolvableFields,
boolean doNotResolveStrings,
String resolvableFields,
boolean alwaysReformatOnSave,
Path importWorkingDirectory,
String lastExportExtension,
Path exportWorkingDirectory) {
this.nonWrappableFields = new SimpleStringProperty(nonWrappableFields);
this.resolveStringsForStandardBibtexFields = new SimpleBooleanProperty(resolveStringsForStandardBibtexFields);
this.resolveStringsForAllStrings = new SimpleBooleanProperty(resolveStringsForAllStrings);
this.nonResolvableFields = new SimpleStringProperty(nonResolvableFields);
this.doNotResolveStrings = new SimpleBooleanProperty(doNotResolveStrings);
this.resolvableFields = new SimpleStringProperty(resolvableFields);
this.alwaysReformatOnSave = new SimpleBooleanProperty(alwaysReformatOnSave);
this.importWorkingDirectory = new SimpleObjectProperty<>(importWorkingDirectory);
this.lastExportExtension = new SimpleStringProperty(lastExportExtension);
Expand All @@ -49,40 +47,28 @@ public void setNonWrappableFields(String nonWrappableFields) {
this.nonWrappableFields.set(nonWrappableFields);
}

public boolean shouldResolveStringsForStandardBibtexFields() {
return resolveStringsForStandardBibtexFields.get();
}

public BooleanProperty resolveStringsForStandardBibtexFieldsProperty() {
return resolveStringsForStandardBibtexFields;
}

public void setResolveStringsForStandardBibtexFields(boolean resolveStringsForStandardBibtexFields) {
this.resolveStringsForStandardBibtexFields.set(resolveStringsForStandardBibtexFields);
}

public boolean shouldResolveStringsForAllStrings() {
return resolveStringsForAllStrings.get();
public boolean doNotResolveStrings() {
return doNotResolveStrings.get();
}

public BooleanProperty resolveStringsForAllStringsProperty() {
return resolveStringsForAllStrings;
public BooleanProperty doNotResolveStringsProperty() {
return doNotResolveStrings;
}

public void setResolveStringsForAllStrings(boolean resolveStringsForAllStrings) {
this.resolveStringsForAllStrings.set(resolveStringsForAllStrings);
public void setDoNotResolveStrings(boolean doNotResolveStrings) {
this.doNotResolveStrings.set(doNotResolveStrings);
}

public String getNonResolvableFields() {
return nonResolvableFields.get();
public String getResolvableFields() {
return resolvableFields.get();
}

public StringProperty nonResolvableFieldsProperty() {
return nonResolvableFields;
public StringProperty resolvableFieldsProperty() {
return resolvableFields;
}

public void setNonResolvableFields(String nonResolvableFields) {
this.nonResolvableFields.set(nonResolvableFields);
public void setResolvableFields(String resolvableFields) {
this.resolvableFields.set(resolvableFields);
}

public boolean shouldAlwaysReformatOnSave() {
Expand Down Expand Up @@ -132,4 +118,5 @@ public ObjectProperty<Path> exportWorkingDirectoryProperty() {
public void setExportWorkingDirectory(Path exportWorkingDirectory) {
this.exportWorkingDirectory.set(exportWorkingDirectory);
}

}
Loading