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

move initialisation of vimperator.input to the constructor function

This commit is contained in:
Doug Kearns
2007-07-12 07:48:27 +00:00
parent fbc88ab606
commit 8d1e4ef276

View File

@@ -83,13 +83,6 @@ function init() //{{{
Vimperator.prototype.echo = vimperator.commandline.echo; Vimperator.prototype.echo = vimperator.commandline.echo;
Vimperator.prototype.echoerr = vimperator.commandline.echoErr; Vimperator.prototype.echoerr = vimperator.commandline.echoErr;
// XXX: move into Vimperator() ?
vimperator.input = {
buffer: "", // partial command storage
pendingMap: null, // pending map storage
count: -1 // parsed count from the input buffer
};
// XXX: move elsewhere // XXX: move elsewhere
vimperator.registerCallback("submit", vimperator.modes.EX, function(command) { /*vimperator.*/execute(command); } ); vimperator.registerCallback("submit", vimperator.modes.EX, function(command) { /*vimperator.*/execute(command); } );
vimperator.registerCallback("complete", vimperator.modes.EX, function(str) { return exTabCompletion(str); } ); vimperator.registerCallback("complete", vimperator.modes.EX, function(str) { return exTabCompletion(str); } );
@@ -200,13 +193,13 @@ function Vimperator() //{{{
var str_mode = mode_messages[mode]; var str_mode = mode_messages[mode];
var str_extended = mode_messages[extended_mode]; var str_extended = mode_messages[extended_mode];
if(!str_mode && !str_extended) if (!str_mode && !str_extended)
{ {
vimperator.echo(""); vimperator.echo("");
return; return;
} }
if(str_mode && str_extended) if (str_mode && str_extended)
str_extended = " (" + str_extended + ")"; str_extended = " (" + str_extended + ")";
else else
{ {
@@ -223,6 +216,12 @@ function Vimperator() //{{{
this.version = "###VERSION### CVS (created: ###DATE###)"; this.version = "###VERSION### CVS (created: ###DATE###)";
this.input = {
buffer: "", // partial command storage
pendingMap: null, // pending map storage
count: -1 // parsed count from the input buffer
};
/////////////// callbacks //////////////////////////// /////////////// callbacks ////////////////////////////
// XXX: shouldn't that callback be moved to commandline? --mst // XXX: shouldn't that callback be moved to commandline? --mst
/** /**
@@ -237,6 +236,7 @@ function Vimperator() //{{{
// TODO: check if callback is already registered // TODO: check if callback is already registered
callbacks.push([type, mode, func]); callbacks.push([type, mode, func]);
} }
this.triggerCallback = function(type, data) this.triggerCallback = function(type, data)
{ {
for (var i in callbacks) for (var i in callbacks)
@@ -274,12 +274,14 @@ function Vimperator() //{{{
if (!silent) if (!silent)
showMode(); showMode();
} }
// returns true if "whichmode" is found in either the main or // returns true if "whichmode" is found in either the main or
// extended mode // extended mode
this.hasMode = function(whichmode) this.hasMode = function(whichmode)
{ {
return ((mode & whichmode) || (extended_mode & whichmode) > 0) ? true : false; return ((mode & whichmode) || (extended_mode & whichmode) > 0) ? true : false;
} }
this.addMode = function(main, extended) this.addMode = function(main, extended)
{ {
if (main) if (main)
@@ -289,6 +291,7 @@ function Vimperator() //{{{
showMode(); showMode();
} }
// always show the new mode in the statusline // always show the new mode in the statusline
this.removeMode = function(main, extended) this.removeMode = function(main, extended)
{ {
@@ -318,7 +321,7 @@ function Vimperator() //{{{
*/ */
this.log = function(msg, level) this.log = function(msg, level)
{ {
// if(Options.getPref("verbose") >= level) // FIXME: hangs vimperator, probably timing issue --mst // if (Options.getPref("verbose") >= level) // FIXME: hangs vimperator, probably timing issue --mst
console_service.logStringMessage('vimperator: ' + msg); console_service.logStringMessage('vimperator: ' + msg);
} }
@@ -424,7 +427,7 @@ function Events() //{{{
vimperator.history.add(url, title); vimperator.history.add(url, title);
// code which is only relevant if the page load is the current tab goes here: // code which is only relevant if the page load is the current tab goes here:
if(doc == getBrowser().selectedBrowser.contentDocument) if (doc == getBrowser().selectedBrowser.contentDocument)
{ {
/* none yet */ /* none yet */
//vimperator.statusline.updateUrl(); //vimperator.statusline.updateUrl();
@@ -441,7 +444,7 @@ function Events() //{{{
{ {
// BIG TODO: removeEventListeners() to avoid mem leaks // BIG TODO: removeEventListeners() to avoid mem leaks
window.dump("TODO: remove eventlisteners"); window.dump("TODO: remove eventlisteners");
}; }
this.onEscape = function() this.onEscape = function()
{ {
@@ -453,8 +456,7 @@ function Events() //{{{
vimperator.focusContent(); vimperator.focusContent();
vimperator.statusline.updateUrl(); vimperator.statusline.updateUrl();
} }
}; }
this.onKeyPress = function(event) this.onKeyPress = function(event)
{ {
@@ -485,7 +487,7 @@ function Events() //{{{
{ {
var elt = window.document.commandDispatcher.focusedElement; var elt = window.document.commandDispatcher.focusedElement;
if(elt.setSelectionRange && readFromClipboard()) if (elt.setSelectionRange && readFromClipboard())
// readFromClipboard would return 'undefined' if not checked // readFromClipboard would return 'undefined' if not checked
// dunno about .setSelectionRange // dunno about .setSelectionRange
{ {
@@ -514,7 +516,7 @@ function Events() //{{{
// handle Escape-all-keys mode (I) // handle Escape-all-keys mode (I)
if (vimperator.hasMode(vimperator.modes.ESCAPE_ALL_KEYS)) if (vimperator.hasMode(vimperator.modes.ESCAPE_ALL_KEYS))
{ {
if(vimperator.hasMode(vimperator.modes.ESCAPE_ONE_KEY)) if (vimperator.hasMode(vimperator.modes.ESCAPE_ONE_KEY))
vimperator.removeMode(null, vimperator.modes.ESCAPE_ONE_KEY); // and then let flow continue vimperator.removeMode(null, vimperator.modes.ESCAPE_ONE_KEY); // and then let flow continue
else if (key == "<Esc>" || key == "<C-[>" || key == "<C-v>") else if (key == "<Esc>" || key == "<C-[>" || key == "<C-v>")
; // let flow continue to handle these keys ; // let flow continue to handle these keys
@@ -555,7 +557,7 @@ function Events() //{{{
var map = vimperator.mappings.get(vimperator.modes.HINTS, key); var map = vimperator.mappings.get(vimperator.modes.HINTS, key);
if (map) if (map)
{ {
if(map.always_active || vimperator.hints.currentState() == 1) if (map.always_active || vimperator.hints.currentState() == 1)
{ {
//g_hint_mappings[i][1].call(this, event); //g_hint_mappings[i][1].call(this, event);
map.execute(); map.execute();
@@ -592,8 +594,8 @@ function Events() //{{{
if (res < 0) // error occured processing this key if (res < 0) // error occured processing this key
{ {
vimperator.beep(); vimperator.beep();
//if(vimperator.hints.currentMode() == HINT_MODE_QUICK) //if (vimperator.hints.currentMode() == HINT_MODE_QUICK)
if(vimperator.hasMode(vimperator.modes.QUICK_HINT)) if (vimperator.hasMode(vimperator.modes.QUICK_HINT))
vimperator.hints.disableHahMode(); vimperator.hints.disableHahMode();
else // ALWAYS mode else // ALWAYS mode
vimperator.hints.resetHintedElements(); vimperator.hints.resetHintedElements();
@@ -611,8 +613,8 @@ function Events() //{{{
else // open in current window else // open in current window
vimperator.hints.openHints(false, false); vimperator.hints.openHints(false, false);
//if(vimperator.hints.currentMode() == HINT_MODE_QUICK) //if (vimperator.hints.currentMode() == HINT_MODE_QUICK)
if(vimperator.hasMode(vimperator.modes.QUICK_HINT)) if (vimperator.hasMode(vimperator.modes.QUICK_HINT))
vimperator.hints.disableHahMode(); vimperator.hints.disableHahMode();
else // ALWAYS mode else // ALWAYS mode
vimperator.hints.resetHintedElements(); vimperator.hints.resetHintedElements();
@@ -682,7 +684,7 @@ function Events() //{{{
} }
vimperator.statusline.updateInputBuffer(vimperator.input.buffer); vimperator.statusline.updateInputBuffer(vimperator.input.buffer);
return false; return false;
}; }
window.addEventListener("keypress", this.onKeyPress, true); window.addEventListener("keypress", this.onKeyPress, true);
@@ -703,11 +705,11 @@ function Events() //{{{
{ {
// STATE_IS_DOCUMENT | STATE_IS_WINDOW is important, because we also // STATE_IS_DOCUMENT | STATE_IS_WINDOW is important, because we also
// receive statechange events for loading images and other parts of the web page // receive statechange events for loading images and other parts of the web page
if(flags & (Components.interfaces.nsIWebProgressListener.STATE_IS_DOCUMENT | if (flags & (Components.interfaces.nsIWebProgressListener.STATE_IS_DOCUMENT |
Components.interfaces.nsIWebProgressListener.STATE_IS_WINDOW)) Components.interfaces.nsIWebProgressListener.STATE_IS_WINDOW))
{ {
// This fires when the load event is initiated // This fires when the load event is initiated
if(flags & Components.interfaces.nsIWebProgressListener.STATE_START) if (flags & Components.interfaces.nsIWebProgressListener.STATE_START)
{ {
vimperator.statusline.updateProgress(0); vimperator.statusline.updateProgress(0);
} }
@@ -719,11 +721,11 @@ function Events() //{{{
onSecurityChange: function (webProgress, aRequest, aState) onSecurityChange: function (webProgress, aRequest, aState)
{ {
const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener; const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
if(aState & nsIWebProgressListener.STATE_IS_INSECURE) if (aState & nsIWebProgressListener.STATE_IS_INSECURE)
vimperator.statusline.setClass("insecure"); vimperator.statusline.setClass("insecure");
else if(aState & nsIWebProgressListener.STATE_IS_BROKEN) else if (aState & nsIWebProgressListener.STATE_IS_BROKEN)
vimperator.statusline.setClass("broken"); vimperator.statusline.setClass("broken");
else if(aState & nsIWebProgressListener.STATE_IS_SECURE) else if (aState & nsIWebProgressListener.STATE_IS_SECURE)
vimperator.statusline.setClass("secure"); vimperator.statusline.setClass("secure");
}, },
onStatusChange: function(webProgress, request, status, message) onStatusChange: function(webProgress, request, status, message)
@@ -777,6 +779,7 @@ function Events() //{{{
setDefaultStatus : function(status) { ; }, setDefaultStatus : function(status) { ; },
onLinkIconAvailable: function() { ; } onLinkIconAvailable: function() { ; }
}; };
window.XULBrowserWindow = this.progressListener; window.XULBrowserWindow = this.progressListener;
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation) .getInterface(Components.interfaces.nsIWebNavigation)
@@ -1038,7 +1041,7 @@ function Tabs() //{{{
if (quit_on_last_tab >= 1 && getBrowser().mTabs.length <= count) if (quit_on_last_tab >= 1 && getBrowser().mTabs.length <= count)
vimperator.quit(quit_on_last_tab == 2); vimperator.quit(quit_on_last_tab == 2);
if(focus_left_tab && tab.previousSibling) if (focus_left_tab && tab.previousSibling)
this.select("-1", false); this.select("-1", false);
getBrowser().removeTab(tab); getBrowser().removeTab(tab);