X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=common%2Fmodules%2Fstyles.jsm;h=c89c2812ef454217e315d0f1388ecb3068ce204d;hb=8b6fcae7eaa413bc62d645d2d0c99835c47265e6;hp=98d49605a4b4edeb7ad3dde0535d2c37994236aa;hpb=5ebd29f56d17f62011cdd596b1d351947ee534ff;p=dactyl.git diff --git a/common/modules/styles.jsm b/common/modules/styles.jsm index 98d4960..c89c281 100644 --- a/common/modules/styles.jsm +++ b/common/modules/styles.jsm @@ -1,19 +1,21 @@ -// Copyright (c) 2008-2011 by Kris Maglione +// Copyright (c) 2008-2012 Kris Maglione // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. -/* use strict */ +"use strict"; -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("styles", { exports: ["Style", "Styles", "styles"], require: ["services", "util"] -}, this); +}); + +lazyRequire("contexts", ["Contexts"]); +lazyRequire("template", ["template"]); function cssUri(css) "chrome-data:text/css," + encodeURI(css); -var namespace = "@namespace html " + XHTML.uri.quote() + ";\n" + - "@namespace xul " + XUL.uri.quote() + ";\n" + - "@namespace dactyl " + NS.uri.quote() + ";\n"; +var namespace = "@namespace html " + XHTML.quote() + ";\n" + + "@namespace xul " + XUL.quote() + ";\n" + + "@namespace dactyl " + NS.quote() + ";\n"; var Sheet = Struct("name", "id", "sites", "css", "hive", "agent"); Sheet.liveProperty = function (name) { @@ -34,8 +36,8 @@ Sheet.liveProperty("sites"); update(Sheet.prototype, { formatSites: function (uris) template.map(this.sites, - function (filter) {filter}, - <>,), + function (filter) ["span", { highlight: uris.some(Styles.matchFilter(filter)) ? "Filter" : "" }, filter], + ","), remove: function () { this.hive.remove(this); }, @@ -314,38 +316,34 @@ var Styles = Module("Styles", { let uris = util.visibleURIs(content); - let list = - - - - - - - - - - { - template.map(hives, function (hive) let (i = 0) - + - template.map(sheets(hive), function (sheet) - - - - - - - ) + - ) - } -
- - {_("title.Name")}{_("title.Filter")}{_("title.CSS")}
{!i++ ? hive.name : ""}{sheet.enabled ? "" : UTF8("×")}{sheet.name || hive.sheets.indexOf(sheet)}{sheet.formatSites(uris)}{sheet.css}
; - - // TODO: Move this to an ItemList to show this automatically - if (list.*.length() === list.text().length() + 5) - dactyl.echomsg(_("style.none")); - else - commandline.commandOutput(list); + let list = ["table", {}, + ["tr", { highlight: "Title" }, + ["td"], + ["td"], + ["td", { style: "padding-right: 1em;" }, _("title.Name")], + ["td", { style: "padding-right: 1em;" }, _("title.Filter")], + ["td", { style: "padding-right: 1em;" }, _("title.CSS")]], + ["col", { style: "min-width: 4em; padding-right: 1em;" }], + ["col", { style: "min-width: 1em; text-align: center; color: red; font-weight: bold;" }], + ["col", { style: "padding: 0 1em 0 1ex; vertical-align: top;" }], + ["col", { style: "padding: 0 1em 0 0; vertical-align: top;" }], + template.map(hives, function (hive) let (i = 0) [ + ["tr", { style: "height: .5ex;" }], + template.map(sheets(hive), function (sheet) + ["tr", {}, + ["td", { highlight: "Title" }, !i++ ? hive.name : ""], + ["td", {}, sheet.enabled ? "" : UTF8("×")], + ["td", {}, sheet.name || hive.sheets.indexOf(sheet)], + ["td", {}, sheet.formatSites(uris)], + ["td", {}, sheet.css]]), + ["tr", { style: "height: .5ex;" }]])]; + + // E4X-FIXME + // // TODO: Move this to an ItemList to show this automatically + // if (list.*.length() === list.text().length() + 5) + // dactyl.echomsg(_("style.none")); + // else + commandline.commandOutput(list); }, registerSheet: function registerSheet(url, agent, reload) { @@ -463,7 +461,7 @@ var Styles = Module("Styles", { } }, - propertyPattern: util.regexp( *) (?P [-a-z]*) @@ -485,14 +483,14 @@ var Styles = Module("Styles", { )? ) (?P * (?: ; | $) ) - ]]>, "gix", + */), "gix", { space: /(?: \s | \/\* .*? \*\/ )/, string: /(?:" (?:[^\\"]|\\.)* (?:"|$) | '(?:[^\\']|\\.)* (?:'|$) )/ }), patterns: memoize({ - get property() util.regexp( *) (?P [-a-z]*) @@ -503,26 +501,26 @@ var Styles = Module("Styles", { )? ) (?P * (?: ; | $) ) - ]]>, "gix", this), + */), "gix", this), - get function() util.regexp( \s* \( \s* (?: | [^)]* ) \s* (?: \) | $) ) - ]]>, "gx", this), + */), "gx", this), space: /(?: \s | \/\* .*? \*\/ )/, - get string() util.regexp( " (?:[^\\"]|\\.)* (?:"|$) | ' (?:[^\\']|\\.)* (?:'|$) ) - ]]>, "gx", this), + */), "gx", this), - get token() util.regexp( (?P [-\w]+) ? @@ -532,7 +530,7 @@ var Styles = Module("Styles", { | + | [^;}\s]+ ) - ]]>, "gix", this) + */), "gix", this) }), /** @@ -545,7 +543,7 @@ var Styles = Module("Styles", { return '"' + str.replace(/([\\"])/g, "\\$1").replace(/\n/g, "\\00000a") + '"'; }, }, { - commands: function (dactyl, modules, window) { + commands: function initCommands(dactyl, modules, window) { const { commands, contexts, styles } = modules; function sheets(context, args, filter) { @@ -553,7 +551,7 @@ var Styles = Module("Styles", { 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")} + 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); @@ -694,7 +692,7 @@ var Styles = Module("Styles", { }); }); }, - contexts: function (dactyl, modules, window) { + contexts: function initContexts(dactyl, modules, window) { modules.contexts.Hives("styles", Class("LocalHive", Contexts.Hive, { init: function init(group) { @@ -715,8 +713,8 @@ var Styles = Module("Styles", { } })); }, - completion: function (dactyl, modules, window) { - const names = Array.slice(DOM(
, window.document).style); + completion: function initCompletion(dactyl, modules, window) { + const names = Array.slice(DOM(["div"], window.document).style); modules.completion.css = function (context) { context.title = ["CSS Property"]; context.keys = { text: function (p) p + ":", description: function () "" }; @@ -730,7 +728,7 @@ var Styles = Module("Styles", { } }; }, - javascript: function (dactyl, modules, window) { + javascript: function initJavascript(dactyl, modules, window) { modules.JavaScript.setCompleter(["get", "add", "remove", "find"].map(function (m) Hive.prototype[m]), [ // Prototype: (name, filter, css, index) function (context, obj, args) this.names, @@ -739,35 +737,36 @@ var Styles = Module("Styles", { function (context, obj, args) this.sheets ]); }, - template: function () { + template: function initTemplate() { let patterns = Styles.patterns; template.highlightCSS = function highlightCSS(css) { - XML.prettyPrinting = XML.ignoreWhitespace = false; - return this.highlightRegexp(css, patterns.property, function (match) { if (!match.length) - return <>; - return <>{match.preSpace}{template.filter(match.name)}: { + return []; + return ["", match.preSpace, template.filter(match.name), ": ", template.highlightRegexp(match.value, patterns.token, function (match) { if (match.function) - return <>{template.filter(match.word)}{ + return ["", template.filter(match.word), template.highlightRegexp(match.function, patterns.string, - function (match) {match.string}) - }; + function (match) ["span", { highlight: "String" }, match.string]) + ]; if (match.important == "!important") - return {match.important}; + return ["span", { highlight: "String" }, match.important]; if (match.string) - return {match.string}; - return template.highlightRegexp(match.wholeMatch, /^(\d+)(em|ex|px|in|cm|mm|pt|pc)?/g, - function (m, n, u) <>{n}{u || ""}); - }) - - }{ match.postSpace } + return ["span", { highlight: "String" }, match.string]; + return template._highlightRegexp(match.wholeMatch, /^(\d+)(em|ex|px|in|cm|mm|pt|pc)?/g, + function (m, n, u) [ + ["span", { highlight: "Number" }, n], + ["span", { highlight: "Object" }, u || ""] + ]); + }), + match.postSpace + ] }) } - }, + } }); endModule();