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

Convert "wait for save" dialog to JavaFX #4697

Merged
merged 1 commit into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 2 additions & 11 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -502,17 +502,8 @@ public boolean quit() {
context.getDatabaseFile().map(File::getAbsolutePath).ifPresent(filenames::add);
}

// Wait for save operations to finish
for (int i = 0; i < tabbedPane.getTabs().size(); i++) {
if (getBasePanelAt(i).isSaving()) {
// There is a database still being saved, so we need to wait.
WaitForSaveOperation w = new WaitForSaveOperation(this);
w.show(); // This method won't return until canceled or the save operation is done.
if (w.canceled()) {
return false; // The user clicked cancel.
}
}
}
WaitForSaveFinishedDialog waitForSaveFinishedDialog = new WaitForSaveFinishedDialog(dialogService);
waitForSaveFinishedDialog.showAndWait(getBasePanelList());

// Good bye!
tearDownJabRef(filenames);
Expand Down
43 changes: 43 additions & 0 deletions src/main/java/org/jabref/gui/WaitForSaveFinishedDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.jabref.gui;

import java.util.List;

import javafx.concurrent.Task;

import org.jabref.logic.l10n.Localization;

/**
* Dialog shown when closing of application needs to wait for a save operation to finish.
*/
public class WaitForSaveFinishedDialog {

private final DialogService dialogService;

public WaitForSaveFinishedDialog(DialogService dialogService) {
this.dialogService = dialogService;
}

public void showAndWait(List<BasePanel> basePanels) {
if (basePanels.stream().anyMatch(BasePanel::isSaving)) {
Task<Void> waitForSaveFinished = new Task<Void>() {
@Override
protected Void call() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

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

You should ideally use the udpateProgress(ProgressBar.INDETERMINATE_PROGRESS) somewhere at the beginning to make the progress bar moving

while (basePanels.stream().anyMatch(BasePanel::isSaving)) {
if (isCancelled()) {
return null;
} else {
Thread.sleep(100);
}
}
return null;
}
};

dialogService.showProgressDialogAndWait(
Localization.lang("Please wait..."),
Localization.lang("Waiting for save operation to finish") + "...",
waitForSaveFinished
);
}
}
}
82 changes: 0 additions & 82 deletions src/main/java/org/jabref/gui/WaitForSaveOperation.java

This file was deleted.