1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 08:07:59 +01:00

Refactor modules.config.

This commit is contained in:
Kris Maglione
2009-11-09 03:12:27 -05:00
parent 4d88ccb036
commit a72068c9f7
26 changed files with 160 additions and 175 deletions

View File

@@ -12,6 +12,8 @@ const AutoCommand = new Struct("event", "pattern", "command");
* @instance autocommands * @instance autocommands
*/ */
const AutoCommands = Module("autocommands", { const AutoCommands = Module("autocommands", {
requires: ["config"],
init: function () { init: function () {
this._store = []; this._store = [];
}, },

View File

@@ -8,7 +8,7 @@ const DEFAULT_FAVICON = "chrome://mozapps/skin/places/defaultFavicon.png";
// also includes methods for dealing with keywords and search engines // also includes methods for dealing with keywords and search engines
const Bookmarks = Module("bookmarks", { const Bookmarks = Module("bookmarks", {
requires: ["autocommands", "liberator", "storage", "services"], requires: ["autocommands", "config", "liberator", "storage", "services"],
init: function () { init: function () {
const faviconService = services.get("favicon"); const faviconService = services.get("favicon");

View File

@@ -15,6 +15,8 @@ const Point = new Struct("x", "y");
* @instance buffer * @instance buffer
*/ */
const Buffer = Module("buffer", { const Buffer = Module("buffer", {
requires: ["config"],
init: function () { init: function () {
this.pageInfo = {}; this.pageInfo = {};

View File

@@ -12,7 +12,7 @@
* this class when the chrome is ready. * this class when the chrome is ready.
*/ */
const CommandLine = Module("commandline", { const CommandLine = Module("commandline", {
requires: ["liberator", "modes", "services", "storage", "template", "util"], requires: ["config", "liberator", "modes", "services", "storage", "template", "util"],
init: function () { init: function () {
const self = this; const self = this;

View File

@@ -33,6 +33,8 @@
* @private * @private
*/ */
const Command = Class("Command", { const Command = Class("Command", {
requires: ["config"],
init: function (specs, description, action, extraInfo) { init: function (specs, description, action, extraInfo) {
specs = Array.concat(specs); specs = Array.concat(specs);

View File

@@ -3,8 +3,7 @@
// This work is licensed for reuse under an MIT license. Details are // This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file. // given in the LICENSE.txt file included with this file.
const ConfigBase = Class(ModuleBase, {
const configbase = { //{{{
/** /**
* @property {[["string", "string"]]} A sequence of names and descriptions * @property {[["string", "string"]]} A sequence of names and descriptions
* of the autocommands available in this application. Primarily used * of the autocommands available in this application. Primarily used
@@ -99,6 +98,6 @@ const configbase = { //{{{
*/ */
get tempFile() this.name.toLowerCase() + ".tmp" get tempFile() this.name.toLowerCase() + ".tmp"
}; //}}} });
// vim: set fdm=marker sw=4 ts=4 et: // vim: set fdm=marker sw=4 ts=4 et:

View File

@@ -11,6 +11,8 @@
/** @instance editor */ /** @instance editor */
const Editor = Module("editor", { const Editor = Module("editor", {
requires: ["config"],
init: function () { init: function () {
// store our last search with f, F, t or T // store our last search with f, F, t or T
// //

View File

@@ -10,7 +10,7 @@
* @instance events * @instance events
*/ */
const Events = Module("events", { const Events = Module("events", {
requires: ["autocommands"], requires: ["autocommands", "config"],
init: function () { init: function () {
const self = this; const self = this;

View File

@@ -20,6 +20,8 @@
* @instance finder * @instance finder
*/ */
const Finder = Module("finder", { const Finder = Module("finder", {
requires: ["config"],
init: function () { init: function () {
const self = this; const self = this;

View File

@@ -8,6 +8,8 @@
/** @instance hints */ /** @instance hints */
const ELEM = 0, TEXT = 1, SPAN = 2, IMG_SPAN = 3; const ELEM = 0, TEXT = 1, SPAN = 2, IMG_SPAN = 3;
const Hints = Module("hints", { const Hints = Module("hints", {
requires: ["config"],
init: function () { init: function () {
this._hintMode; this._hintMode;

View File

@@ -4,6 +4,8 @@
// given in the LICENSE.txt file included with this file. // given in the LICENSE.txt file included with this file.
const History = Module("history", { const History = Module("history", {
requires: ["config"],
get format() bookmarks.format, get format() bookmarks.format,
get service() services.get("history"), get service() services.get("history"),

View File

@@ -267,7 +267,7 @@ const File = Class("File", {
* @instance io * @instance io
*/ */
const IO = Module("io", { const IO = Module("io", {
requires: ["services"], requires: ["config", "services"],
init: function () { init: function () {
this._processDir = services.get("directory").get("CurWorkD", Ci.nsIFile); this._processDir = services.get("directory").get("CurWorkD", Ci.nsIFile);

View File

@@ -37,8 +37,8 @@
"commandline.js", "commandline.js",
"commands.js", "commands.js",
"completion.js", "completion.js",
"config.js",
"configbase.js", "configbase.js",
"config.js",
"liberator.js", "liberator.js",
"editor.js", "editor.js",
"events.js", "events.js",
@@ -55,10 +55,9 @@
"template.js", "template.js",
"util.js", "util.js",
].forEach(load); ].forEach(load);
modules.config.__proto__ = modules.configbase;
prefix.unshift("chrome://" + modules.config.name.toLowerCase() + "/content/"); prefix.unshift("chrome://" + modules.Config.prototype.name.toLowerCase() + "/content/");
modules.config.scripts.forEach(load); modules.Config.prototype.scripts.forEach(load);
})(); })();

View File

@@ -38,7 +38,7 @@ const FailedAssertion = Class("FailedAssertion", Error, {
}); });
const Liberator = Module("liberator", { const Liberator = Module("liberator", {
requires: ["services"], requires: ["config", "services"],
init: function () { init: function () {
window.liberator = this; window.liberator = this;

View File

@@ -8,7 +8,7 @@
* @instance marks * @instance marks
*/ */
const Marks = Module("marks", { const Marks = Module("marks", {
requires: ["storage"], requires: ["config", "storage"],
init: function init() { init: function init() {
this._localMarks = storage.newMap("local-marks", { store: true, privateData: true }); this._localMarks = storage.newMap("local-marks", { store: true, privateData: true });

View File

@@ -6,7 +6,7 @@
/** @scope modules */ /** @scope modules */
const Modes = Module("modes", { const Modes = Module("modes", {
requires: ["util"], requires: ["config", "util"],
init: function () { init: function () {
this._main = 1; // NORMAL this._main = 1; // NORMAL

View File

@@ -1,7 +1,10 @@
const ModuleBase = Class("ModuleBase", { requires: [] }); const ModuleBase = Class("ModuleBase", { requires: [] });
function Module(name, inst, clas, moduleInit) { function Module(name, inst, clas, moduleInit) {
const module = Class(name, ModuleBase, inst, clas); var base = ModuleBase;
if (callable(inst))
base = Array.splice(arguments, 1, 1)[0]
const module = Class(name, base, inst, clas);
module.INIT = moduleInit || {}; module.INIT = moduleInit || {};
module.requires = inst.requires || []; module.requires = inst.requires || [];
Module.list.push(module); Module.list.push(module);
@@ -12,7 +15,7 @@ Module.list = [];
Module.constructors = {}; Module.constructors = {};
window.addEventListener("load", function () { window.addEventListener("load", function () {
function dump(str) window.dump(String.replace(str, /\n?$/, "\n").replace(/^/m, config.name.toLowerCase() + ": ")); function dump(str) window.dump(String.replace(str, /\n?$/, "\n").replace(/^/m, Config.prototype.name.toLowerCase() + ": "));
const start = Date.now(); const start = Date.now();
const deferredInit = { load: [] }; const deferredInit = { load: [] };
const seen = set(); const seen = set();

View File

@@ -401,7 +401,7 @@ const Option = Class("Option", {
* @instance options * @instance options
*/ */
const Options = Module("options", { const Options = Module("options", {
requires: ["highlight", "storage"], requires: ["config", "highlight", "storage"],
init: function () { init: function () {
for (let [, pref] in Iterator(this.allPrefs(Options.OLD_SAVED))) { for (let [, pref] in Iterator(this.allPrefs(Options.OLD_SAVED))) {

View File

@@ -9,7 +9,7 @@
* @instance quickmarks * @instance quickmarks
*/ */
const QuickMarks = Module("quickmarks", { const QuickMarks = Module("quickmarks", {
requires: ["storage"], requires: ["config", "storage"],
init: function () { init: function () {
this._qmarks = storage.newMap("quickmarks", { store: true }); this._qmarks = storage.newMap("quickmarks", { store: true });

View File

@@ -557,7 +557,7 @@ function Styles(name, store) {
} }
Module("styles", { Module("styles", {
requires: ["liberator", "storage", "util"], requires: ["config", "liberator", "storage", "util"],
init: function () { init: function () {
let (array = util.Array) { let (array = util.Array) {
@@ -707,7 +707,7 @@ Module("styles", {
}); });
Module("highlight", { Module("highlight", {
requires: ["styles"], requires: ["config", "styles"],
init: function () { init: function () {
const self = storage.newObject("highlight", Highlights, { store: false }); const self = storage.newObject("highlight", Highlights, { store: false });

View File

@@ -12,6 +12,8 @@
* @instance tabs * @instance tabs
*/ */
const Tabs = Module("tabs", { const Tabs = Module("tabs", {
requires: ["config"],
init: function () { init: function () {
this._alternates = [getBrowser().mCurrentTab, null]; this._alternates = [getBrowser().mCurrentTab, null];

View File

@@ -3,7 +3,12 @@
// This work is licensed for reuse under an MIT license. Details are // This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file. // given in the LICENSE.txt file included with this file.
const config = { //{{{ const config = Module("config", ConfigBase, {
init: function () {
// don't wait too long when selecting new messages
// GetThreadTree()._selectDelay = 300; // TODO: make configurable
},
/*** required options, no checks done if they really exist, so be careful ***/ /*** required options, no checks done if they really exist, so be careful ***/
name: "Muttator", name: "Muttator",
hostApplication: "Thunderbird", // TODO: can this be found out otherwise? gBrandBundle.getString("brandShortName"); hostApplication: "Thunderbird", // TODO: can this be found out otherwise? gBrandBundle.getString("brandShortName");
@@ -146,20 +151,21 @@ const config = { //{{{
get scripts() this.isComposeWindow() ? ["compose/compose.js"] : [ get scripts() this.isComposeWindow() ? ["compose/compose.js"] : [
"addressbook.js", "addressbook.js",
"mail.js", "mail.js",
"tabs.js",
], ],
// to allow Vim to :set ft=mail automatically // to allow Vim to :set ft=mail automatically
tempFile: "mutt-ator-mail", tempFile: "mutt-ator-mail",
init: function () { }, {
// don't wait too long when selecting new messages }, {
// GetThreadTree()._selectDelay = 300; // TODO: make configurable commands: function () {
commands.add(["pref[erences]", "prefs"], commands.add(["pref[erences]", "prefs"],
"Show " + config.hostApplication + " preferences", "Show " + config.hostApplication + " preferences",
function () { window.openOptionsDialog(); }, function () { window.openOptionsDialog(); },
{ argCount: "0" }); { argCount: "0" });
},
optons: function () {
// FIXME: comment obviously incorrect // FIXME: comment obviously incorrect
// 0: never automatically edit externally // 0: never automatically edit externally
// 1: automatically edit externally when message window is shown the first time // 1: automatically edit externally when message window is shown the first time
@@ -179,9 +185,7 @@ const config = { //{{{
}, },
getter: function () MailOfflineMgr.isOnline() getter: function () MailOfflineMgr.isOnline()
}); });
},
//}}} })
}
}; //}}}
// vim: set fdm=marker sw=4 ts=4 et: // vim: set fdm=marker sw=4 ts=4 et:

View File

@@ -479,7 +479,7 @@ const Mail = Module("mail", {
bang: true, bang: true,
}); });
}, },
completions: function () { completion: function () {
completion.mailFolder = function mailFolder(context) { completion.mailFolder = function mailFolder(context) {
let folders = mail.getFolders(context.filter); let folders = mail.getFolders(context.filter);
context.anchored = false; context.anchored = false;

View File

@@ -3,8 +3,10 @@
// This work is licensed for reuse under an MIT license. Details are // This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file. // given in the LICENSE.txt file included with this file.
const Config = Module("config", ConfigBase, {
init: function () {
},
const config = { //{{{
/*** required options, no checks done if they really exist, so be careful ***/ /*** required options, no checks done if they really exist, so be careful ***/
name: "Vimperator", name: "Vimperator",
hostApplication: "Firefox", hostApplication: "Firefox",
@@ -97,15 +99,7 @@ const config = { //{{{
hasTabbrowser: true, hasTabbrowser: true,
get ignoreKeys() { ignoreKeys: {},
delete this.ignoreKeys;
return this.ignoreKeys = {
"<Return>": modes.NORMAL | modes.INSERT,
"<Space>": modes.NORMAL | modes.INSERT,
"<Up>": modes.NORMAL | modes.INSERT,
"<Down>": modes.NORMAL | modes.INSERT
};
},
scripts: [ scripts: [
"browser.js", "browser.js",
@@ -126,8 +120,9 @@ const config = { //{{{
return prefix + ".tmp"; return prefix + ".tmp";
}, },
}, {
init: function () { }, {
commands: function () {
commands.add(["winon[ly]"], commands.add(["winon[ly]"],
"Close all other windows", "Close all other windows",
function () { function () {
@@ -227,28 +222,8 @@ const config = { //{{{
literal: 0, literal: 0,
privateData: true privateData: true
}); });
/////////////////////////////////////////////////////////////////////////////}}}
////////////////////// OPTIONS /////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
options.add(["online"],
"Set the 'work offline' option",
"boolean", true,
{
setter: function (value) {
const ioService = services.get("io");
if (ioService.offline == value)
BrowserOffline.toggleOfflineStatus();
return value;
}, },
getter: function () !services.get("io").offline completion: function () {
});
/////////////////////////////////////////////////////////////////////////////}}}
////////////////////// COMPLETIONS /////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
var searchRunning = false; // only until Firefox fixes https://bugzilla.mozilla.org/show_bug.cgi?id=510589 var searchRunning = false; // only until Firefox fixes https://bugzilla.mozilla.org/show_bug.cgi?id=510589
completion.location = function location(context) { completion.location = function location(context) {
if (!services.get("autoCompleteSearch")) if (!services.get("autoCompleteSearch"))
@@ -292,9 +267,29 @@ const config = { //{{{
completion.addUrlCompleter("l", completion.addUrlCompleter("l",
"Firefox location bar entries (bookmarks and history sorted in an intelligent way)", "Firefox location bar entries (bookmarks and history sorted in an intelligent way)",
completion.location); completion.location);
},
//}}} modes: function () {
} this.ignoreKeys = {
}; //}}} "<Return>": modes.NORMAL | modes.INSERT,
"<Space>": modes.NORMAL | modes.INSERT,
"<Up>": modes.NORMAL | modes.INSERT,
"<Down>": modes.NORMAL | modes.INSERT
};
},
options: function () {
options.add(["online"],
"Set the 'work offline' option",
"boolean", true,
{
setter: function (value) {
const ioService = services.get("io");
if (ioService.offline == value)
BrowserOffline.toggleOfflineStatus();
return value;
},
getter: function () !services.get("io").offline
});
},
});
// vim: set fdm=marker sw=4 ts=4 et: // vim: set fdm=marker sw=4 ts=4 et:

View File

@@ -6,7 +6,18 @@
Components.utils.import("resource://gre/modules/utils.js"); // XXX Components.utils.import("resource://gre/modules/utils.js"); // XXX
const config = { //{{{ const config = Module("config", {
init: function () {
// TODO: mention this to SB devs, they seem keen to provide these
// functions to make porting from FF as simple as possible.
window.toJavaScriptConsole = function () {
toOpenWindowByType("global:console", "chrome://global/content/console.xul");
};
window.BrowserStop = function () {
SBGetBrowser().mCurrentBrowser.stop();
};
},
/*** required options, no checks done if they really exist, so be careful ***/ /*** required options, no checks done if they really exist, so be careful ***/
name: "Xulmus", name: "Xulmus",
hostApplication: "Songbird", hostApplication: "Songbird",
@@ -158,13 +169,10 @@ const config = { //{{{
stop: function (tab) { stop: function (tab) {
SBGetBrowser().mCurrentBrowser.stop(); SBGetBrowser().mCurrentBrowser.stop();
}, },
}, {
init: function () {
// Adding a mode for Player
//modes.addMode("PLAYER"); // Player mode for songbird
// TODO: support 'nrformats'? -> probably not worth it --mst // TODO: support 'nrformats'? -> probably not worth it --mst
function incrementURL(count) { incrementURL: function (count) {
let matches = buffer.URL.match(/(.*?)(\d+)(\D*)$/); let matches = buffer.URL.match(/(.*?)(\d+)(\D*)$/);
if (!matches) if (!matches)
return void liberator.beep(); return void liberator.beep();
@@ -178,17 +186,17 @@ const config = { //{{{
} }
liberator.open(pre + newNumberStr + post); liberator.open(pre + newNumberStr + post);
} },
function showServicePane(value) { showServicePane: function (value) {
const key = "splitter.servicepane_splitter.was_collapsed"; const key = "splitter.servicepane_splitter.was_collapsed";
gServicePane.open = value; gServicePane.open = value;
SBDataSetBoolValue(key, gServicePane.open); SBDataSetBoolValue(key, gServicePane.open);
} },
function openDisplayPane(id) { openDisplayPane: function (id) {
if (id == "servicepane") if (id == "servicepane")
showServicePane(true); this.showServicePane(true);
else { else {
let pane = document.getElementById(id); let pane = document.getElementById(id);
let manager = Cc['@songbirdnest.com/Songbird/DisplayPane/Manager;1'].getService(Ci.sbIDisplayPaneManager); let manager = Cc['@songbirdnest.com/Songbird/DisplayPane/Manager;1'].getService(Ci.sbIDisplayPaneManager);
@@ -199,57 +207,31 @@ const config = { //{{{
pane.loadContent(paneinfo); pane.loadContent(paneinfo);
} }
} },
function closeDisplayPane(id) { closeDisplayPane: function (id) {
if (id == "servicepane") if (id == "servicepane")
showServicePane(false); this.showServicePane(false);
else else
document.getElementById(id).hide(); document.getElementById(id).hide();
} },
// FIXME: best way to format these args? Hyphenated? One word like :dialog? // FIXME: best way to format these args? Hyphenated? One word like :dialog?
let displayPanes = { displayPanes: {
"service pane left": "servicepane", "service pane left": "servicepane",
"content pane bottom": "displaypane_contentpane_bottom", "content pane bottom": "displaypane_contentpane_bottom",
"service pane bottom": "displaypane_servicepane_bottom", "service pane bottom": "displaypane_servicepane_bottom",
"right sidebar": "displaypane_right_sidebar" "right sidebar": "displaypane_right_sidebar"
}; }
}, {
completion.displayPane = function (context) { commands: function () {
context.title = ["Display Pane"];
context.completions = displayPanes; // FIXME: useful description etc
};
////////////////////////////////////////////////////////////////////////////////
////////////////////// STYLES //////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
let img = Image();
img.src = "chrome://xulmus/content/logo.png";
img.onload = function () {
styles.addSheet(true, "logo", "chrome://liberator/locale/*",
".xulmus-logo {" + <>
display: inline-block;
background: url({img.src});
width: {img.width}px;
height: {img.height}px;
</> + "}",
true);
delete img;
};
/////////////////////////////////////////////////////////////////////////////}}}
////////////////////// COMMANDS ////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
commands.add(["dpcl[ose]"], commands.add(["dpcl[ose]"],
"Close a display pane", "Close a display pane",
function (args) { function (args) {
let arg = args.literalArg; let arg = args.literalArg;
if (arg in displayPanes) if (arg in Config.displayPanes)
closeDisplayPane(displayPanes[arg]); Config.closeDisplayPane(Config.displayPanes[arg]);
else else
liberator.echoerr("E475: Invalid argument: " + arg); liberator.echoerr("E475: Invalid argument: " + arg);
@@ -266,8 +248,8 @@ const config = { //{{{
function (args) { function (args) {
let arg = args.literalArg; let arg = args.literalArg;
if (arg in displayPanes) if (arg in Config.displayPanes)
openDisplayPane(displayPanes[arg]); Config.openDisplayPane(Config.displayPanes[arg]);
// TODO: focus when we have better key handling of these extended modes // TODO: focus when we have better key handling of these extended modes
else else
liberator.echoerr("E475: Invalid argument: " + arg); liberator.echoerr("E475: Invalid argument: " + arg);
@@ -293,11 +275,14 @@ const config = { //{{{
argCount: "0", argCount: "0",
bang: true bang: true
}); });
},
/////////////////////////////////////////////////////////////////////////////}}} completion: function () {
////////////////////// OPTIONS ///////////////////////////////////////////////// completion.displayPane = function (context) {
/////////////////////////////////////////////////////////////////////////////{{{ context.title = ["Display Pane"];
context.completions = Config.displayPanes; // FIXME: useful description etc
};
},
options: function () {
// TODO: SB doesn't explicitly support an offline mode. Should we? --djk // TODO: SB doesn't explicitly support an offline mode. Should we? --djk
options.add(["online"], options.add(["online"],
"Set the 'work offline' option", "Set the 'work offline' option",
@@ -311,23 +296,7 @@ const config = { //{{{
}, },
getter: function () !services.get("io").offline getter: function () !services.get("io").offline
}); });
/////////////////////////////////////////////////////////////////////////////}}}
////////////////////// COMPLETIONS /////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
//}}}
// TODO: mention this to SB devs, they seem keen to provide these
// functions to make porting from FF as simple as possible.
window.toJavaScriptConsole = function () {
toOpenWindowByType("global:console", "chrome://global/content/console.xul");
};
window.BrowserStop = function () {
SBGetBrowser().mCurrentBrowser.stop();
};
} }
}; //}}} });
// vim: set fdm=marker sw=4 ts=4 et: // vim: set fdm=marker sw=4 ts=4 et:

View File

@@ -560,7 +560,7 @@ const Player = Module("player", {
}, },
{ argCount: "1" }); { argCount: "1" });
}, },
completions: function () { completion: function () {
completion.song = function song(context, args) { completion.song = function song(context, args) {
// TODO: useful descriptions? // TODO: useful descriptions?
function map(list) list.map(function (i) [i, ""]); function map(list) list.map(function (i) [i, ""]);