Commit aa652340 authored by ThorbenQuast's avatar ThorbenQuast
Browse files

editor: save file specific preview paths in cookies

parent b01b115d
......@@ -104,7 +104,7 @@ define(function() {
},
cookies: {
description: "Allow the web-browser to store the last executed command.",
description: "Allow the web-browser to store the last executed commands and preview paths of each file.",
type: "boolean",
value: true
},
......
......@@ -24,22 +24,36 @@ define(["jquery", "emitter"], function($, Emitter) {
this.previewData = [];
this.cookie = null;
this.thumbnailSize = null;
this.view.on("stateChange", function(key) {
switch (key) {
case "path":
var path = this.getState("path");
if (path && !this.getState("previewPath")) {
var path = self.view.getState("path");
if (path && !self.view.getState("previewPath")) {
var cookie = $.cookie("VISPA-preview-path");
if (cookie && self.view.getPreference("cookies")) {
cookie = JSON.parse(cookie);
var key = self.view.getState("path");
key = key ? key.split("/").pop() : "UNTITLED";
if (cookie[key]) {
self.setPath(cookie[key], false);
return;
}
}
self.setPath(path, true);
}
break;
case "previewPath":
var previewPath = this.getState("previewPath");
if (previewPath) {
if (self.pathInput)
if (self.pathInput) {
self.pathInput.val(previewPath);
self.pathToCookie(previewPath);
}
self.previewChanged = true;
self.refresh();
}
......@@ -50,7 +64,6 @@ define(["jquery", "emitter"], function($, Emitter) {
setup: function(node) {
var self = this;
var rightBottomNode = node.find(".codeeditor-right-bottom");
this.zoomBtn = $("#zoom", rightBottomNode);
......@@ -89,9 +102,6 @@ define(["jquery", "emitter"], function($, Emitter) {
this.thumbnailSize = this.giveThumbnailSize();
if (this.editor.path)
this.setPath(this.editor.path, true);
// load the preview template
this.view.getTemplate("html/preview.html", function(err, tmpl) {
self.previewTmpl = tmpl;
......@@ -156,7 +166,7 @@ define(["jquery", "emitter"], function($, Emitter) {
self.previewUpdating = false;
return;
}
var files = $.grep(res.filelist, function(file) {
return file.type == "f" && ~self.allowedExtensions.indexOf(file.name.split(".").pop().toLowerCase());
});
......@@ -278,6 +288,21 @@ define(["jquery", "emitter"], function($, Emitter) {
return size;
},
pathToCookie: function(previewPath) {
if (!this.view.getPreference("cookies"))
return;
var cookie = $.cookie("VISPA-preview-path");
if (cookie)
cookie = JSON.parse(cookie);
else
cookie = {};
var key = this.view.getState("path");
key = key ? key.split("/").pop() : "UNTITLED";
cookie[key] = previewPath;
$.cookie("VISPA-preview-path", JSON.stringify(cookie), {
expires: 7
});
}
});
return CodeEditorPreview;
......
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