Skip to content

Commit

Permalink
Add prompt settings and local save restore prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
knicos committed Jul 12, 2017
1 parent f1d128d commit e33d3a3
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 12 deletions.
34 changes: 30 additions & 4 deletions js/core/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,22 @@ Eden.DB.hasLocal = function(pid, vid) {
}


function removeActive(src) {
var ix = src.indexOf("action ACTIVE {");
var count = 1;

var i = ix+16;
for (; i<src.length; i++) {
var ch = src.charAt(i);
if (ch == "{") count++;
else if (ch == "}") count--;
if (count == 0) break;
}

return src.substring(0,ix) + src.substring(i);
}


Eden.DB.load = function(pid, vid, readPassword, callback) {
if(arguments.length == 3){
callback = readPassword;
Expand All @@ -404,9 +420,17 @@ Eden.DB.load = function(pid, vid, readPassword, callback) {
console.log(data);
Eden.DB.emit("error", [(data) ? data.description : "No response from server"]);
} else {
if (Eden.DB.hasLocal(pid,data.saveID)) {
if (eden.root.lookup("jseden_autosave").value() && Eden.DB.hasLocal(pid,data.saveID)) {
console.log("Yes, load local");
callback(Eden.DB.loadLocal(pid));
var ldata = Eden.DB.loadLocal(pid);

if (removeActive(ldata.source) != removeActive(data.source)) {
var r = window.confirm("You have local changes, restore these?");
if (r) callback(ldata);
else callback(data);
} else {
callback(data);
}
} else {
callback(data);
}
Expand All @@ -419,8 +443,10 @@ Eden.DB.load = function(pid, vid, readPassword, callback) {
}
});
} else if (callback) {
if (Eden.DB.hasLocal(pid,vid)) {
callback(Eden.DB.loadLocal(pid));
if (eden.root.lookup("jseden_autosave").value() && Eden.DB.hasLocal(pid,vid)) {
var r = window.confirm("You have local changes, restore these?");
if (r) callback(Eden.DB.loadLocal(pid));
else callback(undefined, "Disconnected");
} else {
callback(undefined, "Disconnected");
}
Expand Down
12 changes: 7 additions & 5 deletions js/core/initialise.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ var doingNavigateAway = false;
var confirmUnload = function (event) {
Eden.DB.log("leave", {project: (eden.project) ? eden.project.id : -1});
if (!doingNavigateAway) {
//eden.project.localSave();
var prompt = "Leaving this page will discard the current script. Your work will not be saved.";
event.returnValue = prompt;
return prompt;
if (eden.root.lookup("jseden_autosave").value()) eden.project.localSave();
else if (eden.root.lookup("jseden_leaveprompt").value()) {
var prompt = "Leaving this page will discard the current script. Your work will not be saved.";
event.returnValue = prompt;
return prompt;
}
}
};

Expand Down Expand Up @@ -218,7 +220,7 @@ function Construit(options,callback) {

// TODO Remove this once restore works
if (edenUI.getOptionValue('optConfirmUnload') != "false") {
//window.addEventListener("beforeunload", confirmUnload);
window.addEventListener("beforeunload", confirmUnload);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion js/core/jseden.min.js

Large diffs are not rendered by default.

30 changes: 29 additions & 1 deletion js/ui/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ EdenUI.Explorer = function() {
</div>
<div class="explore-settings" style="display: none">
<div style="font-size: 8pt">Note: Many of these do not work yet.</div>
<h1>Environment</h1>
<div id="explorerenvsettings" class="explorer-settings-list"></div>
<h1>Project</h1>
<div id="explorerprojectsettings" class="explorer-settings-list"></div>
<h1>Menu Bar</h1>
Expand Down Expand Up @@ -44,9 +46,13 @@ EdenUI.Explorer = function() {
this.expsettings = this.element.find(".explore-settings");

// Make the settings
var curset = this.expsettings.find('#explorerenvsettings').get(0);
this.addSetting(curset, "jseden_autosave", "Enable autosave to local storage", "", "boolean");
this.addSetting(curset, "jseden_leaveprompt", "Enable a leave page prompt", "", "boolean");

var curset = this.expsettings.find('#explorerprojectsettings').get(0);
this.addSetting(curset, "jseden_project_nocomments", "Disable comments", "", "boolean");
this.addSetting(curset, "jseden_project_nocomments", "Disable forking", "", "boolean");
this.addSetting(curset, "jseden_project_noforking", "Disable forking", "", "boolean");

var curset = this.expsettings.find('#explorermenusettings').get(0);
this.addSetting(curset, "jseden_menu_visible", "Menu visible", "", "boolean");
Expand Down Expand Up @@ -166,6 +172,28 @@ EdenUI.Explorer = function() {
}
});

function saveSetting(sym, value) {
window.localStorage.setItem(sym.name, value);
}

var setlist = [
"jseden_autosave",
"jseden_leaveprompt",
"jseden_menu_visible",
"jseden_menu_showhelp",
"jseden_menu_showsearch",
"jseden_menu_showcreate",
"jseden_menu_showexisting",
"jseden_menu_showshare",
"jseden_explorer_enabled"
];

for (var i=0; i<setlist.length; i++) {
var sym = eden.root.lookup(setlist[i]);
sym.assign(window.localStorage[setlist[i]] == "true", eden.root.scope, EdenSymbol.localJSAgent);
sym.addJSObserver("settings", saveSetting);
}


var zoomSym = eden.root.lookup("jseden_explorer_zoom");
var zoomVal = zoomSym.value();
Expand Down
2 changes: 1 addition & 1 deletion js/ui/jseden-ui.min.js

Large diffs are not rendered by default.

0 comments on commit e33d3a3

Please sign in to comment.