mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Beginning auto save impl
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package processing.mode.experimental;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class AutoSaveUtil {
|
||||
|
||||
private DebugEditor editor;
|
||||
|
||||
private Timer timer;
|
||||
|
||||
private int saveTime;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param dedit
|
||||
* @param timeOut - in minutes
|
||||
*/
|
||||
public AutoSaveUtil(DebugEditor dedit, int timeOut){
|
||||
editor = dedit;
|
||||
if (timeOut < 5) {
|
||||
saveTime = -1;
|
||||
throw new IllegalArgumentException("");
|
||||
}
|
||||
else{
|
||||
saveTime = timeOut * 60 * 1000;
|
||||
}
|
||||
}
|
||||
|
||||
public void init(){
|
||||
if(saveTime < 1000) return;
|
||||
saveTime = 1000;
|
||||
timer = new Timer();
|
||||
timer.schedule(new SaveTask(), saveTime, saveTime);
|
||||
}
|
||||
|
||||
private class SaveTask extends TimerTask{
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ExperimentalMode.log("Saved " + editor.getSketch().getMainFilePath());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -177,6 +177,8 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
*/
|
||||
protected JCheckBoxMenuItem completionsEnabled;
|
||||
|
||||
protected AutoSaveUtil autosaver;
|
||||
|
||||
public DebugEditor(Base base, String path, EditorState state, Mode mode) {
|
||||
super(base, path, state, mode);
|
||||
|
||||
@@ -244,6 +246,8 @@ public class DebugEditor extends JavaEditor implements ActionListener {
|
||||
addXQModeUI();
|
||||
debugToolbarEnabled = new AtomicBoolean(false);
|
||||
log("Sketch Path: " + path);
|
||||
autosaver = new AutoSaveUtil(this, 5);
|
||||
autosaver.init();
|
||||
}
|
||||
|
||||
private void addXQModeUI(){
|
||||
|
||||
Reference in New Issue
Block a user