1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 02:07:58 +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
*/
const AutoCommands = Module("autocommands", {
requires: ["config"],
init: function () {
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
const Bookmarks = Module("bookmarks", {
requires: ["autocommands", "liberator", "storage", "services"],
requires: ["autocommands", "config", "liberator", "storage", "services"],
init: function () {
const faviconService = services.get("favicon");

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,10 @@
const ModuleBase = Class("ModuleBase", { requires: [] });
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.requires = inst.requires || [];
Module.list.push(module);
@@ -12,7 +15,7 @@ Module.list = [];
Module.constructors = {};
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 deferredInit = { load: [] };
const seen = set();

View File

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

View File

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

View File

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

View File

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

View File

@@ -3,7 +3,12 @@
// This work is licensed for reuse under an MIT license. Details are
// 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 ***/
name: "Muttator",
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"] : [
"addressbook.js",
"mail.js",
"tabs.js",
],
// to allow Vim to :set ft=mail automatically
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"],
"Show " + config.hostApplication + " preferences",
function () { window.openOptionsDialog(); },
{ argCount: "0" });
},
optons: function () {
// FIXME: comment obviously incorrect
// 0: never automatically edit externally
// 1: automatically edit externally when message window is shown the first time
@@ -179,9 +185,7 @@ const config = { //{{{
},
getter: function () MailOfflineMgr.isOnline()
});
//}}}
}
}; //}}}
},
})
// vim: set fdm=marker sw=4 ts=4 et:

View File

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

View File

@@ -3,8 +3,10 @@
// This work is licensed for reuse under an MIT license. Details are
// 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 ***/
name: "Vimperator",
hostApplication: "Firefox",
@@ -97,15 +99,7 @@ const config = { //{{{
hasTabbrowser: true,
get 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
};
},
ignoreKeys: {},
scripts: [
"browser.js",
@@ -126,8 +120,9 @@ const config = { //{{{
return prefix + ".tmp";
},
init: function () {
}, {
}, {
commands: function () {
commands.add(["winon[ly]"],
"Close all other windows",
function () {
@@ -227,28 +222,8 @@ const config = { //{{{
literal: 0,
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
});
/////////////////////////////////////////////////////////////////////////////}}}
////////////////////// COMPLETIONS /////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
},
completion: function () {
var searchRunning = false; // only until Firefox fixes https://bugzilla.mozilla.org/show_bug.cgi?id=510589
completion.location = function location(context) {
if (!services.get("autoCompleteSearch"))
@@ -292,9 +267,29 @@ const config = { //{{{
completion.addUrlCompleter("l",
"Firefox location bar entries (bookmarks and history sorted in an intelligent way)",
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:

View File

@@ -6,7 +6,18 @@
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 ***/
name: "Xulmus",
hostApplication: "Songbird",
@@ -158,98 +169,69 @@ const config = { //{{{
stop: function (tab) {
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
incrementURL: function (count) {
let matches = buffer.URL.match(/(.*?)(\d+)(\D*)$/);
if (!matches)
return void liberator.beep();
// TODO: support 'nrformats'? -> probably not worth it --mst
function incrementURL(count) {
let matches = buffer.URL.match(/(.*?)(\d+)(\D*)$/);
if (!matches)
return void liberator.beep();
let [, pre, number, post] = matches;
let newNumber = parseInt(number, 10) + count;
let newNumberStr = String(newNumber > 0 ? newNumber : 0);
if (number.match(/^0/)) { // add 0009<C-a> should become 0010
while (newNumberStr.length < number.length)
newNumberStr = "0" + newNumberStr;
}
liberator.open(pre + newNumberStr + post);
let [, pre, number, post] = matches;
let newNumber = parseInt(number, 10) + count;
let newNumberStr = String(newNumber > 0 ? newNumber : 0);
if (number.match(/^0/)) { // add 0009<C-a> should become 0010
while (newNumberStr.length < number.length)
newNumberStr = "0" + newNumberStr;
}
function showServicePane(value) {
const key = "splitter.servicepane_splitter.was_collapsed";
gServicePane.open = value;
SBDataSetBoolValue(key, gServicePane.open);
liberator.open(pre + newNumberStr + post);
},
showServicePane: function (value) {
const key = "splitter.servicepane_splitter.was_collapsed";
gServicePane.open = value;
SBDataSetBoolValue(key, gServicePane.open);
},
openDisplayPane: function (id) {
if (id == "servicepane")
this.showServicePane(true);
else {
let pane = document.getElementById(id);
let manager = Cc['@songbirdnest.com/Songbird/DisplayPane/Manager;1'].getService(Ci.sbIDisplayPaneManager);
let paneinfo = manager.getPaneInfo(pane._lastURL.stringValue);
if (!paneinfo)
paneinfo = manager.defaultPaneInfo;
pane.loadContent(paneinfo);
}
},
function openDisplayPane(id) {
if (id == "servicepane")
showServicePane(true);
else {
let pane = document.getElementById(id);
let manager = Cc['@songbirdnest.com/Songbird/DisplayPane/Manager;1'].getService(Ci.sbIDisplayPaneManager);
let paneinfo = manager.getPaneInfo(pane._lastURL.stringValue);
if (!paneinfo)
paneinfo = manager.defaultPaneInfo;
pane.loadContent(paneinfo);
}
}
function closeDisplayPane(id) {
if (id == "servicepane")
showServicePane(false);
else
document.getElementById(id).hide();
}
// FIXME: best way to format these args? Hyphenated? One word like :dialog?
let displayPanes = {
"service pane left": "servicepane",
"content pane bottom": "displaypane_contentpane_bottom",
"service pane bottom": "displaypane_servicepane_bottom",
"right sidebar": "displaypane_right_sidebar"
};
completion.displayPane = function (context) {
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 ////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
closeDisplayPane: function (id) {
if (id == "servicepane")
this.showServicePane(false);
else
document.getElementById(id).hide();
},
// FIXME: best way to format these args? Hyphenated? One word like :dialog?
displayPanes: {
"service pane left": "servicepane",
"content pane bottom": "displaypane_contentpane_bottom",
"service pane bottom": "displaypane_servicepane_bottom",
"right sidebar": "displaypane_right_sidebar"
}
}, {
commands: function () {
commands.add(["dpcl[ose]"],
"Close a display pane",
function (args) {
let arg = args.literalArg;
if (arg in displayPanes)
closeDisplayPane(displayPanes[arg]);
if (arg in Config.displayPanes)
Config.closeDisplayPane(Config.displayPanes[arg]);
else
liberator.echoerr("E475: Invalid argument: " + arg);
@@ -266,8 +248,8 @@ const config = { //{{{
function (args) {
let arg = args.literalArg;
if (arg in displayPanes)
openDisplayPane(displayPanes[arg]);
if (arg in Config.displayPanes)
Config.openDisplayPane(Config.displayPanes[arg]);
// TODO: focus when we have better key handling of these extended modes
else
liberator.echoerr("E475: Invalid argument: " + arg);
@@ -293,11 +275,14 @@ const config = { //{{{
argCount: "0",
bang: true
});
/////////////////////////////////////////////////////////////////////////////}}}
////////////////////// OPTIONS /////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
},
completion: function () {
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
options.add(["online"],
"Set the 'work offline' option",
@@ -311,23 +296,7 @@ const config = { //{{{
},
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:

View File

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