mirror of
https://github.com/processing/processing4.git
synced 2026-02-14 02:45:36 +01:00
auto saver work done, i guess.
This commit is contained in:
@@ -33,6 +33,7 @@ public class AutoSaveUtil {
|
||||
}
|
||||
else{
|
||||
saveTime = timeOut * 60 * 1000;
|
||||
ExperimentalMode.log("AutoSaver Interval(mins): " + timeOut);
|
||||
}
|
||||
autosaveDir = new File(editor.getSketch().getFolder().getAbsolutePath() + File.separator + "_autosave");
|
||||
}
|
||||
@@ -42,7 +43,8 @@ public class AutoSaveUtil {
|
||||
String prevSaves[] = Base.listFiles(autosaveDir, false);
|
||||
if(prevSaves.length > 0){
|
||||
File t = new File(Base.listFiles(new File(prevSaves[0]), false)[0]);
|
||||
pastSave = new File(t.getAbsolutePath() + File.separator + t.getName() + ".pde");
|
||||
pastSave = new File(t.getAbsolutePath() + File.separator + t.getName() + ".pde");
|
||||
if(pastSave.exists())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -55,10 +57,11 @@ public class AutoSaveUtil {
|
||||
|
||||
public void init(){
|
||||
if(saveTime < 1000) return;
|
||||
saveTime = 10 * 1000; //TODO: remove
|
||||
//saveTime = 10 * 1000; //TODO: remove
|
||||
timer = new Timer();
|
||||
timer.schedule(new SaveTask(), saveTime, saveTime);
|
||||
isSaving = false;
|
||||
ExperimentalMode.log("AutoSaver started");
|
||||
}
|
||||
|
||||
public void stop(){
|
||||
@@ -204,8 +207,9 @@ public class AutoSaveUtil {
|
||||
|
||||
// let Editor know that the save was successful
|
||||
|
||||
if(deleteOldSave)
|
||||
if(deleteOldSave){
|
||||
Base.removeDir(new File(oldSave));
|
||||
}
|
||||
isSaving = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
// Added temporarily to dump error log. TODO: Remove this later
|
||||
public void internalCloseRunner(){
|
||||
if(ExperimentalMode.errorLogsEnabled) writeErrorsToFile();
|
||||
autosaver.stop();
|
||||
if(autosaver != null) autosaver.stop();
|
||||
super.internalCloseRunner();
|
||||
}
|
||||
|
||||
@@ -874,18 +874,23 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
}
|
||||
|
||||
public void loadAutoSaver(){
|
||||
autosaver = new AutoSaveUtil(this, 5);
|
||||
autosaver = new AutoSaveUtil(this, dmode.autoSaveInterval);
|
||||
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.");
|
||||
int response = Base
|
||||
.showYesNoQuestion(this,
|
||||
"Unsaved backup found!",
|
||||
"An automatic backup of "
|
||||
+ pastSave.getParentFile().getName()
|
||||
+ "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());
|
||||
Base.showMessage("Save it", "Remember to save the backup to a specific location if you want to.");
|
||||
//log(getSketch().getMainFilePath());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -119,11 +119,12 @@ public class ExperimentalMode extends JavaMode {
|
||||
|
||||
volatile public static boolean errorCheckEnabled = true, warningsEnabled = true,
|
||||
codeCompletionsEnabled = true, debugOutputEnabled = false, errorLogsEnabled = false;
|
||||
public int autoSaveInterval = 5; //in minutes
|
||||
|
||||
public final String prefErrorCheck = "pdex.errorCheckEnabled",
|
||||
prefWarnings = "pdex.warningsEnabled",
|
||||
prefCodeCompletionEnabled = "pdex.ccEnabled",
|
||||
prefDebugOP = "pdex.dbgOutput", prefErrorLogs = "pdex.writeErrorLogs";
|
||||
prefDebugOP = "pdex.dbgOutput", prefErrorLogs = "pdex.writeErrorLogs", prefAutoSaveInterval = "pdex.autoSaveInterval";
|
||||
|
||||
public void loadPreferences(){
|
||||
log("Load PDEX prefs");
|
||||
@@ -133,6 +134,7 @@ public class ExperimentalMode extends JavaMode {
|
||||
codeCompletionsEnabled = Preferences.getBoolean(prefCodeCompletionEnabled);
|
||||
DEBUG = Preferences.getBoolean(prefDebugOP);
|
||||
errorLogsEnabled = Preferences.getBoolean(prefErrorLogs);
|
||||
autoSaveInterval = Preferences.getInteger(prefAutoSaveInterval);
|
||||
}
|
||||
|
||||
public void savePreferences(){
|
||||
@@ -142,6 +144,7 @@ public class ExperimentalMode extends JavaMode {
|
||||
Preferences.setBoolean(prefCodeCompletionEnabled, codeCompletionsEnabled);
|
||||
Preferences.setBoolean(prefDebugOP, DEBUG);
|
||||
Preferences.setBoolean(prefErrorLogs,errorLogsEnabled);
|
||||
Preferences.setInteger(prefAutoSaveInterval,autoSaveInterval);
|
||||
}
|
||||
|
||||
public void ensurePrefsExist(){
|
||||
@@ -155,6 +158,8 @@ public class ExperimentalMode extends JavaMode {
|
||||
Preferences.setBoolean(prefDebugOP,DEBUG);
|
||||
if(Preferences.get(prefErrorLogs) == null)
|
||||
Preferences.setBoolean(prefErrorLogs,errorLogsEnabled);
|
||||
if(Preferences.get(prefAutoSaveInterval) == null)
|
||||
Preferences.setInteger(prefAutoSaveInterval,autoSaveInterval);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user