mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
improve auto save/restore logic
This commit is contained in:
+24
-11
@@ -12,6 +12,8 @@ import org.diylc.common.EventType;
|
|||||||
import org.diylc.common.IPlugIn;
|
import org.diylc.common.IPlugIn;
|
||||||
import org.diylc.common.IPlugInPort;
|
import org.diylc.common.IPlugInPort;
|
||||||
import org.diylc.core.IView;
|
import org.diylc.core.IView;
|
||||||
|
import org.diylc.presenter.Presenter;
|
||||||
|
import org.diylc.swing.gui.DummyView;
|
||||||
|
|
||||||
public class AutoSavePlugin implements IPlugIn {
|
public class AutoSavePlugin implements IPlugIn {
|
||||||
|
|
||||||
@@ -39,17 +41,28 @@ public class AutoSavePlugin implements IPlugIn {
|
|||||||
public void run() {
|
public void run() {
|
||||||
boolean wasAbnormal = ConfigurationManager.getInstance()
|
boolean wasAbnormal = ConfigurationManager.getInstance()
|
||||||
.readBoolean(IPlugInPort.ABNORMAL_EXIT_KEY, false);
|
.readBoolean(IPlugInPort.ABNORMAL_EXIT_KEY, false);
|
||||||
if (wasAbnormal && new File(AUTO_SAVE_FILE_NAME).exists()) {
|
File autoSaved = new File(AUTO_SAVE_FILE_NAME);
|
||||||
int decision = view
|
if (autoSaved.exists())
|
||||||
.showConfirmDialog(
|
if (wasAbnormal) {
|
||||||
"It appears that aplication was not closed normally in the previous session. Do you want to open the last auto-saved file?",
|
IPlugInPort testPresenter = new Presenter(
|
||||||
"Auto-Save", IView.YES_NO_OPTION,
|
new DummyView());
|
||||||
IView.QUESTION_MESSAGE);
|
testPresenter.loadProjectFromFile(AUTO_SAVE_FILE_NAME);
|
||||||
if (decision == IView.YES_OPTION) {
|
// Only prompt if there is something saved in the
|
||||||
AutoSavePlugin.this.plugInPort
|
// auto-saved file.
|
||||||
.loadProjectFromFile(AUTO_SAVE_FILE_NAME);
|
if (!testPresenter.getCurrentProject().getComponents()
|
||||||
}
|
.isEmpty()) {
|
||||||
}
|
int decision = view
|
||||||
|
.showConfirmDialog(
|
||||||
|
"It appears that aplication was not closed normally in the previous session. Do you want to open the last auto-saved file?",
|
||||||
|
"Auto-Save", IView.YES_NO_OPTION,
|
||||||
|
IView.QUESTION_MESSAGE);
|
||||||
|
if (decision == IView.YES_OPTION) {
|
||||||
|
AutoSavePlugin.this.plugInPort
|
||||||
|
.loadProjectFromFile(AUTO_SAVE_FILE_NAME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
autoSaved.delete();
|
||||||
// Set abnormal flag to true, GUI side of the app must flip to
|
// Set abnormal flag to true, GUI side of the app must flip to
|
||||||
// false when app closes regularly.
|
// false when app closes regularly.
|
||||||
ConfigurationManager.getInstance().writeValue(
|
ConfigurationManager.getInstance().writeValue(
|
||||||
|
|||||||
Reference in New Issue
Block a user