Commit 4aafee79 authored by ThorbenQuast's avatar ThorbenQuast
Browse files

editor: update for autosave.

new: - set modified when reopening autosave file,
     - name of autosave file ."file"."ext"~,
     - autosave only when modified&writable&path exists
parent 01f79759
......@@ -152,7 +152,11 @@ class FSAjaxController(AbstractController):
path = json.loads(path)
# 'path' can be a unicode/string or list of unicodes/strings
# so convert it with the convert function
fs.remove(path)
try:
fs.remove(path)
return
except:
return
@cherrypy.expose
@cherrypy.tools.ajax()
......
......@@ -121,19 +121,19 @@ var CodeEditor = Emitter.extend({
self.checkModifications();
self.setupAutoSave();
};
//new: check for auto save tmp file
this.view.POST(vispa.url.dynamic("/ajax/fs/get_file"), {
path: path + "_tmp",
path: self.giveAutoSavePath(),
utf8: true,
watch_id: "code"
}).done(function(res) {
if (res.success) { //an autosave file exists
self.view.confirm("An autosave file exists. Do you want to load its content?",
function(b) {
if (b)
if (b) {
initContent(res);
else
self.view.setModified(true);
} else
self.view.POST(vispa.url.dynamic("/ajax/fs/get_file"), {
path: path,
utf8: true,
......@@ -163,16 +163,16 @@ var CodeEditor = Emitter.extend({
clearTimeout(this.autosaveTimeOut);
this.autosaveTimeOut = null;
var t = this.view.getPreference("autosave");
var t = self.view.getPreference("autosave");
t = t * 1000.0;
if (t == 0)
return this;
this.autosaveTimeOut = setTimeout(function() {
if (self.path && self.writable) {
if (self.path && self.writable && self.view.isModified()) {
self.savingProcessing = true;
var tempPath = self.path + "_tmp";
self.view.POST(vispa.url.dynamic("/ajax/fs/save_file"), {
path: tempPath,
path: self.giveAutoSavePath(),
content: self.getContent(),
utf8: true,
watch_id: "code"
......@@ -220,9 +220,9 @@ var CodeEditor = Emitter.extend({
this.view.toggleMenuEntry("save", isModified && hasPath && writable);
var btn = this.view._getFastMenuEntryNode("save");
if (btn){
if (btn) {
var msg = "";
if (!(isModified && hasPath && writable)){
if (!(isModified && hasPath && writable)) {
msg = "Saving disabled:";
if (!isModified)
msg = msg + "\n - file unmodified";
......@@ -233,7 +233,7 @@ var CodeEditor = Emitter.extend({
}
btn.attr("title", msg);
}
return this
return this;
},
addComment: function() {
......@@ -308,6 +308,7 @@ var CodeEditor = Emitter.extend({
save: function(callback, option, path) {
var self = this;
this.setupAutoSave();
this.removeAutoSaveFile();
if (this.path && !this.view.isModified() && option != "new") {
if ($.isFunction(callback))
......@@ -505,6 +506,24 @@ var CodeEditor = Emitter.extend({
break;
}
return mode;
},
giveAutoSavePath: function() {
if (!this.path)
return "";
var path = this.path;
var parts = path.split("/");
var file = parts.pop();
path = parts.join("/") + "/." + file + "~";
return path;
},
removeAutoSaveFile: function() {
this.view.GET(vispa.url.dynamic("/ajax/fs/remove"), {
"path": JSON.stringify(this.giveAutoSavePath())
//syntax of path required for the fs remove function
});
}
});
\ No newline at end of file
......@@ -176,10 +176,7 @@ var CodeEditorView = vispa.ExtensionView.Center.extend({
// cleanup
var cleanUp = function() {
self.GET(vispa.url.dynamic("/ajax/fs/unwatch"), {});
self.GET(vispa.url.dynamic("/ajax/fs/remove"), {
"path": '["' + self.editor.path + '_tmp"]'
//syntax of path required for the fs remove function
});
self.editor.removeAutoSaveFile();
self.POST("close");
self.output.running = false;
self.preview.clearInterval();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment