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

Followup of #4784 - fixes remaining issues of #4762 #4806

Merged
merged 3 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Path class, there should be a method getDatabasePath

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