1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-10 07:34:11 +01:00

Use current group to select :style hive. Clear previous colorscheme's styles on :colo.

--HG--
branch : groups
This commit is contained in:
Kris Maglione
2011-02-05 07:30:46 -05:00
parent 5429db5c53
commit 6ee586087a
5 changed files with 53 additions and 29 deletions

View File

@@ -76,11 +76,11 @@ var Contexts = Module("contexts", {
context: null,
groups: Class.memoize(function () Object.create(Group.groupsProto, {
groups: { value: this.groupList.filter(function (g) g.filter(buffer.uri)) }
groups: { value: this.activeGroups().filter(function (g) g.filter(buffer.uri)) }
})),
allGroups: Class.memoize(function () Object.create(Group.groupsProto, {
groups: { value: this.groupList }
groups: { value: this.activeGroups() }
})),
activeGroups: function (subgroup)
@@ -174,7 +174,19 @@ var Contexts = Module("contexts", {
action.toString = function toString() (type === default_ ? "" : type + " ") + rhs;
args = null;
return action;
}
},
GroupFlag: function (name) ({
names: ["-group", "-g"],
description: "Group to which to add",
type: ArgType("group", function (group) isString(group) ? contexts.getGroup(group, name) : group[name]),
get default() (contexts.context && contexts.context.group || contexts.user)[name],
completer: function (context) completion.group(context)
})
}, {
Context: modules.Script = function Context(file, group, args) {
function Const(val) Class.Property({ enumerable: true, value: val });

View File

@@ -508,7 +508,7 @@ var Mappings = Module("mappings", {
names: ["-ex", "-e"],
description: "Execute this mapping as an Ex command rather than keys"
},
groupFlag,
contexts.GroupFlag("mappings"),
{
names: ["-javascript", "-js", "-j"],
description: "Execute this mapping as JavaScript rather than keys"
@@ -587,7 +587,7 @@ var Mappings = Module("mappings", {
{
argCount: "0",
options: [
groupFlag,
contexts.GroupFlag("mappings"),
update({}, modeFlag, {
names: ["-modes", "-mode", "-m"],
type: CommandOption.LIST,
@@ -616,7 +616,7 @@ var Mappings = Module("mappings", {
argCount: "1",
completer: opts.completer,
options: [
groupFlag,
contexts.GroupFlag("mappings"),
update({}, modeFlag, {
names: ["-modes", "-mode", "-m"],
type: CommandOption.LIST,
@@ -627,13 +627,6 @@ var Mappings = Module("mappings", {
});
}
let groupFlag = {
names: ["-group", "-g"],
description: "Mapping group to which to add this mapping",
type: ArgType("map-group", function (group) isString(group) ? contexts.getGroup(group, "mappings") : group),
get default() (contexts.context && contexts.context.group || contexts.user).mappings,
completer: function (context) completion.group(context)
};
let modeFlag = {
names: ["-mode", "-m"],
type: CommandOption.STRING,

View File

@@ -291,16 +291,21 @@ var Highlights = Module("Highlight", {
}, {
commands: function (dactyl, modules) {
const { autocommands, commands, completion, CommandOption, config, io } = modules;
let lastScheme;
commands.add(["colo[rscheme]"],
"Load a color scheme",
function (args) {
let scheme = args[0];
if (lastScheme)
lastScheme.unload();
if (scheme == "default")
highlight.clear();
else
dactyl.assert(modules.io.sourceFromRuntimePath(["colors/" + scheme + "." + config.fileExtension]),
"E185: Cannot find color scheme " + scheme);
else {
lastScheme = modules.io.sourceFromRuntimePath(["colors/" + scheme + "." + config.fileExtension]);
dactyl.assert(lastScheme, "E185: Cannot find color scheme " + scheme);
}
autocommands.trigger("ColorScheme", { name: scheme });
},
{

View File

@@ -113,7 +113,7 @@ var IO = Module("io", {
*/
sourceFromRuntimePath: function sourceFromRuntimePath(paths, all) {
let dirs = modules.options.get("runtimepath").files;
let found = false;
let found = null;
dactyl.echomsg("Searching for " + paths.join(" ").quote() + " in " + modules.options.get("runtimepath").stringValue, 2);
@@ -125,8 +125,7 @@ var IO = Module("io", {
dactyl.echomsg("Searching for " + file.path.quote(), 3);
if (file.exists() && file.isFile() && file.isReadable()) {
io.source(file.path, false);
found = true;
found = io.source(file.path, false) || true;
if (!all)
break outer;

View File

@@ -229,8 +229,8 @@ try {
var Styles = Module("Styles", {
init: function () {
this._id = 0;
this.user = Hive("user");
this.system = Hive("system");
this.hives = [];
this.cleanup();
this.allSheets = {};
services["dactyl:"].providers["style"] = function styleProvider(uri) {
@@ -242,8 +242,19 @@ var Styles = Module("Styles", {
},
cleanup: function cleanup() {
for each (let hive in [this.user, this.system])
for each (let hive in this.hives)
hive.cleanup();
this.user = this.addHive("user");
this.system = this.addHive("system");
},
addHive: function addHive(name) {
let hive = array.nth(this.hives, function (h) h.name === name, 0);
if (!hive) {
hive = Hive(name);
this.hives.push(hive);
}
return hive;
},
__iterator__: function () Iterator(this.user.sheets.concat(this.system.sheets)),
@@ -425,7 +436,7 @@ var Styles = Module("Styles", {
})
}, {
commands: function (dactyl, modules, window) {
const commands = modules.commands;
const { commands, contexts } = modules;
commands.add(["sty[le]"],
"Add or list user styles",
@@ -434,17 +445,17 @@ var Styles = Module("Styles", {
if (css) {
if ("-append" in args) {
let sheet = styles.user.get(args["-name"]);
let sheet = args["-group"].get(args["-name"]);
if (sheet) {
filter = sheet.sites.concat(filter).join(",");
css = sheet.css + " " + css;
}
}
styles.user.add(args["-name"], filter, css, args["-agent"]);
args["-group"].add(args["-name"], filter, css, args["-agent"]);
}
else {
let list = styles.user.sheets.slice()
let list = args["-group"].sheets.slice()
.sort(function (a, b) a.name && b.name ? String.localeCompare(a.name, b.name)
: !!b.name - !!a.name || a.id - b.id);
let uris = util.visibleURIs(window.content);
@@ -455,7 +466,7 @@ var Styles = Module("Styles", {
"padding: 0 1em 0 1ex; vertical-align: top;",
"padding: 0 1em 0 0; vertical-align: top;"],
([sheet.enabled ? "" : UTF8("×"),
sheet.name || styles.user.sheets.indexOf(sheet),
sheet.name || args["-group"].sheets.indexOf(sheet),
sheet.formatSites(uris),
sheet.css]
for (sheet in values(list))
@@ -466,7 +477,7 @@ var Styles = Module("Styles", {
bang: true,
completer: function (context, args) {
let compl = [];
let sheet = styles.user.get(args["-name"]);
let sheet = args["-group"].get(args["-name"]);
if (args.completeArg == 0) {
if (sheet)
context.completions = [[sheet.sites.join(","), "Current Value"]];
@@ -483,10 +494,11 @@ var Styles = Module("Styles", {
options: [
{ names: ["-agent", "-A"], description: "Apply style as an Agent sheet" },
{ names: ["-append", "-a"], description: "Append site filter and css to an existing, matching sheet" },
contexts.GroupFlag("styles"),
{
names: ["-name", "-n"],
description: "The name of this stylesheet",
completer: function () [[k, v.css] for ([k, v] in Iterator(styles.user.names))],
completer: function () [[k, v.css] for ([k, v] in Iterator(args["-group"].names))],
type: modules.CommandOption.STRING
}
],
@@ -587,6 +599,9 @@ var Styles = Module("Styles", {
});
});
},
contexts: function (dactyl, modules, window) {
modules.Group.SubGroup("styles", function (group) styles.addHive(group.name));
},
completion: function (dactyl, modules, window) {
const names = Array.slice(util.computedStyle(window.document.createElement("div")));
modules.completion.css = function (context) {