Settings are now merged a la Sublime, which is much better for migrations.
This commit is contained in:
parent
dc594f1472
commit
295ca0c714
4 changed files with 78 additions and 10 deletions
|
@ -33,11 +33,18 @@
|
|||
{
|
||||
"label": "Settings",
|
||||
"sub": [
|
||||
{ "label": "User Settings", "command": "session:open-settings-file", "argument": "user" },
|
||||
{ "label": "User Preferences", "command": "session:open-settings-file", "argument": "user" },
|
||||
{ "label": "Keyboard", "command": "session:open-settings-file", "argument": "keys" },
|
||||
{ "label": "Menus", "command": "session:open-settings-file", "argument": "menus" },
|
||||
"divider",
|
||||
{ "label": "Reset to Default",
|
||||
{ "label": "View Defaults",
|
||||
"sub": [
|
||||
{ "label": "User Preferences", "command": "session:open-settings-defaults", "argument": "user" },
|
||||
{ "label": "Keyboard", "command": "session:open-settings-defaults", "argument": "keys" },
|
||||
{ "label": "Menus", "command": "session:open-settings-defaults", "argument": "menus" }
|
||||
]
|
||||
},
|
||||
{ "label": "Reset",
|
||||
"sub": [
|
||||
{ "label": "User Settings", "command": "settings:delete-local", "argument": "user" },
|
||||
{ "label": "Keyboard", "command": "settings:delete-local", "argument": "keys" },
|
||||
|
|
|
@ -5,13 +5,18 @@ these files from the menu, then save it, it'll be dropped into Chrome's
|
|||
synchronized storage, which means that (theoretically) all your computers will
|
||||
get a copy. Comments are allowed, obviously--they'll be stripped out on load.
|
||||
|
||||
Unfortunately, it's not (yet) possible to merge configuration the way that
|
||||
Sublime does, which means that this won't behave exactly like you may expect.
|
||||
If new options are introduced, you'll need to copy your settings to a new
|
||||
file, reset Caret's config to the defaults from the menu, then copy your
|
||||
configuration changes back over. Sorry about that. I'm working on it.
|
||||
Your individual settings are shallow-merged with a copy of the defaults
|
||||
(available from Settings > View Defaults). When you first open them, your
|
||||
configuration will be a copy of the defaults, but I recommend stripping out
|
||||
anything you don't want to set explicitly, so that you can benefit if the
|
||||
default settings change in future releases.
|
||||
|
||||
If your local file is not valid JSON, the defaults will be used. If your changes
|
||||
aren't being accepted, run the file (sans comments) through a JSON checker and
|
||||
make sure you don't have any syntax errors.
|
||||
|
||||
*/
|
||||
|
||||
{
|
||||
//This should be any of the supported Ace themes
|
||||
"defaultTheme": "chrome", //AKA "Native"
|
||||
|
@ -27,4 +32,5 @@ configuration changes back over. Sorry about that. I'm working on it.
|
|||
//Web workers are used for code hinting in PHP, JavaScript, and JSON.
|
||||
//We don't yet have a way to set the worker options, but you can disable it.
|
||||
"useWorker": true
|
||||
|
||||
}
|
|
@ -159,6 +159,7 @@ define([
|
|||
}
|
||||
tab.syntaxMode = syntaxValue;
|
||||
}
|
||||
tab.setMode("ace/mode/" + syntaxValue);
|
||||
syntax.value = syntaxValue;
|
||||
};
|
||||
|
||||
|
@ -385,6 +386,17 @@ define([
|
|||
});
|
||||
});
|
||||
|
||||
//defaults don't get loaded as files, just as content
|
||||
command.on("session:open-settings-defaults", function(name) {
|
||||
Settings.load(name, function() {
|
||||
var tab = addTab(Settings.getAsString(name, true));
|
||||
tab.syntaxMode = "javascript";
|
||||
setTabSyntax(tab);
|
||||
tab.fileName = name + ".json";
|
||||
renderTabs();
|
||||
});
|
||||
});
|
||||
|
||||
command.on("session:open-launch", openFromLaunchData);
|
||||
|
||||
var locationMemory = null;
|
||||
|
|
|
@ -36,18 +36,61 @@ define(["command"], function(command) {
|
|||
},
|
||||
retain: function() { return false; }
|
||||
};
|
||||
|
||||
var clone = function(item) {
|
||||
var cloneArray = function(a) {
|
||||
var n = [];
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
if (a[i] instanceof Array) {
|
||||
n[i] = cloneArray(a[i]);
|
||||
} else if (typeof a[i] == "object") {
|
||||
n[i] = cloneObject(a[i]);
|
||||
} else {
|
||||
n[i] = a[i];
|
||||
}
|
||||
}
|
||||
return n;
|
||||
};
|
||||
var cloneObject = function(o) {
|
||||
var n = {};
|
||||
for (var key in o) {
|
||||
if (o[key] instanceof Array) {
|
||||
n[key] = cloneArray(o[key]);
|
||||
} else if (typeof o[key] == "object") {
|
||||
n[key] = cloneObject(o[key]);
|
||||
} else {
|
||||
n[key] = o[key];
|
||||
}
|
||||
}
|
||||
return n;
|
||||
};
|
||||
if (item instanceof Array) {
|
||||
return cloneArray(item);
|
||||
}
|
||||
return cloneObject(item);
|
||||
};
|
||||
|
||||
var Settings = {
|
||||
get: function(name) {
|
||||
name = name + ".json";
|
||||
var comments = /\/\*[\s\S]*?\*\/|\/\/.*$/gm;
|
||||
var original = clone(JSON.parse(defaults[name].replace(comments, "")));
|
||||
var custom = {};
|
||||
try {
|
||||
return JSON.parse(local[name].replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, ""));
|
||||
custom = JSON.parse(local[name].replace(comments, ""));
|
||||
} catch (e) {
|
||||
return JSON.parse(defaults[name].replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, ""));
|
||||
//parse failed
|
||||
}
|
||||
for (var key in custom) {
|
||||
original[key] = custom[key];
|
||||
}
|
||||
return original;
|
||||
},
|
||||
getAsString: function(name) {
|
||||
getAsString: function(name, original) {
|
||||
name = name + ".json";
|
||||
if (original) {
|
||||
return defaults[name];
|
||||
}
|
||||
return local[name] || defaults[name];
|
||||
},
|
||||
getAsFile: function(name) {
|
||||
|
|
Loading…
Reference in a new issue