1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 05:57:58 +01:00

changed module loading and moved it to {vimperator,muttator}.js for

optional modules
This commit is contained in:
Martin Stubenschrott
2008-06-12 00:51:26 +00:00
parent 8589c22226
commit 29a387f870
12 changed files with 114 additions and 105 deletions

View File

@@ -239,7 +239,7 @@ liberator.Bookmarks = function () //{{{
} }
catch (e) catch (e)
{ {
liberator.log(e); liberator.log(e, 0);
return false; return false;
} }
@@ -306,7 +306,7 @@ liberator.Bookmarks = function () //{{{
} }
catch (e) catch (e)
{ {
liberator.log(e); liberator.log(e, 0);
return i; return i;
} }

View File

@@ -640,7 +640,7 @@ liberator.Buffer = function () //{{{
newWindow = true; newWindow = true;
break; break;
default: default:
liberator.log("Invalid where argument for followLink()"); liberator.log("Invalid where argument for followLink()", 0);
} }
elem.focus(); elem.focus();

View File

@@ -489,7 +489,7 @@ liberator.Commands = function () //{{{
if (exCommands[i].name == command.name) if (exCommands[i].name == command.name)
{ {
// never replace for now // never replace for now
liberator.log("Warning: :" + names[0] + " already exists, NOT replacing existing command.", 2); liberator.log("Warning: :" + names[0] + " already exists, NOT replacing existing command.", 1);
return false; return false;
} }
} }
@@ -635,9 +635,9 @@ liberator.Commands = function () //{{{
}); });
// TODO: remove preview window, or change it at least // TODO: remove preview window, or change it at least
commandManager.add(["pc[lose]"], // commandManager.add(["pc[lose]"],
"Close preview window on bottom of screen", // "Close preview window on bottom of screen",
function () { liberator.previewwindow.hide(); }); // function () { liberator.previewwindow.hide(); });
//}}} //}}}

View File

