Skip to content

Commit

Permalink
Fix timestamps not being updated for changed entries
Browse files Browse the repository at this point in the history
This is a fix for the issue JabRef#2810.

The functionality has been moved from the EntryEditor to the BasePanel
class so that it can listen for EntryChangedEvents on the whole
database instead of specific EntryEditor objects. This allows us to
also update the timestamps of entries that were changed by other
sources (like cleanup operations).

The inner class UpdateTimestampListener is defined as "public static"
so that it can be used in the test cases for the implemented
functionality.
  • Loading branch information
Tobias Bouschen committed Nov 14, 2017
1 parent 0546077 commit bafddde
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -46,6 +46,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where fetching entries from crossref that had no titles caused an error [#3376](https://github.com/JabRef/jabref/issues/3376)
- We fixed an issue where the same Java Look and Feel would be listed more than once in the Preferences. [#3391](https://github.com/JabRef/jabref/issues/3391)
- We fixed an issue where errors in citation styles triggered an exception when opening the preferences dialog [#3389](https://github.com/JabRef/jabref/issues/3389)
- We fixed an issue where timestamps were not updated for changed entries [#2810](https://github.com/JabRef/jabref/issues/2810)

### Removed

Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/jabref/gui/BasePanel.java
Expand Up @@ -237,6 +237,8 @@ public BasePanel(JabRefFrame frame, BibDatabaseContext bibDatabaseContext) {
this.baseChanged = true;
}
}

this.getDatabase().registerListener(new UpdateTimestampListener(Globals.prefs));
}

public static void runWorker(AbstractWorker worker) throws Exception {
Expand Down Expand Up @@ -2100,6 +2102,25 @@ public void listen(EntryRemovedEvent removedEntryEvent) {
}
}

/**
* Updates the timestamp of changed entries if the feature is enabled
*/
public static class UpdateTimestampListener {
private final JabRefPreferences jabRefPreferences;

public UpdateTimestampListener(JabRefPreferences jabRefPreferences) {
this.jabRefPreferences = jabRefPreferences;
}

@Subscribe
public void listen(EntryChangedEvent event) {
if (jabRefPreferences.getTimestampPreferences().includeTimestamps()) {
event.getBibEntry().setField(jabRefPreferences.getTimestampPreferences().getTimestampField(),
jabRefPreferences.getTimestampPreferences().now());
}
}
}

private class UndoAction implements BaseAction {

@Override
Expand Down

0 comments on commit bafddde

Please sign in to comment.