working on autosave

This commit is contained in:
Manindra Moharana
2014-03-02 20:40:42 +05:30
parent 1377f759b3
commit f159f80986
4 changed files with 81 additions and 20 deletions

View File

@@ -238,7 +238,7 @@ public class ASTGenerator {
/**
* Toggle AST View window
*/
public static final boolean SHOWAST = true;
public static final boolean SHOWAST = !true;
protected DefaultMutableTreeNode buildAST(String source, CompilationUnit cu) {
if (cu == null) {
@@ -254,14 +254,14 @@ public class ASTGenerator {
compilationUnit = (CompilationUnit) parser.createAST(null);
} else {
compilationUnit = cu;
log("Other cu");
//log("Other cu");
}
// OutlineVisitor visitor = new OutlineVisitor();
// compilationUnit.accept(visitor);
getCodeComments();
codeTree = new DefaultMutableTreeNode(new ASTNodeWrapper((ASTNode) compilationUnit
.types().get(0)));
log("Total CU " + compilationUnit.types().size());
//log("Total CU " + compilationUnit.types().size());
if(compilationUnit.types() == null || compilationUnit.types().isEmpty()){
logE("No CU found!");
}

View File

@@ -46,6 +46,10 @@ public class AutoSaveUtil {
private boolean isSaving;
private boolean isAutoSaveBackup;
private File sketchFolder, sketchBackupFolder;
/**
*
* @param dedit
@@ -62,8 +66,18 @@ public class AutoSaveUtil {
ExperimentalMode.log("AutoSaver Interval(mins): " + timeOut);
}
autosaveDir = new File(editor.getSketch().getFolder().getAbsolutePath() + File.separator + "_autosave");
sketchFolder = editor.getSketch().getFolder();
checkIfBackup();
}
private void checkIfBackup(){
}
public boolean isAutoSaveBackup() {
return isAutoSaveBackup;
}
/**
* Check if any previous autosave exists
* @return
@@ -73,6 +87,7 @@ 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]);
sketchBackupFolder = t;
pastSave = new File(t.getAbsolutePath() + File.separator + t.getName() + ".pde");
if(pastSave.exists())
return true;
@@ -89,6 +104,18 @@ public class AutoSaveUtil {
autosaveDir = new File(editor.getSketch().getFolder().getAbsolutePath() + File.separator + "_autosave");
}
/**
* The folder of the original sketch
* @return
*/
public File getSketchFolder(){
return sketchFolder;
}
public File getSketchBackupFolder(){
return sketchBackupFolder;
}
public File getPastSave(){
return pastSave;
}
@@ -98,7 +125,7 @@ public class AutoSaveUtil {
*/
public void init(){
if(saveTime < 10000) saveTime = 10 * 1000;
//saveTime = 10 * 1000; //TODO: remove
saveTime = 5 * 1000; //TODO: remove
timer = new Timer();
timer.schedule(new SaveTask(), saveTime, saveTime);
isSaving = false;
@@ -112,6 +139,7 @@ public class AutoSaveUtil {
while(isSaving); // save operation mustn't be interrupted
if(timer != null) timer.cancel();
Base.removeDir(autosaveDir);
ExperimentalMode.log("Stopping autosaver and deleting backup dir");
}
/**

View File

@@ -245,7 +245,10 @@ public class DebugEditor extends JavaEditor implements ActionListener {
ta.setECSandThemeforTextArea(errorCheckerService, dmode);
addXQModeUI();
debugToolbarEnabled = new AtomicBoolean(false);
log("Sketch Path: " + path);
//log("Sketch Path: " + path);
viewingAutosaveBackup = false;
log("DebugEdit constructed. Viewing auto save false " + viewingAutosaveBackup);
}
private void addXQModeUI(){
@@ -342,7 +345,10 @@ public class DebugEditor extends JavaEditor implements ActionListener {
// Added temporarily to dump error log. TODO: Remove this later
public void internalCloseRunner(){
if(ExperimentalMode.errorLogsEnabled) writeErrorsToFile();
if(autosaver != null) autosaver.stop();
if(autosaver != null && !viewingAutosaveBackup) {
log("stopping autosaver in internalCloseRunner");
autosaver.stop();
}
super.internalCloseRunner();
}
@@ -738,6 +744,7 @@ public class DebugEditor extends JavaEditor implements ActionListener {
*/
@Override
protected boolean handleOpenInternal(String path) {
log("handleOpenInternal, path: " + path);
boolean didOpen = super.handleOpenInternal(path);
if (didOpen && dbg != null) {
// should already been stopped (open calls handleStop)
@@ -745,9 +752,16 @@ public class DebugEditor extends JavaEditor implements ActionListener {
clearBreakpointedLines(); // force clear breakpoint highlights
variableInspector().reset(); // clear contents of variable inspector
}
if(autosaver != null)
autosaver.stop();
loadAutoSaver();
if(!viewingAutosaveBackup){
log("Sketch isn't a backup");
if(autosaver != null){
log("stopping autosaver in handleOpenInternal");
autosaver.stop();
}
loadAutoSaver();
}
log("handleOpenInternal, viewing autosave? " + viewingAutosaveBackup);
return didOpen;
}
@@ -825,7 +839,25 @@ public class DebugEditor extends JavaEditor implements ActionListener {
@Override
public boolean handleSave(boolean immediately) {
//System.out.println("handleSave " + immediately);
log("handleSave, viewing autosave? " + viewingAutosaveBackup);
/* If user wants to save a backup, the backup sketch should get
* copied to the main sketch directory, simply reload the main sketch.
*/
if(viewingAutosaveBackup){
File files[] = autosaver.getSketchBackupFolder().listFiles();
File src = autosaver.getSketchBackupFolder(), dst = autosaver
.getSketchFolder();
for (File f : files) {
log("Copying " + f.getAbsolutePath() + " to " + dst.getAbsolutePath());
// if(f.isFile())
//Base.copyFile(f, new File(dst + File.separator + f.getName()));
// else
// Base.copyDir(f, new File(dst + File.separator + f.getName()));
}
//viewingAutosaveBackup = false;
}
// note modified tabs
final List<String> modified = new ArrayList();
for (int i = 0; i < getSketch().getCodeCount(); i++) {
@@ -887,6 +919,8 @@ public class DebugEditor extends JavaEditor implements ActionListener {
return saved;
}
private boolean viewingAutosaveBackup;
/**
* Loads and starts the auto save service
* Also handles the case where an auto save backup is found.
@@ -894,15 +928,12 @@ public class DebugEditor extends JavaEditor implements ActionListener {
*/
public void loadAutoSaver(){
log("Load Auto Saver()");
if(autosaver != null){
autosaver.stop();
}
autosaver = new AutoSaveUtil(this, ExperimentalMode.autoSaveInterval);
autosaver = new AutoSaveUtil(this, ExperimentalMode.autoSaveInterval);
if(!autosaver.checkForPastSave()) {
autosaver.init();
return;
}
if(viewingAutosaveBackup) return;
File pastSave = autosaver.getPastSave();
int response = Base
.showYesNoQuestion(this,
@@ -913,9 +944,11 @@ public class DebugEditor extends JavaEditor implements ActionListener {
"was closed 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 sketch to a specific location if you want to.");
viewingAutosaveBackup = true;
handleOpenInternal(pastSave.getAbsolutePath());
// Base.showMessage("Save it..", "Remember to save the backup sketch to a specific location if you want to.");
//log(getSketch().getMainFilePath());
log("loadAutoSaver, viewing autosave? " + viewingAutosaveBackup);
return;
}
else{

View File

@@ -1387,9 +1387,9 @@ public class ErrorCheckerService implements Runnable{
* compiler classpath needs to be updated.
*/
protected void checkForChangedImports() {
log("Imports: " + programImports.size() +
" Prev Imp: "
+ previousImports.size());
// log("Imports: " + programImports.size() +
// " Prev Imp: "
// + previousImports.size());
if (programImports.size() != previousImports.size()) {
// log(1);
loadCompClass = true;