mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-03-04 05:15:46 +01:00
Use current group to select :style hive. Clear previous colorscheme's styles on :colo.
--HG-- branch : groups
This commit is contained in:
@@ -76,11 +76,11 @@ var Contexts = Module("contexts", {
|
|||||||
context: null,
|
context: null,
|
||||||
|
|
||||||
groups: Class.memoize(function () Object.create(Group.groupsProto, {
|
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, {
|
allGroups: Class.memoize(function () Object.create(Group.groupsProto, {
|
||||||
groups: { value: this.groupList }
|
groups: { value: this.activeGroups() }
|
||||||
})),
|
})),
|
||||||
|
|
||||||
activeGroups: function (subgroup)
|
activeGroups: function (subgroup)
|
||||||
@@ -174,7 +174,19 @@ var Contexts = Module("contexts", {
|
|||||||
action.toString = function toString() (type === default_ ? "" : type + " ") + rhs;
|
action.toString = function toString() (type === default_ ? "" : type + " ") + rhs;
|
||||||
args = null;
|
args = null;
|
||||||
return action;
|
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) {
|
Context: modules.Script = function Context(file, group, args) {
|
||||||
function Const(val) Class.Property({ enumerable: true, value: val });
|
function Const(val) Class.Property({ enumerable: true, value: val });
|
||||||
|
|||||||
@@ -508,7 +508,7 @@ var Mappings = Module("mappings", {
|
|||||||
names: ["-ex", "-e"],
|
names: ["-ex", "-e"],
|
||||||
description: "Execute this mapping as an Ex command rather than keys"
|
description: "Execute this mapping as an Ex command rather than keys"
|
||||||
},
|
},
|
||||||
groupFlag,
|
contexts.GroupFlag("mappings"),
|
||||||
{
|
{
|
||||||
names: ["-javascript", "-js", "-j"],
|
names: ["-javascript", "-js", "-j"],
|
||||||
description: "Execute this mapping as JavaScript rather than keys"
|
description: "Execute this mapping as JavaScript rather than keys"
|
||||||
@@ -587,7 +587,7 @@ var Mappings = Module("mappings", {
|
|||||||
{
|
{
|
||||||
argCount: "0",
|
argCount: "0",
|
||||||
options: [
|
options: [
|
||||||
groupFlag,
|
contexts.GroupFlag("mappings"),
|
||||||
update({}, modeFlag, {
|
update({}, modeFlag, {
|
||||||
names: ["-modes", "-mode", "-m"],
|
names: ["-modes", "-mode", "-m"],
|
||||||
type: CommandOption.LIST,
|
type: CommandOption.LIST,
|
||||||
@@ -616,7 +616,7 @@ var Mappings = Module("mappings", {
|
|||||||
argCount: "1",
|
argCount: "1",
|
||||||
completer: opts.completer,
|
completer: opts.completer,
|
||||||
options: [
|
options: [
|
||||||
groupFlag,
|
contexts.GroupFlag("mappings"),
|
||||||
update({}, modeFlag, {
|
update({}, modeFlag, {
|
||||||
names: ["-modes", "-mode", "-m"],
|
names: ["-modes", "-mode", "-m"],
|
||||||
type: CommandOption.LIST,
|
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 = {
|
let modeFlag = {
|
||||||
names: ["-mode", "-m"],
|
names: ["-mode", "-m"],
|
||||||
type: CommandOption.STRING,
|
type: CommandOption.STRING,
|
||||||
|
|||||||
@@ -291,16 +291,21 @@ var Highlights = Module("Highlight", {
|
|||||||
}, {
|
}, {
|
||||||
commands: function (dactyl, modules) {
|
commands: function (dactyl, modules) {
|
||||||
const { autocommands, commands, completion, CommandOption, config, io } = modules;
|
const { autocommands, commands, completion, CommandOption, config, io } = modules;
|
||||||
|
|
||||||
|
let lastScheme;
|
||||||
commands.add(["colo[rscheme]"],
|
commands.add(["colo[rscheme]"],
|
||||||
"Load a color scheme",
|
"Load a color scheme",
|
||||||
function (args) {
|
function (args) {
|
||||||
let scheme = args[0];
|
let scheme = args[0];
|
||||||
|
if (lastScheme)
|
||||||
|
lastScheme.unload();
|
||||||
|
|
||||||
if (scheme == "default")
|
if (scheme == "default")
|
||||||
highlight.clear();
|
highlight.clear();
|
||||||
else
|
else {
|
||||||
dactyl.assert(modules.io.sourceFromRuntimePath(["colors/" + scheme + "." + config.fileExtension]),
|
lastScheme = modules.io.sourceFromRuntimePath(["colors/" + scheme + "." + config.fileExtension]);
|
||||||
"E185: Cannot find color scheme " + scheme);
|
dactyl.assert(lastScheme, "E185: Cannot find color scheme " + scheme);
|
||||||
|
}
|
||||||
autocommands.trigger("ColorScheme", { name: scheme });
|
autocommands.trigger("ColorScheme", { name: scheme });
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ var IO = Module("io", {
|
|||||||
*/
|
*/
|
||||||
sourceFromRuntimePath: function sourceFromRuntimePath(paths, all) {
|
sourceFromRuntimePath: function sourceFromRuntimePath(paths, all) {
|
||||||
let dirs = modules.options.get("runtimepath").files;
|
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);
|
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);
|
dactyl.echomsg("Searching for " + file.path.quote(), 3);
|
||||||
|
|
||||||
if (file.exists() && file.isFile() && file.isReadable()) {
|
if (file.exists() && file.isFile() && file.isReadable()) {
|
||||||
io.source(file.path, false);
|
found = io.source(file.path, false) || true;
|
||||||
found = true;
|
|
||||||
|
|
||||||
if (!all)
|
if (!all)
|
||||||
break outer;
|
break outer;
|
||||||
|
|||||||
@@ -229,8 +229,8 @@ try {
|
|||||||
var Styles = Module("Styles", {
|
var Styles = Module("Styles", {
|
||||||
init: function () {
|
init: function () {
|
||||||
this._id = 0;
|
this._id = 0;
|
||||||
this.user = Hive("user");
|
this.hives = [];
|
||||||
this.system = Hive("system");
|
this.cleanup();
|
||||||
this.allSheets = {};
|
this.allSheets = {};
|
||||||
|
|
||||||
services["dactyl:"].providers["style"] = function styleProvider(uri) {
|
services["dactyl:"].providers["style"] = function styleProvider(uri) {
|
||||||
@@ -242,8 +242,19 @@ var Styles = Module("Styles", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
cleanup: function cleanup() {
|
cleanup: function cleanup() {
|
||||||
for each (let hive in [this.user, this.system])
|
for each (let hive in this.hives)
|
||||||
hive.cleanup();
|
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)),
|
__iterator__: function () Iterator(this.user.sheets.concat(this.system.sheets)),
|
||||||
@@ -425,7 +436,7 @@ var Styles = Module("Styles", {
|
|||||||
})
|
})
|
||||||
}, {
|
}, {
|
||||||
commands: function (dactyl, modules, window) {
|
commands: function (dactyl, modules, window) {
|
||||||
const commands = modules.commands;
|
const { commands, contexts } = modules;
|
||||||
|
|
||||||
commands.add(["sty[le]"],
|
commands.add(["sty[le]"],
|
||||||
"Add or list user styles",
|
"Add or list user styles",
|
||||||
@@ -434,17 +445,17 @@ var Styles = Module("Styles", {
|
|||||||
|
|
||||||
if (css) {
|
if (css) {
|
||||||
if ("-append" in args) {
|
if ("-append" in args) {
|
||||||
let sheet = styles.user.get(args["-name"]);
|
let sheet = args["-group"].get(args["-name"]);
|
||||||
if (sheet) {
|
if (sheet) {
|
||||||
filter = sheet.sites.concat(filter).join(",");
|
filter = sheet.sites.concat(filter).join(",");
|
||||||
css = sheet.css + " " + css;
|
css = sheet.css + " " + css;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
styles.user.add(args["-name"], filter, css, args["-agent"]);
|
args["-group"].add(args["-name"], filter, css, args["-agent"]);
|
||||||
}
|
}
|
||||||
else {
|
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)
|
.sort(function (a, b) a.name && b.name ? String.localeCompare(a.name, b.name)
|
||||||
: !!b.name - !!a.name || a.id - b.id);
|
: !!b.name - !!a.name || a.id - b.id);
|
||||||
let uris = util.visibleURIs(window.content);
|
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 1ex; vertical-align: top;",
|
||||||
"padding: 0 1em 0 0; vertical-align: top;"],
|
"padding: 0 1em 0 0; vertical-align: top;"],
|
||||||
([sheet.enabled ? "" : UTF8("×"),
|
([sheet.enabled ? "" : UTF8("×"),
|
||||||
sheet.name || styles.user.sheets.indexOf(sheet),
|
sheet.name || args["-group"].sheets.indexOf(sheet),
|
||||||
sheet.formatSites(uris),
|
sheet.formatSites(uris),
|
||||||
sheet.css]
|
sheet.css]
|
||||||
for (sheet in values(list))
|
for (sheet in values(list))
|
||||||
@@ -466,7 +477,7 @@ var Styles = Module("Styles", {
|
|||||||
bang: true,
|
bang: true,
|
||||||
completer: function (context, args) {
|
completer: function (context, args) {
|
||||||
let compl = [];
|
let compl = [];
|
||||||
let sheet = styles.user.get(args["-name"]);
|
let sheet = args["-group"].get(args["-name"]);
|
||||||
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"]];
|
||||||
@@ -483,10 +494,11 @@ var Styles = Module("Styles", {
|
|||||||
options: [
|
options: [
|
||||||
{ 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"),
|
||||||
{
|
{
|
||||||
names: ["-name", "-n"],
|
names: ["-name", "-n"],
|
||||||
description: "The name of this stylesheet",
|
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
|
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) {
|
completion: function (dactyl, modules, window) {
|
||||||
const names = Array.slice(util.computedStyle(window.document.createElement("div")));
|
const names = Array.slice(util.computedStyle(window.document.createElement("div")));
|
||||||
modules.completion.css = function (context) {
|
modules.completion.css = function (context) {
|
||||||
|
|||||||
Reference in New Issue
Block a user