load prev save if found

This commit is contained in:
Manindra Moharana
2014-01-12 19:23:03 +05:30
parent 3730031c25
commit 47a11b2f79
2 changed files with 36 additions and 3 deletions
@@ -17,7 +17,7 @@ public class AutoSaveUtil {
private int saveTime;
private File autosaveDir;
private File autosaveDir, pastSave;
private boolean isSaving;
/**
@@ -37,6 +37,21 @@ public class AutoSaveUtil {
autosaveDir = new File(editor.getSketch().getFolder().getAbsolutePath() + File.separator + "_autosave");
}
public boolean checkForPastSave(){
if(autosaveDir.exists()){
String prevSaves[] = Base.listFiles(autosaveDir, false);
if(prevSaves.length > 0){
pastSave = new File(prevSaves[0]);
return true;
}
}
return false;
}
public File getPastSave(){
return pastSave;
}
public void init(){
if(saveTime < 1000) return;
saveTime = 10 * 1000;
@@ -246,8 +246,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
addXQModeUI();
debugToolbarEnabled = new AtomicBoolean(false);
log("Sketch Path: " + path);
autosaver = new AutoSaveUtil(this, 5);
autosaver.init();
loadAutoSaver();
}
private void addXQModeUI(){
@@ -870,6 +869,25 @@ public class DebugEditor extends JavaEditor implements ActionListener {
}
return saved;
}
public void loadAutoSaver(){
autosaver = new AutoSaveUtil(this, 5);
if(!autosaver.checkForPastSave()) {
autosaver.init();
return;
}
File pastSave = autosaver.getPastSave();
int response = Base.showYesNoQuestion(this, "Unsaved backup found!", "An automatic backup of this " +
"sketch has been found. This may mean Processing quit unexpectedly last time.",
"Select YES to view it or NO to delete the backup.");
if(response == JOptionPane.YES_OPTION){
handleOpenInternal(pastSave.getAbsolutePath());
}
else{
autosaver.init();
}
}
/**
* Set text contents of a specific tab. Updates underlying document and text