Beginning auto save impl

This commit is contained in:
Manindra Moharana
2014-01-11 20:28:31 +05:30
parent 5fdfc88f3d
commit 22d5216fc4
2 changed files with 54 additions and 0 deletions
@@ -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(){