Skip to content

Commit

Permalink
followup of #4784 - fixes remaining issues of #4762
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasgeiger committed Mar 24, 2019
1 parent 6c61664 commit 73bfc78
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
40 changes: 22 additions & 18 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public class BasePanel extends StackPane {

private final BibDatabaseContext bibDatabaseContext;
private final MainTableDataModel tableModel;
private final DatabaseChangePane changePane;

private final CitationStyleCache citationStyleCache;
private final FileAnnotationCache annotationCache;
Expand All @@ -138,6 +137,7 @@ public class BasePanel extends StackPane {
// As most enums, this must not be null
private BasePanelMode mode = BasePanelMode.SHOWING_NOTHING;
private SplitPane splitPane;
private DatabaseChangePane changePane;
private boolean saving;

// AutoCompleter used in the search bar
Expand Down Expand Up @@ -186,22 +186,6 @@ public BasePanel(JabRefFrame frame, BasePanelPreferences preferences, BibDatabas
// ensure that all entry changes mark the panel as changed
this.bibDatabaseContext.getDatabase().registerListener(this);

Optional<File> file = bibDatabaseContext.getDatabaseFile();
if (file.isPresent()) {
// Register so we get notifications about outside changes to the file.
changeMonitor = Optional.of(new DatabaseChangeMonitor(bibDatabaseContext, Globals.getFileUpdateMonitor(), Globals.TASK_EXECUTOR));
changePane = new DatabaseChangePane(splitPane, bibDatabaseContext, changeMonitor.get());
getChildren().add(changePane);
} else {
if (bibDatabaseContext.getDatabase().hasEntries()) {
// if the database is not empty and no file is assigned,
// the database came from an import and has to be treated somehow
// -> mark as changed
this.baseChanged = true;
}
changePane = null;
}

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

this.entryEditor = new EntryEditor(this, preferences.getEntryEditorPreferences(), Globals.getFileUpdateMonitor(), dialogService, externalFileTypes, Globals.TASK_EXECUTOR);
Expand Down Expand Up @@ -790,6 +774,22 @@ public void setupMainPanel() {
dividerPositionSubscription = EasyBind.monadic(Bindings.valueAt(splitPane.getDividers(), 0))
.flatMap(SplitPane.Divider::positionProperty)
.subscribe((observable, oldValue, newValue) -> saveDividerLocation(newValue));

// Add changePane in case a file is present - otherwise just add the splitPane to the panel
Optional<File> file = bibDatabaseContext.getDatabaseFile();
if (file.isPresent()) {
// create changeMonitor and changePane so we get notifications about outside changes to the file.
resetChangeMonitorAndChangePane();
} else {
if (bibDatabaseContext.getDatabase().hasEntries()) {
// if the database is not empty and no file is assigned,
// the database came from an import and has to be treated somehow
// -> mark as changed
this.baseChanged = true;
}
changePane = null;
getChildren().add(splitPane);
}
}

/**
Expand Down Expand Up @@ -1182,9 +1182,13 @@ public FileAnnotationCache getAnnotationCache() {
return annotationCache;
}

public void resetChangeMonitor() {
public void resetChangeMonitorAndChangePane() {
changeMonitor.ifPresent(DatabaseChangeMonitor::unregister);
changeMonitor = Optional.of(new DatabaseChangeMonitor(bibDatabaseContext, Globals.getFileUpdateMonitor(), Globals.TASK_EXECUTOR));

changePane = new DatabaseChangePane(splitPane, bibDatabaseContext, changeMonitor.get());

this.getChildren().setAll(changePane);
}

public void updateTimeStamp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void saveAs(Path file) {
save();

// Reinstall AutosaveManager and BackupManager
panel.resetChangeMonitor();
panel.resetChangeMonitorAndChangePane();
if (readyForAutosave(context)) {
AutosaveManager autosaver = AutosaveManager.start(context);
autosaver.registerListener(new AutosaveUIManager(panel));
Expand Down

0 comments on commit 73bfc78

Please sign in to comment.