diff --git a/public/res/core.js b/public/res/core.js index d52ee475..601d6e39 100644 --- a/public/res/core.js +++ b/public/res/core.js @@ -814,11 +814,12 @@ define([ applyTheme(this.value); }); - // Import settings - $(".action-import-settings").click(function(e) { - $("#input-file-import-settings").click(); + // Import docs and settings + $(".action-import-docs-settings").click(function(e) { + $("#input-file-import-docs-settings").click(); }); - $("#input-file-import-settings").change(function(evt) { + var newLocalStorage = undefined; + $("#input-file-import-docs-settings").change(function(evt) { var files = (evt.dataTransfer || evt.target).files; $(".modal-settings").modal("hide"); _.each(files, function(file) { @@ -827,23 +828,34 @@ define([ return function(e) { var content = e.target.result; try { - JSON.parse(content); + newLocalStorage = JSON.parse(content); + if(!newLocalStorage.version) { + throw 1; + } + $('.modal-import-docs-settings').modal('show'); } catch(e) { - eventMgr.onError(importedFile.name + " is not a valid JSON file."); + eventMgr.onError("Wrong format: " + importedFile.name); return; } - localStorage.settings = content; - window.location.reload(); }; })(file); - var blob = file.slice(0, IMPORT_FILE_MAX_CONTENT_SIZE); - reader.readAsText(blob); + reader.readAsText(file); }); }); + $(".action-import-docs-settings-confirm").click(function(e) { + localStorage.clear(); + var allowedKeys = /^file\.|^focusMode$|^folder\.|^publish\.|^settings$|^sync\.|^theme$|^version$|^welcomeTour$/; + _.each(newLocalStorage, function(value, key) { + if(allowedKeys.test(key)) { + localStorage[key] = value; + } + }); + window.location.reload(); + }); // Export settings - $(".action-export-settings").click(function(e) { - utils.saveAs(JSON.stringify(settings), "StackEdit Settings.json"); + $(".action-export-docs-settings").click(function(e) { + utils.saveAs(JSON.stringify(localStorage), "StackEdit local storage.json"); }); $(".action-default-settings").click(function() { diff --git a/public/res/html/bodyIndex.html b/public/res/html/bodyIndex.html index 6d56a43c..64f71a06 100644 --- a/public/res/html/bodyIndex.html +++ b/public/res/html/bodyIndex.html @@ -1016,18 +1016,6 @@ your own extension...
-
- Import settings - Export settings - Load default settings -
@@ -1037,7 +1025,19 @@ class="icon-help-circled icon-white"> Welcome tour
- Import docs & settings + Export docs & settings +
+
+ + Load default settings Reset application @@ -1117,5 +1117,26 @@
+ + +
\ No newline at end of file diff --git a/public/res/styles/main.less b/public/res/styles/main.less index ea86f602..db4fc3c4 100644 --- a/public/res/styles/main.less +++ b/public/res/styles/main.less @@ -203,7 +203,7 @@ a { * Input ********************/ -// Fix form-inline broken since v3 +// Fix form-inline broken since Bootstrap v3 .form-inline { .col-lg-1 { width: percentage((1 / @grid-columns)); } .col-lg-2 { width: percentage((2 / @grid-columns)); }