1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-04-01 02:43:36 +02:00

Fix some context splitting issues and add the group flag missing from some :style commands.

This commit is contained in:
Kris Maglione
2011-02-11 07:22:44 -05:00
parent f387275ea0
commit 791994cc18
2 changed files with 62 additions and 58 deletions

View File

@@ -227,7 +227,7 @@ var Contexts = Module("contexts", {
if (!group) if (!group)
group = this.addGroup(commands.nameRegexp group = this.addGroup(commands.nameRegexp
.iterate(name.replace(/\.[^.]*$/, "")) .iterate(name.replace(/\.[^.]*$/, ""))
.join("-"), .join("-").replace(/--+/g, "-"),
"Script group for " + file.path, "Script group for " + file.path,
null, false); null, false);
@@ -608,7 +608,7 @@ var Contexts = Module("contexts", {
iter({ Active: true, Inactive: false }).forEach(function ([name, active]) { iter({ Active: true, Inactive: false }).forEach(function ([name, active]) {
context.split(name, null, function (context) { context.split(name, null, function (context) {
context.title[0] = name + " Groups"; context.title[0] = name + " Groups";
context.filters.push(function (item) item.active == active); context.filters.push(function ({ item }) !!item.filter(modules.buffer.uri) == active);
}); });
}); });
}; };

View File

@@ -316,7 +316,8 @@ var Styles = Module("Styles", {
.join(" "); .join(" ");
}, },
completeSite: function (context, content) { completeSite: function (context, content, group) {
group = group || styles.user;
context.anchored = false; context.anchored = false;
try { try {
context.fork("current", 0, this, function (context) { context.fork("current", 0, this, function (context) {
@@ -328,10 +329,18 @@ var Styles = Module("Styles", {
}); });
} }
catch (e) {} catch (e) {}
context.fork("others", 0, this, function (context) {
context.title = ["Site"]; let uris = util.visibleURIs(content);
context.completions = [[s, ""] for ([, s] in Iterator(styles.user.sites))];
}); context.generate = function () values(group.sites);
context.keys.text = util.identity;
context.keys.description = function (site) this.sheets.length + " sheet" + (this.sheets.length == 1 ? "" : "s") + ": " +
array.compact(this.sheets.map(function (s) s.name)).join(", ");
context.keys.sheets = function (site) group.sheets.filter(function (s) s.sites.indexOf(site) >= 0);
context.keys.active = function (site) uris.some(Styles.matchFilter(site));
Styles.splitContext(context, "Sites");
}, },
/** /**
@@ -367,6 +376,17 @@ var Styles = Module("Styles", {
return test(arguments[1]); return test(arguments[1]);
}, },
splitContext: function splitContext(context, title) {
for (let item in Iterator({ Active: true, Inactive: false })) {
let [name, active] = item;
context.split(name, null, function (context) {
context.title[0] = name + " " + (title || "Sheets");
context.filters.push(function (item) !!item.active == active);
});
}
},
propertyIter: function (str, always) { propertyIter: function (str, always) {
let i = 0; let i = 0;
for (let match in this.propertyPattern.iterate(str)) { for (let match in this.propertyPattern.iterate(str)) {
@@ -452,6 +472,28 @@ var Styles = Module("Styles", {
commands: function (dactyl, modules, window) { commands: function (dactyl, modules, window) {
const { commands, contexts } = modules; const { commands, contexts } = modules;
function sheets(context, args, filter) {
let uris = util.visibleURIs(window.content);
context.compare = modules.CompletionContext.Sort.number;
context.generate = function () args["-group"].sheets;
context.keys.active = function (sheet) uris.some(sheet.closure.match);
context.keys.description = function (sheet) <>{sheet.formatSites(uris)}: {sheet.css.replace("\n", "\\n")}</>
if (filter)
context.filters.push(function ({ item }) filter(item));
Styles.splitContext(context);
}
function nameFlag(filter) ({
names: ["-name", "-n"],
description: "The name of this stylesheet",
type: modules.CommandOption.STRING,
completer: function (context, args) {
context.keys.text = function (sheet) sheet.name;
context.filters.push(function ({ item }) item.name);
sheets(context, args, filter);
}
});
commands.add(["sty[le]"], commands.add(["sty[le]"],
"Add or list user styles", "Add or list user styles",
function (args) { function (args) {
@@ -495,7 +537,7 @@ var Styles = Module("Styles", {
if (args.completeArg == 0) { if (args.completeArg == 0) {
if (sheet) if (sheet)
context.completions = [[sheet.sites.join(","), "Current Value"]]; context.completions = [[sheet.sites.join(","), "Current Value"]];
context.fork("sites", 0, Styles, "completeSite", window.content); context.fork("sites", 0, Styles, "completeSite", window.content, args["-group"]);
} }
else if (args.completeArg == 1) { else if (args.completeArg == 1) {
if (sheet) if (sheet)
@@ -509,12 +551,7 @@ var Styles = Module("Styles", {
{ names: ["-agent", "-A"], description: "Apply style as an Agent sheet" }, { names: ["-agent", "-A"], description: "Apply style as an Agent sheet" },
{ names: ["-append", "-a"], description: "Append site filter and css to an existing, matching sheet" }, { names: ["-append", "-a"], description: "Append site filter and css to an existing, matching sheet" },
contexts.GroupFlag("styles"), contexts.GroupFlag("styles"),
{ nameFlag()
names: ["-name", "-n"],
description: "The name of this stylesheet",
completer: function (context, args) [[k, v.css] for ([k, v] in Iterator(args["-group"].hive.names))],
type: modules.CommandOption.STRING
}
], ],
serialize: function () [ serialize: function () [
{ {
@@ -551,64 +588,30 @@ var Styles = Module("Styles", {
action: function (sheet) sheet.remove() action: function (sheet) sheet.remove()
} }
].forEach(function (cmd) { ].forEach(function (cmd) {
function splitContext(context, generate) {
for (let item in Iterator({ Active: true, Inactive: false })) {
let [name, active] = item;
context.split(name, null, function (context) {
context.title[0] = name + " Sheets";
context.filters.push(function (item) item.active == active);
});
}
}
function sheets(context) {
let uris = util.visibleURIs(window.content);
context.compare = modules.CompletionContext.Sort.number;
context.generate = function () styles.user.sheets;
context.keys.active = function (sheet) uris.some(sheet.closure.match);
context.keys.description = function (sheet) <>{sheet.formatSites(uris)}: {sheet.css.replace("\n", "\\n")}</>
if (cmd.filter)
context.filters.push(function ({ item }) cmd.filter(item));
splitContext(context);
}
commands.add(cmd.name, cmd.desc, commands.add(cmd.name, cmd.desc,
function (args) { function (args) {
styles.user.find(args["-name"], args[0], args.literalArg, args["-index"]) args["-group"].find(args["-name"], args[0], args.literalArg, args["-index"])
.forEach(cmd.action); .forEach(cmd.action);
}, { }, {
completer: function (context) { completer: function (context, args) {
let uris = util.visibleURIs(window.content); let uris = util.visibleURIs(window.content);
context.generate = function () styles.user.sites;
context.keys.text = util.identity;
context.keys.description = function (site) this.sheets.length + " sheet" + (this.sheets.length == 1 ? "" : "s") + ": " +
array.compact(this.sheets.map(function (s) s.name)).join(", ");
context.keys.sheets = function (site) styles.user.sheets.filter(function (s) s.sites.indexOf(site) >= 0);
context.keys.active = function (site) uris.some(Styles.matchFilter(site));
if (cmd.filter) if (cmd.filter)
context.filters.push(function ({ sheets }) sheets.some(cmd.filter)); context.filters.push(function ({ sheets }) sheets.some(cmd.filter));
Styles.completeSite(context, window.content, args["-group"]);
splitContext(context);
}, },
literal: 1, literal: 1,
options: [ options: [
contexts.GroupFlag("styles"),
{ {
names: ["-index", "-i"], names: ["-index", "-i"],
type: modules.CommandOption.INT, type: modules.CommandOption.INT,
completer: function (context) { completer: function (context, args) {
context.keys.text = function (sheet) styles.user.sheets.indexOf(sheet); context.keys.text = function (sheet) args["-group"].sheets.indexOf(sheet);
sheets(context); sheets(context, args, cmd.filter);
},
}, {
names: ["-name", "-n"],
type: modules.CommandOption.STRING,
completer: function (context) {
context.keys.text = function (sheet) sheet.name;
context.filters.push(function ({ item }) item.name);
sheets(context);
} }
} },
nameFlag(cmd.filter)
] ]
}); });
}); });
@@ -625,6 +628,7 @@ var Styles = Module("Styles", {
get names() this.hive.names, get names() this.hive.names,
get sheets() this.hive.sheets, get sheets() this.hive.sheets,
get sites() this.hive.sites,
__noSuchMethod__: function __noSuchMethod__(meth, args) { __noSuchMethod__: function __noSuchMethod__(meth, args) {
return this.hive[meth].apply(this.hive, args); return this.hive[meth].apply(this.hive, args);