mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
load prev save if found
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user