Skip to content

Commit

Permalink
Add date fields (#7334)
Browse files Browse the repository at this point in the history
Co-authored-by: Oliver Kopp <[email protected]>
  • Loading branch information
DominikVoigt and koppor authored Jan 14, 2021
1 parent 727602b commit e66f5be
Show file tree
Hide file tree
Showing 36 changed files with 529 additions and 257 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We added the extension support and the external application support (For Texshow, Texmaker and LyX) to the flatpak [#7248](https://github.com/JabRef/jabref/pull/7248)
- We added some symbols and keybindings to the context menu in the entry editor. [#7268](https://github.com/JabRef/jabref/pull/7268)
- We added keybindings for setting and clearing the read status. [#7264](https://github.com/JabRef/jabref/issues/7264)
- We added two new fields to track the creation and most recent modification date and time for each entry. [koppor#130](https://github.com/koppor/jabref/issues/130)

### Changed

- The content of the field `timestamp` is migrated to `creationdate`. In case one configured "udpate timestampe", it is migrated to `modificationdate`. [koppor#130](https://github.com/koppor/jabref/issues/130)

### Fixed

- We fixed an issue where the "Normalize page numbers" formatter did not replace en-dashes or em-dashes with a hyphen-minus sign. [#7239](https://github.com/JabRef/jabref/issues/7239)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private static Optional<ParserResult> importFile(Path file, String importFormat)
// * means "guess the format":
System.out.println(Localization.lang("Importing in unknown format") + ": " + file);

ImportFormatReader.UnknownFormatImport importResult = Globals.IMPORT_FORMAT_READER.importUnknownFormat(file, new DummyFileUpdateMonitor());
ImportFormatReader.UnknownFormatImport importResult = Globals.IMPORT_FORMAT_READER.importUnknownFormat(file, Globals.prefs.getTimestampPreferences(), new DummyFileUpdateMonitor());

System.out.println(Localization.lang("Format used") + ": " + importResult.format);
return Optional.of(importResult.parserResult);
Expand Down Expand Up @@ -321,7 +321,7 @@ private List<ParserResult> importAndOpenFiles() {
boolean bibExtension = aLeftOver.toLowerCase(Locale.ENGLISH).endsWith("bib");
ParserResult pr = new ParserResult();
if (bibExtension) {
pr = OpenDatabase.loadDatabase(aLeftOver, Globals.prefs.getImportFormatPreferences(), Globals.getFileUpdateMonitor());
pr = OpenDatabase.loadDatabase(aLeftOver, Globals.prefs.getImportFormatPreferences(), Globals.prefs.getTimestampPreferences(), Globals.getFileUpdateMonitor());
}

if (!bibExtension || (pr.isEmpty())) {
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 @@ -275,7 +275,7 @@ private void openLastEditedDatabases() {
}

ParserResult parsedDatabase = OpenDatabase.loadDatabase(fileName,
Globals.prefs.getImportFormatPreferences(), Globals.getFileUpdateMonitor());
Globals.prefs.getImportFormatPreferences(), Globals.prefs.getTimestampPreferences(), Globals.getFileUpdateMonitor());

if (parsedDatabase.isEmpty()) {
LOGGER.error(Localization.lang("Error opening file") + " '" + dbFile.getPath() + "'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void execute() {
}
final Crawler crawler;
try {
crawler = new Crawler(studyDefinitionFile.get(), new GitHandler(studyDefinitionFile.get().getParent()), fileUpdateMonitor, importFormatPreferneces, savePreferences, new BibEntryTypesManager());
crawler = new Crawler(studyDefinitionFile.get(), new GitHandler(studyDefinitionFile.get().getParent()), fileUpdateMonitor, importFormatPreferneces, savePreferences, preferencesService.getTimestampPreferences(), new BibEntryTypesManager());
} catch (IOException | ParseException | GitAPIException e) {
LOGGER.error("Error during reading of study definition file.", e);
dialogService.showErrorDialogAndWait(Localization.lang("Error during reading of study definition file."), e);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/jabref/gui/UpdateTimestampListener.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.gui;

import org.jabref.model.entry.event.EntryChangedEvent;
import org.jabref.model.entry.field.StandardField;
import org.jabref.preferences.PreferencesService;

import com.google.common.eventbus.Subscribe;
Expand All @@ -17,8 +18,8 @@ class UpdateTimestampListener {

@Subscribe
public void listen(EntryChangedEvent event) {
if (preferencesService.getTimestampPreferences().shouldIncludeTimestamps()) {
event.getBibEntry().setField(preferencesService.getTimestampPreferences().getTimestampField(),
if (preferencesService.getTimestampPreferences().shouldAddModificationDate()) {
event.getBibEntry().setField(StandardField.MODIFICATIONDATE,
preferencesService.getTimestampPreferences().now());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/collab/ChangeScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public List<DatabaseChangeViewModel> scanForChanges() {
// Parse the modified file
// Important: apply all post-load actions
ImportFormatPreferences importFormatPreferences = preferencesService.getImportFormatPreferences();
ParserResult result = OpenDatabase.loadDatabase(database.getDatabasePath().get(), importFormatPreferences, new DummyFileUpdateMonitor());
ParserResult result = OpenDatabase.loadDatabase(database.getDatabasePath().get(), importFormatPreferences, preferencesService.getTimestampPreferences(), new DummyFileUpdateMonitor());
BibDatabaseContext databaseOnDisk = result.getDatabaseContext();

// Start looking at changes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ImportHandler(DialogService dialogService,
this.stateManager = stateManager;

this.linker = new ExternalFilesEntryLinker(externalFileTypes, preferencesService.getFilePreferences(), database);
this.contentImporter = new ExternalFilesContentImporter(preferencesService.getImportFormatPreferences());
this.contentImporter = new ExternalFilesContentImporter(preferencesService.getImportFormatPreferences(), preferencesService.getTimestampPreferences());
this.undoManager = undoManager;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/importer/ImportAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private List<ImportFormatReader.UnknownFormatImport> doImport(List<Path> files)
// Unknown format:
DefaultTaskExecutor.runInJavaFXThread(() -> frame.getDialogService().notify(Localization.lang("Importing in unknown format") + "..."));
// This import method never throws an IOException:
imports.add(Globals.IMPORT_FORMAT_READER.importUnknownFormat(filename, Globals.getFileUpdateMonitor()));
imports.add(Globals.IMPORT_FORMAT_READER.importUnknownFormat(filename, prefs.getTimestampPreferences(), Globals.getFileUpdateMonitor()));
} else {
DefaultTaskExecutor.runInJavaFXThread(() -> frame.getDialogService().notify(Localization.lang("Importing in %0 format", importer.get().getName()) + "..."));
// Specific importer:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private ParserResult loadDatabase(Path file) throws Exception {
}

ParserResult result = OpenDatabase.loadDatabase(fileToLoad.toString(),
Globals.prefs.getImportFormatPreferences(), Globals.getFileUpdateMonitor());
Globals.prefs.getImportFormatPreferences(), Globals.prefs.getTimestampPreferences(), Globals.getFileUpdateMonitor());

if (result.getDatabase().isShared()) {
try {
Expand Down
29 changes: 2 additions & 27 deletions src/main/java/org/jabref/gui/preferences/GeneralTab.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,6 @@
</HBox>

<Label styleClass="sectionHeader" text="%Time stamp"/>
<CheckBox fx:id="markTimestamp" text="%Mark new entries with addition date"/>
<HBox spacing="10.0">
<GridPane hgap="10.0" vgap="4.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES"/>
<ColumnConstraints hgrow="SOMETIMES"/>
<ColumnConstraints hgrow="SOMETIMES"/>
<ColumnConstraints hgrow="SOMETIMES"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
</rowConstraints>
<Label fx:id="markTimeStampFormatLabel" text="%Date format"/>
<TextField fx:id="markTimeStampFormat" prefWidth="200.0" GridPane.columnIndex="1"/>
<CheckBox fx:id="markTimeStampOverwrite" text="%Overwrite" GridPane.columnIndex="2">
<tooltip>
<Tooltip text="%If a pasted or imported entry already has the field set, overwrite."/>
</tooltip>
</CheckBox>
<Button fx:id="markTimeStampHelp" prefWidth="20.0" GridPane.columnIndex="3"/>
<Label fx:id="markTimeStampFieldNameLabel" text="%Field name" GridPane.rowIndex="1"/>
<TextField fx:id="markTimeStampFieldName" prefWidth="200.0" GridPane.columnIndex="1"
GridPane.rowIndex="1"/>
</GridPane>
</HBox>
<CheckBox fx:id="updateTimeStamp" text="%Update timestamp on modification"/>
<CheckBox fx:id="addCreationDate" text="%Add timestamp to new entries (field &quot;creationdate&quot;)"/>
<CheckBox fx:id="addModificationDate" text="%Add timestamp to modified entries (field &quot;modificationdate&quot;)"/>
</fx:root>
26 changes: 4 additions & 22 deletions src/main/java/org/jabref/gui/preferences/GeneralTabView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import java.nio.charset.Charset;

import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;

import org.jabref.gui.Globals;
Expand Down Expand Up @@ -40,14 +38,8 @@ public class GeneralTabView extends AbstractPreferenceTabView<GeneralTabViewMode
@FXML private TextField markOwnerName;
@FXML private CheckBox markOwnerOverwrite;
@FXML private Button markOwnerHelp;
@FXML private CheckBox markTimestamp;
@FXML private TextField markTimeStampFormat;
@FXML private Label markTimeStampFormatLabel;
@FXML private CheckBox markTimeStampOverwrite;
@FXML private TextField markTimeStampFieldName;
@FXML private Label markTimeStampFieldNameLabel;
@FXML private Button markTimeStampHelp;
@FXML private CheckBox updateTimeStamp;
@FXML private CheckBox addCreationDate;
@FXML private CheckBox addModificationDate;

private final ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer();

Expand Down Expand Up @@ -98,22 +90,12 @@ public void initialize() {
markOwnerOverwrite.selectedProperty().bindBidirectional(viewModel.markOwnerOverwriteProperty());
markOwnerOverwrite.disableProperty().bind(markOwner.selectedProperty().not());

markTimestamp.selectedProperty().bindBidirectional(viewModel.markTimestampProperty());
markTimeStampFormatLabel.disableProperty().bind(markTimestamp.selectedProperty().not());
markTimeStampFormat.textProperty().bindBidirectional(viewModel.markTimeStampFormatProperty());
markTimeStampFormat.disableProperty().bind(markTimestamp.selectedProperty().not());
markTimeStampOverwrite.selectedProperty().bindBidirectional(viewModel.markTimeStampOverwriteProperty());
markTimeStampOverwrite.disableProperty().bind(markTimestamp.selectedProperty().not());
markTimeStampFieldNameLabel.disableProperty().bind(markTimestamp.selectedProperty().not());
markTimeStampFieldName.textProperty().bindBidirectional(viewModel.markTimeStampFieldNameProperty());
markTimeStampFieldName.disableProperty().bind(markTimestamp.selectedProperty().not());
updateTimeStamp.selectedProperty().bindBidirectional(viewModel.updateTimeStampProperty());
addCreationDate.selectedProperty().bindBidirectional(viewModel.addCreationDateProperty());
addModificationDate.selectedProperty().bindBidirectional(viewModel.addModificationDateProperty());

ActionFactory actionFactory = new ActionFactory(Globals.getKeyPrefs());
actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.OWNER), markOwnerHelp);
actionFactory.configureIconButton(StandardActions.HELP, new HelpAction(HelpFile.TIMESTAMP), markTimeStampHelp);

validationVisualizer.setDecoration(new IconValidationDecorator());
Platform.runLater(() -> validationVisualizer.initVisualization(viewModel.markTimeStampFormatValidationStatus(), markTimeStampFormat));
}
}
82 changes: 13 additions & 69 deletions src/main/java/org/jabref/gui/preferences/GeneralTabViewModel.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jabref.gui.preferences;

import java.nio.charset.Charset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -22,16 +21,10 @@
import org.jabref.logic.preferences.OwnerPreferences;
import org.jabref.logic.preferences.TimestampPreferences;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.field.FieldFactory;
import org.jabref.preferences.GeneralPreferences;
import org.jabref.preferences.PreferencesService;
import org.jabref.preferences.TelemetryPreferences;

import de.saxsys.mvvmfx.utils.validation.FunctionBasedValidator;
import de.saxsys.mvvmfx.utils.validation.ValidationMessage;
import de.saxsys.mvvmfx.utils.validation.ValidationStatus;
import de.saxsys.mvvmfx.utils.validation.Validator;

public class GeneralTabViewModel implements PreferenceTabViewModel {
private final ListProperty<Language> languagesListProperty = new SimpleListProperty<>();
private final ObjectProperty<Language> selectedLanguageProperty = new SimpleObjectProperty<>();
Expand All @@ -49,13 +42,8 @@ public class GeneralTabViewModel implements PreferenceTabViewModel {
private final BooleanProperty markOwnerProperty = new SimpleBooleanProperty();
private final StringProperty markOwnerNameProperty = new SimpleStringProperty("");
private final BooleanProperty markOwnerOverwriteProperty = new SimpleBooleanProperty();
private final BooleanProperty markTimestampProperty = new SimpleBooleanProperty();
private final StringProperty markTimeStampFormatProperty = new SimpleStringProperty("");
private final BooleanProperty markTimeStampOverwriteProperty = new SimpleBooleanProperty();
private final StringProperty markTimeStampFieldNameProperty = new SimpleStringProperty("");
private final BooleanProperty updateTimeStampProperty = new SimpleBooleanProperty();

private Validator markTimeStampFormatValidator;
private final BooleanProperty addCreationDateProperty = new SimpleBooleanProperty();
private final BooleanProperty addModificationDateProperty = new SimpleBooleanProperty();

private final DialogService dialogService;
private final PreferencesService preferencesService;
Expand All @@ -74,25 +62,6 @@ public GeneralTabViewModel(DialogService dialogService, PreferencesService prefe
this.initialTelemetryPreferences = preferencesService.getTelemetryPreferences();
this.initialOwnerPreferences = preferencesService.getOwnerPreferences();
this.initialTimestampPreferences = preferencesService.getTimestampPreferences();

markTimeStampFormatValidator = new FunctionBasedValidator<>(
markTimeStampFormatProperty,
input -> {
try {
DateTimeFormatter.ofPattern(markTimeStampFormatProperty.getValue());
} catch (IllegalArgumentException exception) {
return false;
}
return true;
},
ValidationMessage.error(String.format("%s > %s > %s %n %n %s",
Localization.lang("General"),
Localization.lang("Time stamp"),
Localization.lang("Date format"),
Localization.lang("Invalid date format")
)
)
);
}

public void setValues() {
Expand All @@ -116,11 +85,8 @@ public void setValues() {
markOwnerNameProperty.setValue(initialOwnerPreferences.getDefaultOwner());
markOwnerOverwriteProperty.setValue(initialOwnerPreferences.isOverwriteOwner());

markTimestampProperty.setValue(initialTimestampPreferences.shouldUseTimestamps());
markTimeStampFormatProperty.setValue(initialTimestampPreferences.getTimestampFormat());
markTimeStampOverwriteProperty.setValue(initialTimestampPreferences.shouldOverwriteTimestamp());
markTimeStampFieldNameProperty.setValue(initialTimestampPreferences.getTimestampField().getName());
updateTimeStampProperty.setValue(initialTimestampPreferences.shouldUpdateTimestamp());
addCreationDateProperty.setValue(initialTimestampPreferences.shouldAddCreationDate());
addModificationDateProperty.setValue(initialTimestampPreferences.shouldAddModificationDate());
}

public void storeSettings() {
Expand Down Expand Up @@ -155,24 +121,14 @@ public void storeSettings() {
markOwnerOverwriteProperty.getValue()));

preferencesService.storeTimestampPreferences(new TimestampPreferences(
markTimestampProperty.getValue(),
updateTimeStampProperty.getValue(),
FieldFactory.parseField(markTimeStampFieldNameProperty.getValue().trim()),
markTimeStampFormatProperty.getValue().trim(),
markTimeStampOverwriteProperty.getValue()));
}

public ValidationStatus markTimeStampFormatValidationStatus() {
return markTimeStampFormatValidator.getValidationStatus();
addCreationDateProperty.getValue(),
addModificationDateProperty.getValue(),
initialTimestampPreferences.shouldUpdateTimestamp(),
initialTimestampPreferences.getTimestampField(),
initialTimestampPreferences.getTimestampFormat()));
}

public boolean validateSettings() {
ValidationStatus validationStatus = markTimeStampFormatValidationStatus();
if (!validationStatus.isValid()) {
validationStatus.getHighestMessage().ifPresent(message ->
dialogService.showErrorDialogAndWait(message.getMessage()));
return false;
}
return true;
}

Expand Down Expand Up @@ -247,23 +203,11 @@ public BooleanProperty markOwnerOverwriteProperty() {

// Time stamp

public BooleanProperty markTimestampProperty() {
return this.markTimestampProperty;
}

public StringProperty markTimeStampFormatProperty() {
return this.markTimeStampFormatProperty;
}

public BooleanProperty markTimeStampOverwriteProperty() {
return this.markTimeStampOverwriteProperty;
}

public StringProperty markTimeStampFieldNameProperty() {
return this.markTimeStampFieldNameProperty;
public BooleanProperty addCreationDateProperty() {
return addCreationDateProperty;
}

public BooleanProperty updateTimeStampProperty() {
return this.updateTimeStampProperty;
public BooleanProperty addModificationDateProperty() {
return addModificationDateProperty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void parseButtonClicked() {
}

TexBibEntriesResolver entriesResolver = new TexBibEntriesResolver(databaseContext.getDatabase(),
preferencesService.getImportFormatPreferences(), fileMonitor);
preferencesService.getImportFormatPreferences(), preferencesService.getTimestampPreferences(), fileMonitor);

BackgroundTask.wrap(() -> entriesResolver.resolve(new DefaultLatexParser().parse(fileList)))
.onRunning(() -> searchInProgress.set(true))
Expand Down
Loading

0 comments on commit e66f5be

Please sign in to comment.