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

Observable Preferences V (SavePreferences) #9808

Merged
merged 26 commits into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5d0bb90
Reworded SafeOrderConfig
calixtus Apr 22, 2023
427cbf2
Extracted CitationKeyWriterPreferences from SavePreferences
calixtus Apr 22, 2023
e1d4c4a
Extracted CitationKeyWriterPreferences from SavePreferences
calixtus Apr 22, 2023
bdc9d45
Extracted FileWriterPreferences from SavePreferences
calixtus Apr 22, 2023
c6b427a
Removed FieldContentFormatterPreferences and reworded FieldPreferences
calixtus Apr 22, 2023
3d11440
Reworded
calixtus Apr 23, 2023
9f61a2a
Removed saveInOriginalOrder and fixed one test
calixtus Apr 24, 2023
f74a151
Fixed tests
calixtus Apr 24, 2023
f9ed5a1
Reworded and prevented npe
calixtus Apr 25, 2023
51ce8c8
Reworded and moved DatabaseSaveType
calixtus Apr 25, 2023
1b91175
Reworded SavePreferences to SaveConfiguration
calixtus Apr 25, 2023
7cd69bf
Fixed a test
calixtus Apr 25, 2023
a7622d2
Extracted getSavePreferences
calixtus Apr 25, 2023
59a52d0
Reworded SavePreferencesForExport
calixtus Apr 25, 2023
82af5d1
Extracted FieldPreferences
calixtus Apr 26, 2023
6265afe
Moved shouldOpenLastEdited to GeneralPreferences
calixtus Apr 26, 2023
e6d4b0f
CHANGELOG.md
calixtus Apr 27, 2023
349d463
Refactored ExportSaveOrder to new prefs pattern
calixtus Apr 27, 2023
bff47d2
Merge remote-tracking branch 'upstream/main' into SavePreferences
calixtus Apr 27, 2023
bd4f844
CHANGELOG.md
calixtus Apr 27, 2023
958f6c8
Fixed test
calixtus Apr 27, 2023
eaeb92b
Fixed test
calixtus Apr 27, 2023
ff1d2d5
Fixed guitest
calixtus Apr 27, 2023
ea191a5
Removed superfluous title
calixtus Apr 27, 2023
ab8fdbf
Update CHANGELOG.md
calixtus Apr 29, 2023
3ae7988
Fixed preposition
calixtus Apr 29, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We moved the manage content selectors dialog to the library properties. [#9768](https://github.com/JabRef/jabref/pull/9768)
- We moved the preferences menu command from the options menu to the file menu. [#9768](https://github.com/JabRef/jabref/pull/9768)
- We changed the handling of an "overflow" of authors at `[authIniN]`: JabRef uses `+` to indicate an overflow. Example: `[authIni2]` produces `A+` (instead of `AB`) for `Aachen and Berlin and Chemnitz`. [#9703](https://github.com/JabRef/jabref/pull/9703)
- We moved the preferences option to open the last edited files on startup to the 'General' tag. [#9808](https://github.com/JabRef/jabref/pull/9808)
calixtus marked this conversation as resolved.
Show resolved Hide resolved


### Fixed
Expand Down
12 changes: 9 additions & 3 deletions src/jmh/java/org/jabref/benchmarks/Benchmarks.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import java.util.stream.Collectors;

import org.jabref.gui.Globals;
import org.jabref.logic.bibtex.FieldPreferences;
import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences;
import org.jabref.logic.exporter.BibWriter;
import org.jabref.logic.exporter.BibtexDatabaseWriter;
import org.jabref.logic.exporter.SavePreferences;
import org.jabref.logic.exporter.SaveConfiguration;
import org.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.fileformat.BibtexParser;
Expand All @@ -33,7 +35,6 @@
import org.jabref.model.metadata.MetaData;
import org.jabref.model.search.rules.SearchRules.SearchFlags;
import org.jabref.model.util.DummyFileUpdateMonitor;
import org.jabref.preferences.GeneralPreferences;
import org.jabref.preferences.JabRefPreferences;

import org.openjdk.jmh.Main;
Expand Down Expand Up @@ -80,7 +81,12 @@ public void init() throws Exception {
private StringWriter getOutputWriter() throws IOException {
StringWriter outputWriter = new StringWriter();
BibWriter bibWriter = new BibWriter(outputWriter, OS.NEWLINE);
BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(bibWriter, mock(GeneralPreferences.class), mock(SavePreferences.class), new BibEntryTypesManager());
BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(
bibWriter,
mock(SaveConfiguration.class),
mock(FieldPreferences.class),
mock(CitationKeyPatternPreferences.class),
new BibEntryTypesManager());
databaseWriter.savePartOfDatabase(new BibDatabaseContext(database, new MetaData()), database.getEntries());
return outputWriter;
}
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.jabref.gui.externalfiles.AutoSetFileLinksUtil;
import org.jabref.gui.undo.NamedCompound;
import org.jabref.logic.JabRefException;
import org.jabref.logic.bibtex.FieldWriterPreferences;
import org.jabref.logic.bibtex.FieldPreferences;
import org.jabref.logic.citationkeypattern.CitationKeyGenerator;
import org.jabref.logic.exporter.AtomicFileWriter;
import org.jabref.logic.exporter.BibDatabaseWriter;
Expand All @@ -25,7 +25,7 @@
import org.jabref.logic.exporter.EmbeddedBibFilePdfExporter;
import org.jabref.logic.exporter.Exporter;
import org.jabref.logic.exporter.ExporterFactory;
import org.jabref.logic.exporter.SavePreferences;
import org.jabref.logic.exporter.SaveConfiguration;
import org.jabref.logic.exporter.XmpPdfExporter;
import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.ImportException;
Expand Down Expand Up @@ -54,7 +54,6 @@
import org.jabref.model.strings.StringUtil;
import org.jabref.model.util.DummyFileUpdateMonitor;
import org.jabref.preferences.FilePreferences;
import org.jabref.preferences.GeneralPreferences;
import org.jabref.preferences.PreferencesService;
import org.jabref.preferences.SearchPreferences;

Expand Down Expand Up @@ -237,7 +236,7 @@ private List<ParserResult> processArguments() {
preferencesService.getFilePreferences(),
preferencesService.getGeneralPreferences().getDefaultBibDatabaseMode(),
Globals.entryTypesManager,
preferencesService.getFieldWriterPreferences(),
preferencesService.getFieldPreferences(),
cli.isWriteXMPtoPdf() || cli.isWriteMetadatatoPdf(),
cli.isEmbeddBibfileInPdf() || cli.isWriteMetadatatoPdf());
}
Expand Down Expand Up @@ -267,7 +266,7 @@ private List<ParserResult> processArguments() {
return loaded;
}

private void writeMetadatatoPdf(List<ParserResult> loaded, String filesAndCitekeys, XmpPreferences xmpPreferences, FilePreferences filePreferences, BibDatabaseMode databaseMode, BibEntryTypesManager entryTypesManager, FieldWriterPreferences fieldWriterPreferences, boolean writeXMP, boolean embeddBibfile) {
private void writeMetadatatoPdf(List<ParserResult> loaded, String filesAndCitekeys, XmpPreferences xmpPreferences, FilePreferences filePreferences, BibDatabaseMode databaseMode, BibEntryTypesManager entryTypesManager, FieldPreferences fieldPreferences, boolean writeXMP, boolean embeddBibfile) {
if (loaded.isEmpty()) {
LOGGER.error("The write xmp option depends on a valid import option.");
return;
Expand All @@ -277,7 +276,7 @@ private void writeMetadatatoPdf(List<ParserResult> loaded, String filesAndCiteke
BibDatabase dataBase = pr.getDatabase();

XmpPdfExporter xmpPdfExporter = new XmpPdfExporter(xmpPreferences);
EmbeddedBibFilePdfExporter embeddedBibFilePdfExporter = new EmbeddedBibFilePdfExporter(databaseMode, entryTypesManager, fieldWriterPreferences);
EmbeddedBibFilePdfExporter embeddedBibFilePdfExporter = new EmbeddedBibFilePdfExporter(databaseMode, entryTypesManager, fieldPreferences);

if ("all".equals(filesAndCitekeys)) {
for (BibEntry entry : dataBase.getEntries()) {
Expand Down Expand Up @@ -531,16 +530,17 @@ private boolean generateAux(List<ParserResult> loaded, String[] data) {
private void saveDatabase(BibDatabase newBase, String subName) {
try {
System.out.println(Localization.lang("Saving") + ": " + subName);
GeneralPreferences generalPreferences = preferencesService.getGeneralPreferences();
SavePreferences savePreferences = preferencesService.getSavePreferences();
try (AtomicFileWriter fileWriter = new AtomicFileWriter(Path.of(subName), StandardCharsets.UTF_8)) {
BibWriter bibWriter = new BibWriter(fileWriter, OS.NEWLINE);
SaveConfiguration saveConfiguration = new SaveConfiguration()
.withReformatOnSave(preferencesService.getImportExportPreferences().shouldAlwaysReformatOnSave());

BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(
bibWriter,
generalPreferences,
savePreferences,
Globals.entryTypesManager);
bibWriter,
saveConfiguration,
preferencesService.getFieldPreferences(),
preferencesService.getCitationKeyPatternPreferences(),
Globals.entryTypesManager);
databaseWriter.saveDatabase(new BibDatabaseContext(newBase));

// Show just a warning message if encoding did not work for all characters:
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/ClipBoardManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void setContent(String string) {

public void setContent(List<BibEntry> entries) throws IOException {
final ClipboardContent content = new ClipboardContent();
BibEntryWriter writer = new BibEntryWriter(new FieldWriter(preferencesService.getFieldWriterPreferences()), Globals.entryTypesManager);
BibEntryWriter writer = new BibEntryWriter(new FieldWriter(preferencesService.getFieldPreferences()), Globals.entryTypesManager);
String serializedEntries = writer.serializeAll(entries, BibDatabaseMode.BIBTEX);
content.put(DragAndDropDataFormats.ENTRIES, serializedEntries);
content.putString(serializedEntries);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public void about() {
* set to true
*/
private void tearDownJabRef(List<String> filenames) {
if (prefs.getImportExportPreferences().shouldOpenLastEdited()) {
if (prefs.getGeneralPreferences().shouldOpenLastEdited()) {
// Here we store the names of all current files. If there is no current file, we remove any
// previously stored filename.
if (filenames.isEmpty()) {
Expand Down Expand Up @@ -908,7 +908,7 @@ private MenuBar createMenu() {

new SeparatorMenuItem(),

factory.createMenuItem(StandardActions.WRITE_METADATA_TO_PDF, new WriteMetadataToPdfAction(stateManager, Globals.entryTypesManager, prefs.getFieldWriterPreferences(), dialogService, taskExecutor, prefs.getFilePreferences(), prefs.getXmpPreferences())),
factory.createMenuItem(StandardActions.WRITE_METADATA_TO_PDF, new WriteMetadataToPdfAction(stateManager, Globals.entryTypesManager, prefs.getFieldPreferences(), dialogService, taskExecutor, prefs.getFilePreferences(), prefs.getXmpPreferences())),
factory.createMenuItem(StandardActions.COPY_LINKED_FILES, new CopyFilesAction(dialogService, prefs, stateManager)),

new SeparatorMenuItem(),
Expand All @@ -919,9 +919,9 @@ private MenuBar createMenu() {
new SeparatorMenuItem(),

// Systematic Literature Review (SLR)
factory.createMenuItem(StandardActions.START_NEW_STUDY, new StartNewStudyAction(this, Globals.getFileUpdateMonitor(), Globals.TASK_EXECUTOR, prefs, stateManager, themeManager)),
factory.createMenuItem(StandardActions.START_NEW_STUDY, new StartNewStudyAction(this, Globals.getFileUpdateMonitor(), Globals.TASK_EXECUTOR, prefs, stateManager)),
factory.createMenuItem(StandardActions.EDIT_EXISTING_STUDY, new EditExistingStudyAction(this.dialogService, this.stateManager)),
factory.createMenuItem(StandardActions.UPDATE_SEARCH_RESULTS_OF_STUDY, new ExistingStudySearchAction(this, this.getOpenDatabaseAction(), this.getDialogService(), Globals.getFileUpdateMonitor(), Globals.TASK_EXECUTOR, prefs, stateManager, themeManager)),
factory.createMenuItem(StandardActions.UPDATE_SEARCH_RESULTS_OF_STUDY, new ExistingStudySearchAction(this, this.getOpenDatabaseAction(), this.getDialogService(), Globals.getFileUpdateMonitor(), Globals.TASK_EXECUTOR, prefs, stateManager)),

new SeparatorMenuItem(),

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private void openWindow(Stage mainStage) {

private void openDatabases() {
// If the option is enabled, open the last edited libraries, if any.
if (!isBlank && preferencesService.getImportExportPreferences().shouldOpenLastEdited()) {
if (!isBlank && preferencesService.getGeneralPreferences().shouldOpenLastEdited()) {
openLastEditedDatabases();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/SendAsEMailAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private String sendEmail() throws Exception {
List<BibEntry> entries = stateManager.getSelectedEntries();

// write the entries via this writer to "rawEntries" (being a StringWriter), which used later to form the email content
BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new FieldWriter(preferencesService.getFieldWriterPreferences()), Globals.entryTypesManager);
BibEntryWriter bibtexEntryWriter = new BibEntryWriter(new FieldWriter(preferencesService.getFieldPreferences()), Globals.entryTypesManager);

for (BibEntry entry : entries) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import org.jabref.gui.preview.PreviewViewer;
import org.jabref.logic.bibtex.BibEntryWriter;
import org.jabref.logic.bibtex.FieldPreferences;
import org.jabref.logic.bibtex.FieldWriter;
import org.jabref.logic.bibtex.FieldWriterPreferences;
import org.jabref.logic.exporter.BibWriter;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.OS;
Expand Down Expand Up @@ -52,7 +52,7 @@ public TabPane getPreviewWithSourceTab(BibEntry entry, BibDatabaseContext bibDat
}

try {
codeArea.appendText(getSourceString(entry, bibDatabaseContext.getMode(), preferencesService.getFieldWriterPreferences(), entryTypesManager));
codeArea.appendText(getSourceString(entry, bibDatabaseContext.getMode(), preferencesService.getFieldPreferences(), entryTypesManager));
} catch (IOException e) {
LOGGER.error("Error getting Bibtex: {}", entry);
}
Expand All @@ -63,10 +63,10 @@ public TabPane getPreviewWithSourceTab(BibEntry entry, BibDatabaseContext bibDat
return tabPanePreviewCode;
}

private String getSourceString(BibEntry entry, BibDatabaseMode type, FieldWriterPreferences fieldWriterPreferences, BibEntryTypesManager entryTypesManager) throws IOException {
private String getSourceString(BibEntry entry, BibDatabaseMode type, FieldPreferences fieldPreferences, BibEntryTypesManager entryTypesManager) throws IOException {
StringWriter writer = new StringWriter();
BibWriter bibWriter = new BibWriter(writer, OS.NEWLINE);
FieldWriter fieldWriter = FieldWriter.buildIgnoreHashes(fieldWriterPreferences);
FieldWriter fieldWriter = FieldWriter.buildIgnoreHashes(fieldPreferences);
new BibEntryWriter(fieldWriter, entryTypesManager).write(entry, bibWriter, type);
return writer.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import javafx.collections.FXCollections;

import org.jabref.model.entry.field.Field;
import org.jabref.model.metadata.SaveOrderConfig;
import org.jabref.model.metadata.SaveOrder;

public class SaveOrderConfigPanelViewModel {

Expand All @@ -24,7 +24,7 @@ public SaveOrderConfigPanelViewModel() {
}

public void addCriterion() {
selectedSortCriteriaProperty.add(new SortCriterionViewModel(new SaveOrderConfig.SortCriterion()));
selectedSortCriteriaProperty.add(new SortCriterionViewModel(new SaveOrder.SortCriterion()));
}

public void removeCriterion(SortCriterionViewModel sortCriterionViewModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import javafx.beans.property.SimpleObjectProperty;

import org.jabref.model.entry.field.Field;
import org.jabref.model.metadata.SaveOrderConfig;
import org.jabref.model.metadata.SaveOrder;

public class SortCriterionViewModel {

private final ObjectProperty<Field> fieldProperty = new SimpleObjectProperty<>();
private final BooleanProperty descendingProperty = new SimpleBooleanProperty();

public SortCriterionViewModel(SaveOrderConfig.SortCriterion criterion) {
public SortCriterionViewModel(SaveOrder.SortCriterion criterion) {
this.fieldProperty.setValue(criterion.field);
this.descendingProperty.setValue(criterion.descending);
}
Expand All @@ -26,7 +26,7 @@ public BooleanProperty descendingProperty() {
return descendingProperty;
}

public SaveOrderConfig.SortCriterion getCriterion() {
return new SaveOrderConfig.SortCriterion(fieldProperty.getValue(), descendingProperty.getValue());
public SaveOrder.SortCriterion getCriterion() {
return new SaveOrder.SortCriterion(fieldProperty.getValue(), descendingProperty.getValue());
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private List<EntryEditorTab> createTabs() {
sourceTab = new SourceTab(
databaseContext,
undoManager,
preferencesService.getFieldWriterPreferences(),
preferencesService.getFieldPreferences(),
preferencesService.getImportFormatPreferences(),
fileMonitor,
dialogService,
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/jabref/gui/entryeditor/SourceTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import org.jabref.gui.undo.UndoableFieldChange;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.logic.bibtex.BibEntryWriter;
import org.jabref.logic.bibtex.FieldPreferences;
import org.jabref.logic.bibtex.FieldWriter;
import org.jabref.logic.bibtex.FieldWriterPreferences;
import org.jabref.logic.bibtex.InvalidFieldValueException;
import org.jabref.logic.exporter.BibWriter;
import org.jabref.logic.importer.ImportFormatPreferences;
Expand All @@ -63,7 +63,7 @@
public class SourceTab extends EntryEditorTab {

private static final Logger LOGGER = LoggerFactory.getLogger(SourceTab.class);
private final FieldWriterPreferences fieldWriterPreferences;
private final FieldPreferences fieldPreferences;
private final BibDatabaseMode mode;
private final UndoManager undoManager;
private final ObjectProperty<ValidationMessage> sourceIsValid = new SimpleObjectProperty<>();
Expand Down Expand Up @@ -98,13 +98,13 @@ public void execute() {
}
}

public SourceTab(BibDatabaseContext bibDatabaseContext, CountingUndoManager undoManager, FieldWriterPreferences fieldWriterPreferences, ImportFormatPreferences importFormatPreferences, FileUpdateMonitor fileMonitor, DialogService dialogService, StateManager stateManager, KeyBindingRepository keyBindingRepository) {
public SourceTab(BibDatabaseContext bibDatabaseContext, CountingUndoManager undoManager, FieldPreferences fieldPreferences, ImportFormatPreferences importFormatPreferences, FileUpdateMonitor fileMonitor, DialogService dialogService, StateManager stateManager, KeyBindingRepository keyBindingRepository) {
this.mode = bibDatabaseContext.getMode();
this.setText(Localization.lang("%0 source", mode.getFormattedName()));
this.setTooltip(new Tooltip(Localization.lang("Show/edit %0 source", mode.getFormattedName())));
this.setGraphic(IconTheme.JabRefIcons.SOURCE.getGraphicNode());
this.undoManager = undoManager;
this.fieldWriterPreferences = fieldWriterPreferences;
this.fieldPreferences = fieldPreferences;
this.importFormatPreferences = importFormatPreferences;
this.fileMonitor = fileMonitor;
this.dialogService = dialogService;
Expand All @@ -129,10 +129,10 @@ private void highlightSearchPattern() {
}
}

private String getSourceString(BibEntry entry, BibDatabaseMode type, FieldWriterPreferences fieldWriterPreferences) throws IOException {
private String getSourceString(BibEntry entry, BibDatabaseMode type, FieldPreferences fieldPreferences) throws IOException {
StringWriter writer = new StringWriter();
BibWriter bibWriter = new BibWriter(writer, OS.NEWLINE);
FieldWriter fieldWriter = FieldWriter.buildIgnoreHashes(fieldWriterPreferences);
FieldWriter fieldWriter = FieldWriter.buildIgnoreHashes(fieldPreferences);
new BibEntryWriter(fieldWriter, Globals.entryTypesManager).write(entry, bibWriter, type);
return writer.toString();
}
Expand Down Expand Up @@ -225,7 +225,7 @@ private void updateCodeArea() {

codeArea.clear();
try {
codeArea.appendText(getSourceString(currentEntry, mode, fieldWriterPreferences));
codeArea.appendText(getSourceString(currentEntry, mode, fieldPreferences));
codeArea.setEditable(true);
highlightSearchPattern();
} catch (IOException ex) {
Expand Down Expand Up @@ -307,7 +307,7 @@ private void storeSource(BibEntry outOfFocusEntry, String text) {
String newValue = field.getValue();
if (!Objects.equals(oldValue, newValue)) {
// Test if the field is legally set.
new FieldWriter(fieldWriterPreferences).write(fieldName, newValue);
new FieldWriter(fieldPreferences).write(fieldName, newValue);

compound.addEdit(new UndoableFieldChange(outOfFocusEntry, fieldName, oldValue, newValue));
outOfFocusEntry.setField(fieldName, newValue);
Expand Down
Loading