Skip to content

Commit

Permalink
Followup of #4784 - fixes remaining issues of #4762 (#4806)
Browse files Browse the repository at this point in the history
* followup of #4784 - fixes remaining issues of #4762

* use Path instead of File

Co-authored-by: matthiasgeiger <matthias.geiger@uni-bamberg.de>
  • Loading branch information
matthiasgeiger authored and Siedlerchr committed Mar 25, 2019
1 parent c20c28a commit e14b567
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
41 changes: 22 additions & 19 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jabref.gui;

import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -115,7 +114,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 +136,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 +185,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 +773,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<Path> file = bibDatabaseContext.getDatabasePath();
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 +1181,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 e14b567

Please sign in to comment.