1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-29 08:45:47 +01:00

Create 'group's for sourced scripts.

--HG--
branch : groups
This commit is contained in:
Kris Maglione
2011-02-05 05:18:57 -05:00
parent f06e7075ee
commit 020ad98197
3 changed files with 74 additions and 49 deletions

View File

@@ -51,6 +51,8 @@ var Group = Class("Group", {
})
});
plugins.contexts = {};
var Contexts = Module("contexts", {
init: function () {
this.groupList = [];
@@ -72,6 +74,10 @@ var Contexts = Module("contexts", {
groups: { value: this.groupList }
})),
activeGroups: function (subgroup)
let (need = subgroup ? [subgroup] : Object.keys(this.subGroup))
this.groupList.filter(function (group) need.some(function (name) set.has(group, name))),
get subGroup() Group.subGroupMap,
addGroup: function addGroup(name, description, filter, persist) {
@@ -152,6 +158,44 @@ var Contexts = Module("contexts", {
return action;
}
}, {
Context: modules.Script = function Context(file, group, args) {
let isPlugin = io.getRuntimeDirectories("plugins")
.some(function (dir) dir.contains(file, false))
let self = set.has(plugins, file.path) && plugins[file.path];
if (self) {
if (set.has(self, "onUnload"))
self.onUnload();
}
else {
self = update(modules.newContext.apply(null, args || [userContext]), {
NAME: file.leafName.replace(/\..*/, "").replace(/-([a-z])/g, function (m, n1) n1.toUpperCase()),
PATH: file.path,
CONTEXT: self
});
Class.replaceProperty(plugins, file.path, self);
// This belongs elsewhere
if (isPlugin && args)
Object.defineProperty(plugins, self.NAME, {
configurable: true,
enumerable: true,
value: self,
writeable: false
});
}
self.GROUP = group ||
contexts.addGroup(isPlugin ? "plugin-" + self.NAME
: "script-" + array(commands.nameRegexp.iterate(file.path)).join("-"),
"Script group for " + file.path,
null, false);
return plugins.contexts[file.path] = self;
},
Script: function Script(file, group) {
return this.Context(file, group, [plugins, true]);
}
}, {
commands: function initCommands() {
@@ -161,7 +205,7 @@ var Contexts = Module("contexts", {
dactyl.assert(args.length <= 2, "Trailing characters");
if (args.length == 0)
return void completion.listCompleter("group", "");
return void completion.listCompleter("group", "", null, null);
let name = Option.dequote(args[0]);
dactyl.assert(commands.validName.test(name), "Invalid group name");
@@ -306,10 +350,11 @@ var Contexts = Module("contexts", {
});
},
completion: function initCompletion() {
completion.group = function group(context, modes) {
completion.group = function group(context, active) {
context.title = ["Group"];
context.keys = { text: "name", description: function (h) h.description || h.filter };
context.completions = contexts.groupList.slice(0, -1);
context.completions = (active === undefined ? contexts.groupList : contexts.activeGroups(active))
.slice(0, -1);
};
}
});

View File

@@ -1040,7 +1040,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
dir.readDirectory(true).forEach(function (file) {
if (file.isFile() && loadplugins.getKey(file.path) && !(file.path in dactyl.pluginFiles)) {
try {
io.source(file.path, false);
io.source(file.path);
dactyl.pluginFiles[file.path] = true;
}
catch (e) {
@@ -2075,14 +2075,14 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
if (dactyl.commandLineOptions.rcFile) {
let filename = dactyl.commandLineOptions.rcFile;
if (!/^(NONE|NORC)$/.test(filename))
io.source(io.File(filename).path, false); // let io.source handle any read failure like Vim
io.source(io.File(filename).path, { group: contexts.user });
}
else {
if (init)
dactyl.execute(init);
else {
if (rcFile) {
io.source(rcFile.path, false);
io.source(rcFile.path, { group: contexts.user });
services.environment.set("MY_" + config.idName + "RC", rcFile.path);
}
else
@@ -2092,7 +2092,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
if (options["exrc"] && !dactyl.commandLineOptions.rcFile) {
let localRCFile = io.getRCFile(io.cwd);
if (localRCFile && !localRCFile.equals(rcFile))
io.source(localRCFile.path, false);
io.source(localRCFile.path, { group: contexts.user });
}
}