@@ -468,7 +468,6 @@ liberator.Events = function () //{{{
// TODO: move somehwere else, as focusing can already happen earlier than on "load" // TODO: move somehwere else, as focusing can already happen earlier than on "load"
if (liberator.options["focuscontent"]) if (liberator.options["focuscontent"])
{ {
liberator.log("focuscontent");
setTimeout(function () { setTimeout(function () {
var focused = document.commandDispatcher.focusedElement; var focused = document.commandDispatcher.focusedElement;
if (focused && (typeof focused.value != "undefined") && focused.value.length == 0) if (focused && (typeof focused.value != "undefined") && focused.value.length == 0)
@@ -537,12 +536,12 @@ liberator.Events = function () //{{{
var name = file.leafName.replace(/\.vimp$/i, ""); var name = file.leafName.replace(/\.vimp$/i, "");
macros[name] = liberator.io.readFile(file).split(/\n/)[0]; macros[name] = liberator.io.readFile(file).split(/\n/)[0];
liberator.log("Macro " + name + " added: " + macros[name], 8); liberator.log("Macro " + name + " added: " + macros[name], 5);
} }
} }
catch (e) catch (e)
{ {
liberator.log("macro directory not found or error reading macro file"); liberator.log("macro directory not found or error reading macro file", 9);
} }
}, 100); }, 100);
@@ -1118,7 +1117,7 @@ liberator.Events = function () //{{{
if (key == "q") // TODO: should not be hardcoded if (key == "q") // TODO: should not be hardcoded
{ {
liberator.modes.isRecording = false; liberator.modes.isRecording = false;
liberator.log("Recorded " + currentMacro + ": " + macros[currentMacro], 8); liberator.log("Recorded " + currentMacro + ": " + macros[currentMacro], 9);
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return true; return true;

View File

@@ -33,6 +33,12 @@ const liberator = (function () //{{{
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
var callbacks = []; var callbacks = [];
function loadModule(name, func)
{
liberator.log("Loading module " + name + "...", 0);
liberator[name] = func();
}
// Only general options are added here, which are valid for all vimperator like extensions // Only general options are added here, which are valid for all vimperator like extensions
function addOptions() function addOptions()
{ {
@@ -82,7 +88,7 @@ const liberator = (function () //{{{
} }
catch (e) catch (e)
{ {
liberator.log("Couldn't set titlestring", 1); liberator.log("Couldn't set titlestring", 3);
} }
}, },
}); });
@@ -201,8 +207,8 @@ const liberator = (function () //{{{
if (special) // open javascript console if (special) // open javascript console
{ {
liberator.open("chrome://global/content/console.xul", liberator.open("chrome://global/content/console.xul",
(liberator.options.newtab && (liberator.options["newtab"] &&
(liberator.options.newtab == "all" || liberator.options.newtab.split(",").indexOf("javascript") != -1)) ? (liberator.options["newtab"] == "all" || liberator.options["newtab"].split(",").indexOf("javascript") != -1)) ?
liberator.NEW_TAB : liberator.CURRENT_TAB); liberator.NEW_TAB : liberator.CURRENT_TAB);
} }
else else
@@ -228,7 +234,7 @@ const liberator = (function () //{{{
{ {
try try
{ {
eval("with(liberator){" + args + "}"); eval("with(liberator) {" + args + "}");
} }
catch (e) catch (e)
{ {
@@ -287,7 +293,7 @@ const liberator = (function () //{{{
else else
{ {
while (i--) while (i--)
eval("with(liberator){" + args + "}"); eval("with(liberator) {" + args + "}");
} }
if (special) if (special)
@@ -394,6 +400,7 @@ const liberator = (function () //{{{
{ {
var res = []; var res = [];
// they are sorted by relevance, not alphabetically // they are sorted by relevance, not alphabetically
// TODO: move files to liberator.config
var files = ["intro.html", "tutorial.html", "starting.html", "browsing.html", "buffer.html", var files = ["intro.html", "tutorial.html", "starting.html", "browsing.html", "buffer.html",
"options.html", "tabs.html", "marks.html", "repeat.html", "options.html", "tabs.html", "marks.html", "repeat.html",
"autocommands.html", "developer.html", "various.html"]; "autocommands.html", "developer.html", "various.html"];
@@ -472,6 +479,7 @@ const liberator = (function () //{{{
// "cancel" // "cancel"
// "complete" // "complete"
// TODO: "zoom": if the zoom value of the current buffer changed // TODO: "zoom": if the zoom value of the current buffer changed
// TODO: move to ui.js?
registerCallback: function (type, mode, func) registerCallback: function (type, mode, func)
{ {
// TODO: check if callback is already registered // TODO: check if callback is already registered
@@ -559,7 +567,6 @@ const liberator = (function () //{{{
if (window == ww.activeWindow && document.commandDispatcher.focusedElement && clearFocusedElement) if (window == ww.activeWindow && document.commandDispatcher.focusedElement && clearFocusedElement)
document.commandDispatcher.focusedElement.blur(); document.commandDispatcher.focusedElement.blur();
liberator.log("focusContent: " + clearFocusedElement);
// TODO: make more generic // TODO: make more generic
try try
{ {
@@ -580,6 +587,8 @@ const liberator = (function () //{{{
}, },
// partial sixth level expression evaluation // partial sixth level expression evaluation
// TODO: what is that really needed for, and where could it be used?
// Or should it be removed? (c) Viktor
eval: function (string) eval: function (string)
{ {
string = string.toString().replace(/^\s*/, "").replace(/\s*$/, ""); string = string.toString().replace(/^\s*/, "").replace(/\s*$/, "");
@@ -652,6 +661,10 @@ const liberator = (function () //{{{
} }
}, },
echo: function (str, flags) { liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, flags); },
echoerr: function (str, flags) { liberator.commandline.echo(str, liberator.commandline.HL_ERRORMSG, flags); },
// return true, if this VIM-like extension has a certain feature // return true, if this VIM-like extension has a certain feature
has: function (feature) has: function (feature)
{ {
@@ -661,8 +674,9 @@ const liberator = (function () //{{{
help: function (topic) help: function (topic)
{ {
var where = (liberator.options.newtab && (liberator.options.newtab == "all" || liberator.options.newtab.split(",").indexOf("help") != -1)) ? var where = (liberator.options["newtab"] && (liberator.options["newtab"] == "all" ||
liberator.NEW_TAB : liberator.CURRENT_TAB; liberator.options["newtab"].split(",").indexOf("help") != -1)) ?
liberator.NEW_TAB : liberator.CURRENT_TAB;
function jumpToTag(file, tag) function jumpToTag(file, tag)
{ {
@@ -704,11 +718,25 @@ const liberator = (function () //{{{
liberator.echoerr("E149: Sorry, no help for " + topic); liberator.echoerr("E149: Sorry, no help for " + topic);
}, },
globalVariables: { },
loadModule: function (name, func) { loadModule(name, func); },
// logs a message to the javascript error console // logs a message to the javascript error console
// if msg is an object, it is beautified // if msg is an object, it is beautified
log: function (msg, level) log: function (msg, level)
{ {
//if (liberator.options.getPref("verbose") >= level) // FIXME: hangs liberator, probably timing issue --mst var verbose = 0;
if (typeof level != "number")
level = 1;
// liberator.options does not exist at the very beginning
if (liberator.options)
verbose = liberator.options["verbose"];
dump("level: " + level + " - verbose: " + verbose + "\n");
if (level > verbose)
return;
if (typeof msg == "object") if (typeof msg == "object")
msg = liberator.util.objectToString(msg, false); msg = liberator.util.objectToString(msg, false);
@@ -791,6 +819,12 @@ const liberator = (function () //{{{
return true; return true;
}, },
// namespace for plugins/scripts. Actually (only) the active plugin must/can set a
// v.plugins.mode = <str> string to show on v.modes.CUSTOM
// v.plugins.stop = <func> hooked on a v.modes.reset()
// v.plugins.onEvent = <func> function triggered, on keypresses (unless <esc>) (see events.js)
plugins: { },
// quit liberator, no matter how many tabs/windows are open // quit liberator, no matter how many tabs/windows are open
quit: function (saveSession) quit: function (saveSession)
{ {
@@ -838,58 +872,32 @@ const liberator = (function () //{{{
.quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit); .quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
}, },
// TODO: move to {muttator,vimperator,...}.js // TODO: move to {muttator,vimperator,...}.js
// this function is called, when the chrome is ready // this function is called, when the chrome is ready
startup: function () startup: function ()
{ {
function log(module) { liberator.log("Loading module " + module + "...", 3); }; liberator.log("Initializing liberator object...", 0);
liberator.log("Initializing vimperator object...", 1);
// commands must always be the first module to be initialized // commands must always be the first module to be initialized
log("commands"); liberator.commands = liberator.Commands(); addCommands(); loadModule("commands", liberator.Commands); addCommands();
log("options"); liberator.options = liberator.Options(); addOptions(); loadModule("options", liberator.Options); addOptions();
log("mappings"); liberator.mappings = liberator.Mappings(); addMappings(); loadModule("mappings", liberator.Mappings); addMappings();
log("events"); liberator.events = liberator.Events(); loadModule("events", liberator.Events);
log("commandline"); liberator.commandline = liberator.CommandLine(); loadModule("commandline", liberator.CommandLine);
log("search"); liberator.search = liberator.Search(); loadModule("statusline", liberator.StatusLine);
log("preview window"); liberator.previewwindow = liberator.InformationList("liberator-previewwindow", { incrementalFill: false, maxItems: 10 }); loadModule("buffer", liberator.Buffer);
log("statusline"); liberator.statusline = liberator.StatusLine(); loadModule("editor", liberator.Editor);
log("buffer"); liberator.buffer = liberator.Buffer(); loadModule("autocommands", liberator.AutoCommands);
log("editor"); liberator.editor = liberator.Editor(); loadModule("io", liberator.IO);
log("autocommands"); liberator.autocommands = liberator.AutoCommands(); loadModule("completion", liberator.Completion);
log("io"); liberator.io = liberator.IO(); // loadModule("previewwindow" = liberator.InformationList("liberator-previewwindow", { incrementalFill: false, maxItems: 10 });
log("completion"); liberator.completion = liberator.Completion();
// optional modules
if (liberator.has("bookmarks")) { log("bookmarks"); liberator.bookmarks = liberator.Bookmarks(); }
if (liberator.has("history")) { log("history"); liberator.history = liberator.History(); }
if (liberator.has("mail") && liberator.Mail) { log("mail"); liberator.mail = liberator.Mail(); }
if (liberator.has("tabs") && liberator.Tabs) { log("tabs"); liberator.tabs = liberator.Tabs(); }
if (liberator.has("marks")) { log("marks"); liberator.marks = liberator.Marks(); }
if (liberator.has("quickmarks")) { log("quickmarks"); liberator.quickmarks = liberator.QuickMarks(); }
if (liberator.has("hints")) { log("hints"); liberator.hints = liberator.Hints(); }
if (liberator.has("addressbook") && liberator.Addressbook) { log("addressbook"); liberator.addressbook = liberator.Addressbook(); }
liberator.log("All modules loaded", 3);
// This adds options/mappings/commands which are only valid in this particular extension // This adds options/mappings/commands which are only valid in this particular extension
if (liberator.config.init) if (liberator.config.init)
{
liberator.config.init(); liberator.config.init();
// liberator.log("Loaded additional mappings, etc. for " + liberator.config.name, 3);
}
// we define some shortcuts to functions which are used often liberator.log("All modules loaded", 3);
liberator.echo = function (str, flags) { liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, flags); };
liberator.echoerr = function (str, flags) { liberator.commandline.echo(str, liberator.commandline.HL_ERRORMSG, flags); };
liberator.globalVariables = {};
// namespace for plugins/scripts. Actually (only) the active plugin must/can set a
// v.plugins.mode = <str> string to show on v.modes.CUSTOM
// v.plugins.stop = <func> hooked on a v.modes.reset()
// v.plugins.onEvent = <func> function triggered, on keypresses (unless <esc>) (see events.js)
liberator.plugins = {};
// TODO: move elsewhere // TODO: move elsewhere
liberator.registerCallback("submit", liberator.modes.EX, function (command) { liberator.execute(command); }); liberator.registerCallback("submit", liberator.modes.EX, function (command) { liberator.execute(command); });
@@ -958,7 +966,7 @@ const liberator = (function () //{{{
liberator.statusline.update(); liberator.statusline.update();
liberator.log(liberator.config.name + " fully initialized", 1); liberator.log(liberator.config.name + " fully initialized", 0);
}, },
shutdown: function () shutdown: function ()

View File

@@ -98,7 +98,7 @@ liberator.modes = (function () //{{{
function handleModeChange(oldMode, newMode) function handleModeChange(oldMode, newMode)
{ {
// TODO: fix v.log() to work with verbosity level // TODO: fix v.log() to work with verbosity level
liberator.log("switching from mode " + oldMode + " to mode " + newMode, 7); // liberator.log("switching from mode " + oldMode + " to mode " + newMode, 7);
// dump("switching from mode " + oldMode + " to mode " + newMode + "\n"); // dump("switching from mode " + oldMode + " to mode " + newMode + "\n");
switch (oldMode) switch (oldMode)

View File

@@ -129,24 +129,18 @@ liberator.config = {
// GetThreadTree()._selectDelay = 300; // TODO: make configurable // GetThreadTree()._selectDelay = 300; // TODO: make configurable
this.isComposeWindow = window.wintype == "msgcompose"; this.isComposeWindow = window.wintype == "msgcompose";
// load Muttator specific modules
if (this.isComposeWindow) if (this.isComposeWindow)
{ {
/*setTimeout(function () {
document.getElementById("content-frame").contentDocument.designMode = "off"; }
document.getElementById("content-frame").focus(); else
}, 500);*/ {
//document.getElementById("content-frame").contentWindow.addEventListener("load", function () { liberator.loadModule("mail", liberator.Mail);
/*window.addEventListener("load", function () { liberator.loadModule("addressbook", liberator.Addressbook);
alert("load"); liberator.loadModule("tabs", liberator.Tabs);
if (! liberator.editor.editWithExternalEditor()) liberator.loadModule("marks", liberator.Marks);
liberator.echoerr("Editing with external editor failed. Be sure to :set editor correctly"); liberator.loadModule("hints", liberator.Hints);
}, true);
document.getElementById("content-frame").contentDocument.addEventListener("load", function () {
alert("load1");
}, true);*/
/*document.getElementById("content-frame").addEventListener("DOMContentLoaded", function () {
alert("load2");
}, true);*/
} }
} }
}; };

View File

@@ -91,7 +91,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
</statusbar> </statusbar>
<vbox id="liberator-container" hidden="false"> <vbox id="liberator-container" hidden="false">
<listbox id="liberator-previewwindow" class="plain" rows="10" flex="1" hidden="true" <!--listbox id="liberator-previewwindow" class="plain" rows="10" flex="1" hidden="true"
onclick= "liberator.previewwindow.onEvent(event);" onclick= "liberator.previewwindow.onEvent(event);"
ondblclick="liberator.previewwindow.onEvent(event);" ondblclick="liberator.previewwindow.onEvent(event);"
onkeydown= "liberator.previewwindow.onEvent(event);"> onkeydown= "liberator.previewwindow.onEvent(event);">
@@ -99,7 +99,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
<listcol flex="1" width="50%"/> <listcol flex="1" width="50%"/>
<listcol flex="1" width="50%"/> <listcol flex="1" width="50%"/>
</listcols> </listcols>
</listbox> </listbox-->
<iframe id="liberator-multiline-output" src="about:blank" flex="1" height="10px" hidden="false" collapsed="true" <iframe id="liberator-multiline-output" src="about:blank" flex="1" height="10px" hidden="false" collapsed="true"
onclick="liberator.commandline.onMultilineOutputEvent(event)"/> onclick="liberator.commandline.onMultilineOutputEvent(event)"/>

View File

@@ -90,7 +90,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
</statusbar> </statusbar>
<vbox id="liberator-container" hidden="false"> <vbox id="liberator-container" hidden="false">
<listbox id="liberator-previewwindow" class="plain" rows="10" flex="1" hidden="true" <!--listbox id="liberator-previewwindow" class="plain" rows="10" flex="1" hidden="true"
onclick= "liberator.previewwindow.onEvent(event);" onclick= "liberator.previewwindow.onEvent(event);"
ondblclick="liberator.previewwindow.onEvent(event);" ondblclick="liberator.previewwindow.onEvent(event);"
onkeydown= "liberator.previewwindow.onEvent(event);"> onkeydown= "liberator.previewwindow.onEvent(event);">
@@ -98,7 +98,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
<listcol flex="1" width="50%"/> <listcol flex="1" width="50%"/>
<listcol flex="1" width="50%"/> <listcol flex="1" width="50%"/>
</listcols> </listcols>
</listbox> </listbox-->
<iframe id="liberator-multiline-output" src="about:blank" flex="1" height="10px" hidden="false" collapsed="true" <iframe id="liberator-multiline-output" src="about:blank" flex="1" height="10px" hidden="false" collapsed="true"
onclick="liberator.commandline.onMultilineOutputEvent(event)"/> onclick="liberator.commandline.onMultilineOutputEvent(event)"/>

View File

@@ -116,6 +116,15 @@ liberator.config = { //{{{
liberator.open(matches[1] + newNum + matches[3]); liberator.open(matches[1] + newNum + matches[3]);
} }
// load Vimperator specific modules
liberator.loadModule("search", liberator.Search);
liberator.loadModule("bookmarks", liberator.Bookmarks);
liberator.loadModule("history", liberator.History);
liberator.loadModule("tabs", liberator.Tabs);
liberator.loadModule("marks", liberator.Marks);
liberator.loadModule("quickmarks", liberator.QuickMarks);
liberator.loadModule("hints", liberator.Hints);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
////////////////////// MAPPINGS //////////////////////////////////////////////// ////////////////////// MAPPINGS ////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
@@ -342,28 +351,29 @@ liberator.config = { //{{{
completer: function (filter) { return liberator.completion.url(filter); } completer: function (filter) { return liberator.completion.url(filter); }
}); });
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
////////////////////// OPTIONS ///////////////////////////////////////////////// ////////////////////// OPTIONS /////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
liberator.options.add(["online"], "Set and reset the 'work offline' option", "boolean", true, liberator.options.add(["online"],
{ "Set the 'work offline' option",
setter: function (value) "boolean", true,
{ {
var ioService = Components.classes['@mozilla.org/network/io-service;1']. setter: function (value)
getService(Components.interfaces.nsIIOService2); {
var ioService = Components.classes['@mozilla.org/network/io-service;1'].
getService(Components.interfaces.nsIIOService2);
ioService.offline = !value; ioService.offline = !value;
gPrefService.setBoolPref("browser.offline", ioService.offline); gPrefService.setBoolPref("browser.offline", ioService.offline);
}, },
getter: function ()
{
return Components.classes['@mozilla.org/network/io-service;1'].
getService(Components.interfaces.nsIIOService2).offline;
}
});
getter: function ()
{
return Components.classes['@mozilla.org/network/io-service;1'].
getService(Components.interfaces.nsIIOService2).offline;
}
});
} }
//}}} //}}}
}; //}}} }; //}}}

View File

@@ -79,7 +79,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
oncommandupdate="if (typeof liberator.events != 'undefined') liberator.events.onSelectionChange(event);"/> oncommandupdate="if (typeof liberator.events != 'undefined') liberator.events.onSelectionChange(event);"/>
<vbox id="liberator-container" hidden="false"> <vbox id="liberator-container" hidden="false">
<listbox id="liberator-previewwindow" class="plain" rows="10" flex="1" hidden="true" <!--listbox id="liberator-previewwindow" class="plain" rows="10" flex="1" hidden="true"
onclick= "liberator.previewwindow.onEvent(event);" onclick= "liberator.previewwindow.onEvent(event);"
ondblclick="liberator.previewwindow.onEvent(event);" ondblclick="liberator.previewwindow.onEvent(event);"
onkeydown= "liberator.previewwindow.onEvent(event);"> onkeydown= "liberator.previewwindow.onEvent(event);">
@@ -87,7 +87,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
<listcol flex="1" width="50%"/> <listcol flex="1" width="50%"/>
<listcol flex="1" width="50%"/> <listcol flex="1" width="50%"/>
</listcols> </listcols>
</listbox> </listbox-->
<iframe id="liberator-multiline-output" src="about:blank" flex="1" height="10px" hidden="false" collapsed="true" <iframe id="liberator-multiline-output" src="about:blank" flex="1" height="10px" hidden="false" collapsed="true"
onclick="liberator.commandline.onMultilineOutputEvent(event)"/> onclick="liberator.commandline.onMultilineOutputEvent(event)"/>

View File

@@ -561,8 +561,6 @@ Define which type of messages are logged.
When bigger than zero, Vimperator will give messages about what it is doing. When bigger than zero, Vimperator will give messages about what it is doing.
They are printed to the error console which can be shown with [c]:javascript![c]. They are printed to the error console which can be shown with [c]:javascript![c].
The highest value is 9, being the most verbose mode. The highest value is 9, being the most verbose mode.
NOTE: non-functional for now.
____ ____