improve auto save/restore logic

This commit is contained in:
Branislav Stojkovic
2016-10-22 15:07:23 +02:00
parent 83e7c0b077
commit d8b915f8a5
@@ -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,7 +41,16 @@ 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);
if (autoSaved.exists())
if (wasAbnormal) {
IPlugInPort testPresenter = new Presenter(
new DummyView());
testPresenter.loadProjectFromFile(AUTO_SAVE_FILE_NAME);
// Only prompt if there is something saved in the
// auto-saved file.
if (!testPresenter.getCurrentProject().getComponents()
.isEmpty()) {
int decision = view int decision = view
.showConfirmDialog( .showConfirmDialog(
"It appears that aplication was not closed normally in the previous session. Do you want to open the last auto-saved file?", "It appears that aplication was not closed normally in the previous session. Do you want to open the last auto-saved file?",
@@ -50,6 +61,8 @@ public class AutoSavePlugin implements IPlugIn {
.loadProjectFromFile(AUTO_SAVE_FILE_NAME); .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(