mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 15:57:58 +01:00
More groups work, including -args flag and proper serialization.
--HG-- branch : groups
This commit is contained in:
@@ -9,7 +9,7 @@ var Group = Class("Group", {
|
||||
const self = this;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.filter = filter || function (uri) true;
|
||||
this.filter = filter || Group.defaultFilter;
|
||||
this.persist = persist || false;
|
||||
this.subGroups = [];
|
||||
},
|
||||
@@ -20,6 +20,8 @@ var Group = Class("Group", {
|
||||
subGroup.cleanup();
|
||||
},
|
||||
|
||||
argsExtra: function argsExtra() ({}),
|
||||
|
||||
get toStringParams() [this.name],
|
||||
|
||||
get builtin() contexts.builtinGroups.indexOf(this) >= 0,
|
||||
@@ -52,6 +54,8 @@ var Group = Class("Group", {
|
||||
|
||||
groupsProto: {},
|
||||
|
||||
defaultFilter: Class.memoize(function () this.compileFilter(["*"])),
|
||||
|
||||
subGroupMap: {},
|
||||
|
||||
SubGroup: Class("SubGroup", Class.Property, {
|
||||
@@ -91,7 +95,7 @@ var Contexts = Module("contexts", {
|
||||
this.groupMap = {};
|
||||
this.subGroupProto = {};
|
||||
|
||||
this.system = this.addGroup("builtin", "Builtin items");
|
||||
this.builtin = this.addGroup("builtin", "Builtin items");
|
||||
this.user = this.addGroup("user", "User-defined items", null, true);
|
||||
this.builtinGroups = [this.system, this.user];
|
||||
},
|
||||
@@ -295,7 +299,7 @@ var Contexts = Module("contexts", {
|
||||
let filter = Group.compileFilter(args["-locations"]);
|
||||
if (!group)
|
||||
group = contexts.addGroup(name, args["-description"], filter, !args["-nopersist"]);
|
||||
else {
|
||||
else if (!group.builtin) {
|
||||
if (args.has("-locations"))
|
||||
group.filter = filter;
|
||||
if (args.has("-description"))
|
||||
@@ -304,6 +308,12 @@ var Contexts = Module("contexts", {
|
||||
group.persist = !args["-nopersist"]
|
||||
}
|
||||
|
||||
if (!group.builtin && args.has("-args")) {
|
||||
group.argsExtra = contexts.bindMacro({ literalArg: "return " + args["-args"] },
|
||||
"-javascript", util.identity);
|
||||
group.args = args["-args"];
|
||||
}
|
||||
|
||||
if (args.context)
|
||||
args.context.group = group;
|
||||
},
|
||||
@@ -316,6 +326,11 @@ var Contexts = Module("contexts", {
|
||||
},
|
||||
keepQuotes: true,
|
||||
options: [
|
||||
{
|
||||
names: ["-args", "-a"],
|
||||
description: "JavaScript Object which augments the arguments passed to commands, mappings, and autocommands",
|
||||
type: CommandOption.STRING
|
||||
},
|
||||
{
|
||||
names: ["-description", "-desc", "-d"],
|
||||
description: "A description of this group",
|
||||
@@ -332,7 +347,26 @@ var Contexts = Module("contexts", {
|
||||
names: ["-nopersist", "-n"],
|
||||
description: "Do not save this group to an auto-generated RC file"
|
||||
}
|
||||
]
|
||||
],
|
||||
serialGroup: 20,
|
||||
serialize: function () [
|
||||
{
|
||||
command: this.name,
|
||||
bang: true,
|
||||
options: iter([v, typeof group[k] == "boolean" ? null : group[k]]
|
||||
// FIXME: this map is expressed multiple times
|
||||
for ([k, v] in Iterator({
|
||||
args: "-args",
|
||||
description: "-description",
|
||||
filter: "-locations"
|
||||
}))
|
||||
if (group[k])).toObject(),
|
||||
arguments: [group.name],
|
||||
ignoreDefaults: true
|
||||
}
|
||||
for (group in values(contexts.activeGroups()))
|
||||
if (!group.builtin && group.persist)
|
||||
].concat([{ command: this.name, arguments: ["user"] }])
|
||||
});
|
||||
|
||||
commands.add(["delg[roup]"],
|
||||
|
||||
Reference in New Issue
Block a user