1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 04:07: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)
{
liberator.log(e);
liberator.log(e, 0);
return false;
}
@@ -306,7 +306,7 @@ liberator.Bookmarks = function () //{{{
}
catch (e)
{
liberator.log(e);
liberator.log(e, 0);
return i;
}

View File

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

View File

@@ -489,7 +489,7 @@ liberator.Commands = function () //{{{
if (exCommands[i].name == command.name)
{
// 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;
}
}
@@ -635,9 +635,9 @@ liberator.Commands = function () //{{{
});
// TODO: remove preview window, or change it at least
commandManager.add(["pc[lose]"],
"Close preview window on bottom of screen",
function () { liberator.previewwindow.hide(); });
// commandManager.add(["pc[lose]"],
// "Close preview window on bottom of screen",
// 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"
if (liberator.options["focuscontent"])
{
liberator.log("focuscontent");
setTimeout(function () {
var focused = document.commandDispatcher.focusedElement;
if (focused && (typeof focused.value != "undefined") && focused.value.length == 0)
@@ -537,12 +536,12 @@ liberator.Events = function () //{{{
var name = file.leafName.replace(/\.vimp$/i, "");
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)
{
liberator.log("macro directory not found or error reading macro file");
liberator.log("macro directory not found or error reading macro file", 9);
}
}, 100);
@@ -1118,7 +1117,7 @@ liberator.Events = function () //{{{
if (key == "q") // TODO: should not be hardcoded
{
liberator.modes.isRecording = false;
liberator.log("Recorded " + currentMacro + ": " + macros[currentMacro], 8);
liberator.log("Recorded " + currentMacro + ": " + macros[currentMacro], 9);
event.preventDefault();
event.stopPropagation();
return true;

View File

@@ -33,6 +33,12 @@ const liberator = (function () //{{{
/////////////////////////////////////////////////////////////////////////////{{{
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
function addOptions()
{
@@ -82,7 +88,7 @@ const liberator = (function () //{{{
}
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
{
liberator.open("chrome://global/content/console.xul",
(liberator.options.newtab &&
(liberator.options.newtab == "all" || liberator.options.newtab.split(",").indexOf("javascript") != -1)) ?
(liberator.options["newtab"] &&
(liberator.options["newtab"] == "all" || liberator.options["newtab"].split(",").indexOf("javascript") != -1)) ?
liberator.NEW_TAB : liberator.CURRENT_TAB);
}
else
@@ -394,6 +400,7 @@ const liberator = (function () //{{{
{
var res = [];
// 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",
"options.html", "tabs.html", "marks.html", "repeat.html",
"autocommands.html", "developer.html", "various.html"];
@@ -472,6 +479,7 @@ const liberator = (function () //{{{
// "cancel"
// "complete"
// TODO: "zoom": if the zoom value of the current buffer changed
// TODO: move to ui.js?
registerCallback: function (type, mode, func)
{
// TODO: check if callback is already registered
@@ -559,7 +567,6 @@ const liberator = (function () //{{{
if (window == ww.activeWindow && document.commandDispatcher.focusedElement && clearFocusedElement)
document.commandDispatcher.focusedElement.blur();
liberator.log("focusContent: " + clearFocusedElement);
// TODO: make more generic
try
{
@@ -580,6 +587,8 @@ const liberator = (function () //{{{
},
// 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)
{
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
has: function (feature)
{
@@ -661,7 +674,8 @@ const liberator = (function () //{{{
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.options["newtab"].split(",").indexOf("help") != -1)) ?
liberator.NEW_TAB : liberator.CURRENT_TAB;
function jumpToTag(file, tag)
@@ -704,11 +718,25 @@ const liberator = (function () //{{{
liberator.echoerr("E149: Sorry, no help for " + topic);
},
globalVariables: { },
loadModule: function (name, func) { loadModule(name, func); },
// logs a message to the javascript error console
// if msg is an object, it is beautified
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")
msg = liberator.util.objectToString(msg, false);
@@ -791,6 +819,12 @@ const liberator = (function () //{{{
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: function (saveSession)
{
@@ -838,58 +872,32 @@ const liberator = (function () //{{{
.quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
},
// TODO: move to {muttator,vimperator,...}.js
// this function is called, when the chrome is ready
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
log("commands"); liberator.commands = liberator.Commands(); addCommands();
log("options"); liberator.options = liberator.Options(); addOptions();
log("mappings"); liberator.mappings = liberator.Mappings(); addMappings();
log("events"); liberator.events = liberator.Events();
log("commandline"); liberator.commandline = liberator.CommandLine();
log("search"); liberator.search = liberator.Search();
log("preview window"); liberator.previewwindow = liberator.InformationList("liberator-previewwindow", { incrementalFill: false, maxItems: 10 });
log("statusline"); liberator.statusline = liberator.StatusLine();
log("buffer"); liberator.buffer = liberator.Buffer();
log("editor"); liberator.editor = liberator.Editor();
log("autocommands"); liberator.autocommands = liberator.AutoCommands();
log("io"); liberator.io = liberator.IO();
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);
loadModule("commands", liberator.Commands); addCommands();
loadModule("options", liberator.Options); addOptions();
loadModule("mappings", liberator.Mappings); addMappings();
loadModule("events", liberator.Events);
loadModule("commandline", liberator.CommandLine);
loadModule("statusline", liberator.StatusLine);
loadModule("buffer", liberator.Buffer);
loadModule("editor", liberator.Editor);
loadModule("autocommands", liberator.AutoCommands);
loadModule("io", liberator.IO);
loadModule("completion", liberator.Completion);
// loadModule("previewwindow" = liberator.InformationList("liberator-previewwindow", { incrementalFill: false, maxItems: 10 });
// This adds options/mappings/commands which are only valid in this particular extension
if (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.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 = {};
liberator.log("All modules loaded", 3);
// TODO: move elsewhere
liberator.registerCallback("submit", liberator.modes.EX, function (command) { liberator.execute(command); });
@@ -958,7 +966,7 @@ const liberator = (function () //{{{
liberator.statusline.update();
liberator.log(liberator.config.name + " fully initialized", 1);
liberator.log(liberator.config.name + " fully initialized", 0);
},
shutdown: function ()

View File

@@ -98,7 +98,7 @@ liberator.modes = (function () //{{{
function handleModeChange(oldMode, newMode)
{
// 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");
switch (oldMode)

View File

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

View File

@@ -91,7 +91,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
</statusbar>
<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);"
ondblclick="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%"/>
</listcols>
</listbox>
</listbox-->
<iframe id="liberator-multiline-output" src="about:blank" flex="1" height="10px" hidden="false" collapsed="true"
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>
<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);"
ondblclick="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%"/>
</listcols>
</listbox>
</listbox-->
<iframe id="liberator-multiline-output" src="about:blank" flex="1" height="10px" hidden="false" collapsed="true"
onclick="liberator.commandline.onMultilineOutputEvent(event)"/>

View File

@@ -116,6 +116,15 @@ liberator.config = { //{{{
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 ////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
@@ -346,7 +355,9 @@ liberator.config = { //{{{
////////////////////// OPTIONS /////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
liberator.options.add(["online"], "Set and reset the 'work offline' option", "boolean", true,
liberator.options.add(["online"],
"Set the 'work offline' option",
"boolean", true,
{
setter: function (value)
{
@@ -363,7 +374,6 @@ liberator.config = { //{{{
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);"/>
<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);"
ondblclick="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%"/>
</listcols>
</listbox>
</listbox-->
<iframe id="liberator-multiline-output" src="about:blank" flex="1" height="10px" hidden="false" collapsed="true"
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.
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.
NOTE: non-functional for now.
____