1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 16:27:59 +01:00

Fix bugs. Add optional bang to :loadplugins.

--HG--
branch : groups
This commit is contained in:
Kris Maglione
2011-02-07 04:13:57 -05:00
parent a8ef60f4d5
commit 27f973a4d0
3 changed files with 25 additions and 21 deletions

View File

@@ -103,6 +103,7 @@ var Group = Class("Group", {
memoize(Group.prototype, name, function () { memoize(Group.prototype, name, function () {
let group = constructor(this); let group = constructor(this);
this.hives.push(group); this.hives.push(group);
delete contexts.groups;
return group; return group;
}); });
@@ -126,7 +127,7 @@ var Contexts = Module("contexts", {
this.builtin = this.addGroup("builtin", "Builtin items"); this.builtin = this.addGroup("builtin", "Builtin items");
this.user = this.addGroup("user", "User-defined items", null, true); this.user = this.addGroup("user", "User-defined items", null, true);
this.builtinGroups = [this.system, this.user]; this.builtinGroups = [this.builtin, this.user];
}, },
destroy: function () { destroy: function () {
@@ -157,11 +158,16 @@ var Contexts = Module("contexts", {
get hives() Group.hiveMap, get hives() Group.hiveMap,
addGroup: function addGroup(name, description, filter, persist, replace) { addGroup: function addGroup(name, description, filter, persist, replace) {
let group = this.getGroup(name);
if (group)
name = group.name;
if (replace) if (replace)
this.removeGroup(name); this.removeGroup(name);
let group = this.groupMap[name]; if (!group || replace) {
if (!group) { dactyl.assert(name !== "default", "Illegal group name");
group = Group(name, description, filter, persist); group = Group(name, description, filter, persist);
this.groupList.unshift(group); this.groupList.unshift(group);
this.groupMap[name] = group; this.groupMap[name] = group;
@@ -183,6 +189,7 @@ var Contexts = Module("contexts", {
dactyl.assert(!group || !group.builtin, "Cannot remove builtin group"); dactyl.assert(!group || !group.builtin, "Cannot remove builtin group");
if (group) { if (group) {
name = group.name;
this.groupList.splice(this.groupList.indexOf(group), 1); this.groupList.splice(this.groupList.indexOf(group), 1);
group.cleanup(); group.cleanup();
group.destroy(); group.destroy();
@@ -201,7 +208,7 @@ var Contexts = Module("contexts", {
if (name === "default") if (name === "default")
var group = this.context && this.context.context && this.context.context.GROUP; var group = this.context && this.context.context && this.context.context.GROUP;
else else
group = array.nth(this.groupList, function (h) h.name == name, 0) || null; group = set.has(this.groupMap, name) && this.groupMap[name];
if (group && hive) if (group && hive)
return group[hive]; return group[hive];

View File

@@ -1031,7 +1031,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
get: function globalVariables() this._globalVariables get: function globalVariables() this._globalVariables
}), }),
loadPlugins: function (args) { loadPlugins: function (args, force) {
function sourceDirectory(dir) { function sourceDirectory(dir) {
dactyl.assert(dir.isReadable(), "E484: Can't open file " + dir.path); dactyl.assert(dir.isReadable(), "E484: Can't open file " + dir.path);
@@ -1042,7 +1042,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
loadplugins = { __proto__: loadplugins, value: args.map(Option.parseRegexp) } loadplugins = { __proto__: loadplugins, value: args.map(Option.parseRegexp) }
dir.readDirectory(true).forEach(function (file) { dir.readDirectory(true).forEach(function (file) {
if (file.isFile() && loadplugins.getKey(file.path) && !(file.path in dactyl.pluginFiles)) { if (file.isFile() && loadplugins.getKey(file.path) && !(!force && file.path in dactyl.pluginFiles)) {
try { try {
io.source(file.path); io.source(file.path);
dactyl.pluginFiles[file.path] = true; dactyl.pluginFiles[file.path] = true;
@@ -1756,10 +1756,11 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
commands.add(["loadplugins", "lpl"], commands.add(["loadplugins", "lpl"],
"Load all plugins immediately", "Load all plugins immediately",
function (args) { function (args) {
dactyl.loadPlugins(args.length ? args : null); dactyl.loadPlugins(args.length ? args : null, args.bang);
}, },
{ {
argCount: "*", argCount: "*",
bang: true,
keepQuotes: true, keepQuotes: true,
serialGroup: 10, serialGroup: 10,
serialize: function () [ serialize: function () [

View File

@@ -38,8 +38,6 @@ var ProcessorStack = Class("ProcessorStack", {
}, },
execute: function execute(result, force) { execute: function execute(result, force) {
function dbg() {}
if (force && this.actions.length) if (force && this.actions.length)
this.processors.length = 0; this.processors.length = 0;
@@ -71,15 +69,15 @@ var ProcessorStack = Class("ProcessorStack", {
else if (result === undefined) else if (result === undefined)
result = Events.PASS; result = Events.PASS;
dbg("RESULT: " + (result === Events.KILL ? "KILL" : events.dbg("RESULT: " + (result === Events.KILL ? "KILL" :
result === Events.PASS ? "PASS" : result === Events.PASS ? "PASS" :
result === Events.ABORT ? "ABORT" : result)); result === Events.ABORT ? "ABORT" : result));
if (result !== Events.PASS) if (result !== Events.PASS)
Events.kill(this.events[this.events.length - 1]); Events.kill(this.events[this.events.length - 1]);
if (result === Events.PASS || result === Events.ABORT) { if (result === Events.PASS || result === Events.ABORT) {
let list = this.events.filter(function (e) e.getPreventDefault()); let list = this.events.filter(function (e) e.getPreventDefault() && !e.dactylDefaultPrevented);
if (list.length) if (list.length)
events.dbg("REFEED: " + list.map(events.closure.toString).join("")); events.dbg("REFEED: " + list.map(events.closure.toString).join(""));
@@ -102,8 +100,6 @@ var ProcessorStack = Class("ProcessorStack", {
}, },
process: function process(event) { process: function process(event) {
function dbg() {}
if (this.timer) if (this.timer)
this.timer.cancel(); this.timer.cancel();
@@ -115,15 +111,15 @@ var ProcessorStack = Class("ProcessorStack", {
let actions = []; let actions = [];
let processors = []; let processors = [];
dbg("\n\n"); events.dbg("\n\n");
dbg("KEY: " + key + " skipmap: " + event.skipmap + " macro: " + event.isMacro); events.dbg("KEY: " + key + " skipmap: " + event.skipmap + " macro: " + event.isMacro);
for (let [i, input] in Iterator(this.processors)) { for (let [i, input] in Iterator(this.processors)) {
let res = input.process(event); let res = input.process(event);
if (res !== Events.ABORT) if (res !== Events.ABORT)
var result = res; var result = res;
dbg("RES: " + input + " " + (callable(res) ? {}.toString.call(res) : res)); events.dbg("RES: " + input + " " + (callable(res) ? {}.toString.call(res) : res));
if (res === Events.KILL) if (res === Events.KILL)
break; break;
@@ -139,9 +135,9 @@ var ProcessorStack = Class("ProcessorStack", {
processors.push(input); processors.push(input);
} }
dbg("RESULT: " + (callable(result) ? {}.toString.call(result) : result) + " " + event.getPreventDefault()); events.dbg("RESULT: " + (callable(result) ? {}.toString.call(result) : result) + " " + event.getPreventDefault());
dbg("ACTIONS: " + actions.length + " " + this.actions.length); events.dbg("ACTIONS: " + actions.length + " " + this.actions.length);
dbg("PROCESSORS:", processors); events.dbg("PROCESSORS:", processors);
this._actions = actions; this._actions = actions;
this.actions = actions.concat(this.actions); this.actions = actions.concat(this.actions);