1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 18:27:57 +01:00

renamed commandline.js -> ui.js

moved all statusbar code to the StatusLine() class
This commit is contained in:
Martin Stubenschrott
2007-05-16 15:31:50 +00:00
parent 77686ff159
commit d99945054c
5 changed files with 348 additions and 195 deletions

View File

@@ -1471,7 +1471,7 @@ function focusNextFrame()
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
function getCurrentLocation() function getCurrentLocation()
{ {
return content.document.location.href; return window.content.document.location.href;
} }
/* returns the current title or null */ /* returns the current title or null */
@@ -1660,8 +1660,6 @@ function tab_go(index)
else else
getBrowser().mTabContainer.selectedIndex = index-1; getBrowser().mTabContainer.selectedIndex = index-1;
} }
updateStatusbar();
} }
/* quit_on_last_tab = 1: quit without saving session /* quit_on_last_tab = 1: quit without saving session
@@ -2244,7 +2242,7 @@ function removeMode(mode)
function showMode() function showMode()
{ {
// XXX: remove // XXX: remove
showStatusbarMessage(g_current_mode, STATUSFIELD_INPUTBUFFER); // showStatusbarMessage(g_current_mode, STATUSFIELD_INPUTBUFFER);
if (!get_pref("showmode") || !g_modemessages[g_current_mode]) if (!get_pref("showmode") || !g_modemessages[g_current_mode])
return; return;

View File

@@ -254,7 +254,8 @@ function Search()
// Called when the search dialog is asked for. Sets up everything necessary // Called when the search dialog is asked for. Sets up everything necessary
// for this round of searching // for this round of searching
this.openSearchDialog = function() { this.openSearchDialog = function()
{
// Get a reference to the focused window if necessary // Get a reference to the focused window if necessary
if (this.gWin == null) this.gWin = document.commandDispatcher.focusedWindow; if (this.gWin == null) this.gWin = document.commandDispatcher.focusedWindow;
@@ -419,7 +420,8 @@ function Search()
} }
// Finds text in a page // Finds text in a page
this.find = function(str, dir, pt) { this.find = function(str, dir, pt)
{
var norecurse = arguments[3]; var norecurse = arguments[3];
var matchRange; var matchRange;
@@ -451,14 +453,9 @@ function Search()
} }
} }
//logObject(vimperator); logMessage("Search initialized");
logMessage("Search initialized.");
} }
//searcher = new searcher();
//vimperator.registerCallback("submit", MODE_SEARCH, function(command) { /*vimperator.*/alert(command); } );
//vimperator.registerCallback("change", MODE_SEARCH, function(command) { /*vimperator.*/alert(command); } );
// @todo nicer way to register commands? // @todo nicer way to register commands?
g_commands.push( g_commands.push(
[ [

View File

@@ -1,14 +1,14 @@
// XXX: move somehere else! // XXX: move somehere else!
function save_history() // function save_history()
{ // {
set_pref("comp_history", comp_history.join("\n")); // set_pref("comp_history", comp_history.join("\n"));
} // }
//
function load_history() // function load_history()
{ // {
var hist = get_pref("comp_history", ""); // var hist = get_pref("comp_history", "");
comp_history = hist.split("\n"); // comp_history = hist.split("\n");
} // }
function multiliner(line, prev_match, heredoc) function multiliner(line, prev_match, heredoc)
{ {
@@ -86,6 +86,10 @@ function CommandLine ()
// The command bar which contains the current command // The command bar which contains the current command
var command_widget = document.getElementById('new-vim-commandbar'); var command_widget = document.getElementById('new-vim-commandbar');
// load the history
var hist = get_pref("commandline_history", "");
history = hist.split("\n");
function setNormalStyle() function setNormalStyle()
{ {
command_widget.inputField.setAttribute("style","font-family: monospace;"); command_widget.inputField.setAttribute("style","font-family: monospace;");
@@ -197,6 +201,7 @@ function CommandLine ()
{ {
addToHistory(command); addToHistory(command);
completionlist.hide(); completionlist.hide();
vimperator.statusline.updateProgress(""); // we may have a "match x of y" visible
} }
} }
else if(event.type == "input") else if(event.type == "input")
@@ -222,7 +227,7 @@ function CommandLine ()
// if (!end) // if (!end)
// command_line.value = ""; // command_line.value = "";
// the command is saved in the blur() handler // NOTE: the command is saved to the history in the blur() handler
focusContent(); focusContent();
var res = vimperator.triggerCallback("submit", command); var res = vimperator.triggerCallback("submit", command);
return res; return res;
@@ -360,7 +365,7 @@ function CommandLine ()
completion_index = -1; completion_index = -1;
} }
showStatusbarMessage("match " + (completion_index+1).toString() + " of " + completions.length.toString(), STATUSFIELD_PROGRESS); vimperator.statusline.updateProgress("match " + (completion_index+1).toString() + " of " + completions.length.toString());
// if the list is hidden, this function does nothing // if the list is hidden, this function does nothing
completionlist.selectItem(completion_index); completionlist.selectItem(completion_index);
} }
@@ -417,6 +422,12 @@ function CommandLine ()
} }
} }
} }
// it would be better if we had a destructor in javascript ...
this.saveHistory = function()
{
set_pref("commandline_history", history.join("\n"));
}
logMessage("CommandLine initialized."); logMessage("CommandLine initialized.");
} }
@@ -623,4 +634,110 @@ function InformationList(id, options)
logMessage("InformationList initialized for widget id: " + id); logMessage("InformationList initialized for widget id: " + id);
} }
function StatusLine()
{
////////////////////////////////////////////////////////////////////////////////
////////////////////// PRIVATE SECTION /////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// our status bar fields
var statusline_widget = document.getElementById("vimperator-statusline");
var url_widget = document.getElementById("vimperator-statusline-field-url");
var inputbuffer_widget = document.getElementById("vimperator-statusline-field-inputbuffer");
var progress_widget = document.getElementById("vimperator-statusline-field-progress");
var tabcount_widget = document.getElementById("vimperator-statusline-field-tabcount");
var bufferposition_widget = document.getElementById("vimperator-statusline-field-bufferposition");
////////////////////////////////////////////////////////////////////////////////
////////////////////// PUBLIC SECTION //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// use names for the color or "transparent" to remove color information
this.setColor = function(color)
{
if (!color)
color = "transparent";
statusline_widget.setAttribute("style", "background-color: " + color);
};
this.updateUrl = function(url)
{
if (!url || typeof(url) != "string")
url = getCurrentLocation();
url_widget.value = url;
};
this.updateInputBuffer = function(buffer)
{
if (!buffer || typeof(buffer) != "string")
buffer = "";
inputbuffer_widget.value = buffer;
};
this.updateProgress = function(progress)
{
if (!progress)
progress = "";
if (typeof(progress) == "string")
progress_widget.value = progress;
else if (typeof(progress) == "number")
{
var progress_str = "";
if (progress <= 0)
progress_str = "[ Loading... ]";
else if (progress < 1)
{
progress_str = "[";
var done = Math.floor(progress * 20);
for (i=0; i < done; i++)
progress_str += "=";
progress_str += ">";
for (i=19; i > done; i--)
progress_str += " ";
progress_str += "]";
}
progress_widget.value = progress_str;
}
};
// you can omit either of the 2 arguments
this.updateTabCount = function(cur_index, total_tabs)
{
if(!cur_index || typeof(cur_index != "number"))
cur_index = vimperator.tabs.index() + 1;
if(!total_tabs || typeof(cur_index != "number"))
total_tabs = vimperator.tabs.count();
//var tabcount_str = "[" + cur_index.toString() + "/" + total_tabs.toString() + "]";
tabcount_widget.value = "[" + cur_index.toString() + "/" + total_tabs.toString() + "]";
//tabcount_widget.value = tabcount_str;
};
// percent is given between 0 and 1
this.updateBufferPosition = function(percent)
{
if(!percent || typeof(percent) != "number")
{
var win = document.commandDispatcher.focusedWindow;
percent = win.scrollMaxY == 0 ? -1 : win.scrollY / win.scrollMaxY;
}
var bufferpostion_str = "";
percent = Math.round(percent*100);
if (percent < 0) bufferposition_str = "All";
else if (percent == 0) bufferposition_str = "Top";
else if (percent < 10) bufferposition_str = " " + percent.toString() + "%";
else if (percent >= 100) bufferposition_str = "Bot";
else bufferposition_str = percent.toString() + "%";
bufferposition_widget.value = bufferposition_str;
};
logMessage("StatusLine initialized");
}
// vim: set fdm=marker sw=4 ts=4 et: // vim: set fdm=marker sw=4 ts=4 et:

View File

@@ -26,8 +26,7 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL. the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/ }}} ***** END LICENSE BLOCK *****/
// The only global object, a handler to the main Vimperator object
// all our objects
var vimperator = null; var vimperator = null;
// major modes - FIXME: major cleanup needed // major modes - FIXME: major cleanup needed
@@ -54,14 +53,6 @@ var popup_allowed_events; // need to change and reset this firefox pref
var g_inputbuffer = ""; // here we store partial commands (e.g. 'g' if you want to type 'gg') var g_inputbuffer = ""; // here we store partial commands (e.g. 'g' if you want to type 'gg')
var g_count = -1; // the parsed integer of g_inputbuffer, or -1 if no count was given var g_count = -1; // the parsed integer of g_inputbuffer, or -1 if no count was given
var g_bufshow = false; // keeps track if the preview window shows current buffers ('B')
// handlers for vimperator triggered events, such as typing in the command
// line. See triggerVimperatorEvent and registerVimperatorEventHandler
//var g_vimperator_event_handlers = new Array();
// handles wildmode tab index
//var wild_tab_index = 0;
// handles multi-line commands // handles multi-line commands
var prev_match = new Array(5); var prev_match = new Array(5);
@@ -69,7 +60,7 @@ var heredoc = '';
// handles to our gui elements // handles to our gui elements
//var preview_window = null; //var preview_window = null;
var status_line = null; //var status_line = null;
var command_line = null; var command_line = null;
// our status bar fields // our status bar fields
@@ -108,47 +99,36 @@ nsBrowserStatusHandler.prototype =
if (link && ssli) if (link && ssli)
{ {
if (ssli == 1) if (ssli == 1)
updateStatusbar("Link: " + link); vimperator.statusline.updateUrl("Link: " + link);
else if (ssli == 2) else if (ssli == 2)
vimperator.echo("Link: " + link); vimperator.echo("Link: " + link);
} }
if (link == "") if (link == "")
{ {
updateStatusbar(); vimperator.statusline.updateUrl();
showMode(); showMode();
} }
},
setJSStatus : function(status)
{
// echo("setJSStatus");
// this.updateStatusField(status);
},
setJSDefaultStatus : function(status)
{
// echo("setJSDefaultStatus");
// this.updateStatusField(status);
},
setDefaultStatus : function(status)
{
// echo("setDefaultStatus");
// this.updateStatusField(status);
}, },
setJSStatus : function(status) { },
setJSDefaultStatus : function(status) { },
setDefaultStatus : function(status) { },
onStateChange:function(aProgress,aRequest,aFlag,aStatus) onStateChange:function(aProgress,aRequest,aFlag,aStatus)
{ {
//alert("state change");
const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener; const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
const nsIChannel = Components.interfaces.nsIChannel; //const nsIChannel = Components.interfaces.nsIChannel;
if (aFlag & nsIWebProgressListener.STATE_START && aRequest && aRequest.URI) if (aFlag & nsIWebProgressListener.STATE_START && aRequest && aRequest.URI)
{ {
var toLoadUrl = aRequest.URI.spec; vimperator.statusline.updateProgress(0);
} }
// this is called when all loading was done (or when the user canceled the load
else if (aFlag & nsIWebProgressListener.STATE_STOP) else if (aFlag & nsIWebProgressListener.STATE_STOP)
{ {
updateStatusbar(); //alert('stop: ' + aRequest.URI.spec);
vimperator.statusline.updateUrl(aRequest.URI.spec);
vimperator.statusline.updateProgress("");
// also reset the buffer list, since the url titles are valid here // also reset the buffer list, since the url titles are valid here
showBufferList(true); showBufferList(true);
} }
@@ -161,37 +141,43 @@ nsBrowserStatusHandler.prototype =
UpdateBackForwardButtons(); UpdateBackForwardButtons();
var url = aLocation.spec; var url = aLocation.spec;
// also update the original firefox location bar
if (gURLBar) if (gURLBar)
gURLBar.value = url; // also update the original firefox location bar gURLBar.value = url;
// onLocationChange is also called when switching/deleting tabs // onLocationChange is also called when switching/deleting tabs
if (hah.currentMode() != HINT_MODE_ALWAYS) if (hah.currentMode() != HINT_MODE_ALWAYS)
hah.disableHahMode(); hah.disableHahMode();
// updating history cache is not done here but in vimperator.statusline.updateUrl(url);
// the 'pageshow' event handler, because at this point I don't vimperator.statusline.updateProgress();
// have access to the url title setTimeout(function() {vimperator.statusline.updateBufferPosition();}, 100); // if not delayed we get the wrong position of the old buffer
//alert('locchange2');
// updating history cache is not done here but in the 'pageshow' event
// handler, because at this point I don't have access to the url title
return 0;
}, },
onProgressChange:function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress) onProgressChange:function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress)
{ {
showStatusbarMessage(createProgressBar(aCurTotalProgress/aMaxTotalProgress), STATUSFIELD_PROGRESS); vimperator.statusline.updateProgress(aCurTotalProgress/aMaxTotalProgress);
return 0; return 0;
}, },
onStatusChange:function (aWebProgress, aRequest, aStatus, aMessage) onStatusChange:function (aWebProgress, aRequest, aStatus, aMessage)
{ {
showStatusbarMessage(aMessage, STATUSFIELD_URL); //alert('change');
vimperator.statusline.updateUrl(aMessage);
return 0; return 0;
}, },
onSecurityChange:function (aWebProgress, aRequest, aState) onSecurityChange:function (aWebProgress, aRequest, aState)
{ {
const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener; const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
if(aState & nsIWebProgressListener.STATE_IS_INSECURE) if(aState & nsIWebProgressListener.STATE_IS_INSECURE)
setStatusbarColor("transparent"); vimperator.statusline.setColor("transparent");
else if(aState & nsIWebProgressListener.STATE_IS_BROKEN) else if(aState & nsIWebProgressListener.STATE_IS_BROKEN)
setStatusbarColor("orange"); vimperator.statusline.setColor("orange");
else if(aState & nsIWebProgressListener.STATE_IS_SECURE) else if(aState & nsIWebProgressListener.STATE_IS_SECURE)
setStatusbarColor("yellow"); vimperator.statusline.setColor("yellow");
return 0; return 0;
} }
@@ -199,6 +185,7 @@ nsBrowserStatusHandler.prototype =
};/*}}}*/ };/*}}}*/
// called when the chrome is fully loaded and before the main window is shown
window.addEventListener("load", init, false); window.addEventListener("load", init, false);
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
@@ -215,21 +202,120 @@ function init()
Vimperator.prototype.search = new Search; Vimperator.prototype.search = new Search;
Vimperator.prototype.previewwindow = new InformationList("vimperator-preview-window", { incremental_fill: false, max_items: 10 }); Vimperator.prototype.previewwindow = new InformationList("vimperator-preview-window", { incremental_fill: false, max_items: 10 });
Vimperator.prototype.bufferwindow = new InformationList("vimperator-buffer-window", { incremental_fill: false, max_items: 10 }); Vimperator.prototype.bufferwindow = new InformationList("vimperator-buffer-window", { incremental_fill: false, max_items: 10 });
Vimperator.prototype.statusline = new StatusLine();
Vimperator.prototype.tabs = new Tabs();
// XXX: move elsewhere // XXX: move elsewhere
vimperator.registerCallback("submit", MODE_EX, function(command) { /*vimperator.*/execute(command); } ); vimperator.registerCallback("submit", MODE_EX, function(command) { /*vimperator.*/execute(command); } );
vimperator.registerCallback("complete", MODE_EX, function(str) { return exTabCompletion(str); } ); vimperator.registerCallback("complete", MODE_EX, function(str) { return exTabCompletion(str); } );
//status_line = document.getElementById("vim-statusbar");
//preview_window = document.getElementById("vim-preview_window");
status_line = document.getElementById("vim-statusbar");
//completion_list = document.getElementById("vim-completion");
command_line = document.getElementById("vim-commandbar"); command_line = document.getElementById("vim-commandbar");
// if (!completion_list || !command_line)
// alert("GUI not correctly created! Strange things will happen (until I find out, how to exit this script by code)");
// Setup our status handler - from browser.js // Setup our main status handler - from browser.js
window.XULBrowserWindow = new nsBrowserStatusHandler(); window.XULBrowserWindow = new nsBrowserStatusHandler();
// window.XULBrowserWindow = new function()
// {
// this.init = function(){alert("init");};
// QueryInterface: function(aIID)
// {
// if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
// aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
// aIID.equals(Components.interfaces.nsIXULBrowserWindow) ||
// aIID.equals(Components.interfaces.nsISupports))
// return this;
// throw Components.results.NS_NOINTERFACE;
// },
//
// /* functions needed for functioning */
// init: function() {},
// setJSStatus: function(status) {},
// setJSDefaultStatus: function(status) {},
// setDefaultStatus: function(status) {},
// onLinkIconAvailable:function(a) {},
// onStatusChange: function (aWebProgress, aRequest, aStatus, aMessage) { return 0; },
//
// setOverLink: function(link, b)
// {
// var ssli = get_pref("showstatuslinks");
// if (link && ssli)
// {
// if (ssli == 1)
// vimperator.statusline.updateUrl("Link: " + link);
// else if (ssli == 2)
// vimperator.echo("Link: " + link);
// }
//
// if (link == "")
// {
// vimperator.statusline.updateUrl();
// showMode();
// }
// },
//
//
// // called when a page load is requested or finished/stopped
// onStateChange:function(aProgress,aRequest,aFlag,aStatus)
// {
// const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
// //const nsIChannel = Components.interfaces.nsIChannel;
// if (aFlag & nsIWebProgressListener.STATE_START && aRequest && aRequest.URI)
// {
// vimperator.statusline.updateProgress(0);
// }
// // this is called when all loading was done (or when the user canceled the load
// else if (aFlag & nsIWebProgressListener.STATE_STOP)
// {
// vimperator.statusline.updateUrl(aRequest.URI.spec);
// vimperator.statusline.updateProgress("");
// // also reset the buffer list, since the url titles are valid here
// showBufferList(true);
// }
// return 0;
// },
// // onLocationChange is also called when switching/deleting tabs
// onLocationChange: function (aWebProgress, aRequest, aLocation)
// {
// // firefox 3.0 doesn't seem to have this function anymore
// if (typeof UpdateBackForwardButtons == "function")
// UpdateBackForwardButtons();
//
// var url = aLocation.spec;
//
// // also update the original firefox location bar
// if (gURLBar)
// gURLBar.value = url;
//
// if (hah.currentMode() != HINT_MODE_ALWAYS)
// hah.disableHahMode();
//
// vimperator.statusline.updateUrl(url);
// vimperator.statusline.updateProgress();
// setTimeout(function() {vimperator.statusline.updateBufferPosition();}, 100); // if not delayed we get the wrong position of the old buffer
//
// // updating history cache is not done here but in the 'pageshow' event
// // handler, because at this point I don't have access to the url title
// return 0;
// },
// onProgressChange:function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress)
// {
// vimperator.statusline.updateProgress(aCurTotalProgress/aMaxTotalProgress);
// return 0;
// },
// onSecurityChange:function (aWebProgress, aRequest, aState)
// {
// const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
// if(aState & nsIWebProgressListener.STATE_IS_INSECURE)
// vimperator.statusline.setColor("transparent");
// else if(aState & nsIWebProgressListener.STATE_IS_BROKEN)
// vimperator.statusline.setColor("orange");
// else if(aState & nsIWebProgressListener.STATE_IS_SECURE)
// vimperator.statusline.setColor("yellow");
//
// return 0;
// }
// }
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation) .getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem).treeOwner .QueryInterface(Components.interfaces.nsIDocShellTreeItem).treeOwner
@@ -238,6 +324,14 @@ function init()
.XULBrowserWindow = window.XULBrowserWindow; .XULBrowserWindow = window.XULBrowserWindow;
// this function adds all our required listeners to react on events // this function adds all our required listeners to react on events
// also stuff like window.onScroll is handled there. // also stuff like window.onScroll is handled there.
addEventListeners(); addEventListeners();
@@ -299,9 +393,9 @@ function init()
function unload() function unload()
{ {
/*** save our preferences ***/ /*** save our preferences ***/
// save_history(); FIXME vimperator.commandline.saveHistory();
// reset firefox pref // reset some modified firefox prefs
if (get_firefox_pref('dom.popup_allowed_events', 'change click dblclick mouseup reset submit') if (get_firefox_pref('dom.popup_allowed_events', 'change click dblclick mouseup reset submit')
== popup_allowed_events + " keypress") == popup_allowed_events + " keypress")
set_firefox_pref('dom.popup_allowed_events', popup_allowed_events); set_firefox_pref('dom.popup_allowed_events', popup_allowed_events);
@@ -319,6 +413,17 @@ function onVimperatorKeypress(event)/*{{{*/
if (key == null) if (key == null)
return false; return false;
if(event.type == "keydown")
{
logObject(event);
logObject(event.target);
return;//alert(event.target.id);
}
// sometimes the non-content area has focus, making our keys not work
// if (event.target.id == "main-window")
// alert("focusContent();");
// XXX: ugly hack for now pass certain keys to firefox as they are without beeping // XXX: ugly hack for now pass certain keys to firefox as they are without beeping
// also fixes key navigation in menus, etc. // also fixes key navigation in menus, etc.
if (key == "<Tab>" || key == "<Return>" || key == "<Space>" || key == "<Up>" || key == "<Down>") if (key == "<Tab>" || key == "<Return>" || key == "<Space>" || key == "<Up>" || key == "<Down>")
@@ -370,6 +475,7 @@ function onVimperatorKeypress(event)/*{{{*/
// if Hit-a-hint mode is on, special handling of keys is required // if Hit-a-hint mode is on, special handling of keys is required
// g_hint_mappings is used // g_hint_mappings is used
// FIXME: total mess
if (hah.hintsVisible()) if (hah.hintsVisible())
{ {
// never propagate this key to firefox, when hints are visible // never propagate this key to firefox, when hints are visible
@@ -388,14 +494,14 @@ function onVimperatorKeypress(event)/*{{{*/
{ {
hah.disableHahMode(); hah.disableHahMode();
g_inputbuffer = ""; g_inputbuffer = "";
updateStatusbar(); vimperator.statusline.updateInputBuffer("");
return false; return false;
} }
else else
{ {
// make sure that YOU update the statusbar message yourself // FIXME: make sure that YOU update the statusbar message yourself
// first in g_hint_mappings when in this mode! // first in g_hint_mappings when in this mode!
updateStatusbar(); vimperator.statusline.updateInputBuffer(g_inputbuffer);
return false; return false;
} }
} }
@@ -408,7 +514,7 @@ function onVimperatorKeypress(event)/*{{{*/
beep(); beep();
hah.disableHahMode(); hah.disableHahMode();
g_inputbuffer = ""; g_inputbuffer = "";
updateStatusbar(); vimperator.statusline.updateInputBuffer(g_inputbuffer);
return true; return true;
} }
@@ -443,7 +549,7 @@ function onVimperatorKeypress(event)/*{{{*/
g_inputbuffer = ""; g_inputbuffer = "";
} }
updateStatusbar(); vimperator.statusline.updateInputBuffer(g_inputbuffer);
return true; return true;
} }
@@ -458,7 +564,7 @@ function onVimperatorKeypress(event)/*{{{*/
{ {
g_inputbuffer = ""; g_inputbuffer = "";
beep(); beep();
updateStatusbar(); vimperator.statusline.updateInputBuffer(g_inputbuffer);
return true; return true;
} }
else else
@@ -467,7 +573,7 @@ function onVimperatorKeypress(event)/*{{{*/
if (g_inputbuffer != "" || key != "0") if (g_inputbuffer != "" || key != "0")
{ {
g_inputbuffer += key; g_inputbuffer += key;
updateStatusbar(); vimperator.statusline.updateInputBuffer(g_inputbuffer);
return true; return true;
} }
// else let the flow continue, and check if 0 is a mapping // else let the flow continue, and check if 0 is a mapping
@@ -494,7 +600,7 @@ function onVimperatorKeypress(event)/*{{{*/
// command executed, reset input buffer // command executed, reset input buffer
g_inputbuffer = ""; g_inputbuffer = "";
updateStatusbar(); vimperator.statusline.updateInputBuffer(g_inputbuffer);
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return false; return false;
@@ -519,7 +625,7 @@ function onVimperatorKeypress(event)/*{{{*/
beep(); beep();
} }
updateStatusbar(); vimperator.statusline.updateInputBuffer(g_inputbuffer);
return false; return false;
}/*}}}*/ }/*}}}*/
@@ -550,7 +656,6 @@ function focusContent(clear_command_line, clear_statusline)
// completion_list.hidden = true; // completion_list.hidden = true;
// comp_tab_index = COMPLETION_UNINITIALIZED; // comp_tab_index = COMPLETION_UNINITIALIZED;
// comp_history_index = -1; // comp_history_index = -1;
// updateStatusbar();
// } // }
var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
@@ -574,6 +679,7 @@ function onEscape()
setCurrentMode(MODE_NORMAL); setCurrentMode(MODE_NORMAL);
hah.disableHahMode(); hah.disableHahMode();
focusContent(true, true); focusContent(true, true);
vimperator.statusline.updateUrl();
} }
} }
@@ -584,6 +690,7 @@ function addEventListeners()
{ {
window.addEventListener("unload", unload, false); window.addEventListener("unload", unload, false);
window.addEventListener("keypress", onVimperatorKeypress, true); window.addEventListener("keypress", onVimperatorKeypress, true);
// window.addEventListener("keydown", onVimperatorKeypress, true);
// this handler is for middle click only in the content // this handler is for middle click only in the content
//window.addEventListener("mousedown", onVimperatorKeypress, true); //window.addEventListener("mousedown", onVimperatorKeypress, true);
@@ -591,9 +698,9 @@ function addEventListeners()
//document.getElementById("content").onclick = function(event) { alert("foo"); }; //document.getElementById("content").onclick = function(event) { alert("foo"); };
// these 4 events require >=firefox-2.0 beta1 // these 4 events require >=firefox-2.0 beta1
window.addEventListener("TabMove", updateStatusbar, false); window.addEventListener("TabMove", vimperator.statusline.updateTabCount, false);
window.addEventListener("TabOpen", updateStatusbar, false); window.addEventListener("TabOpen", vimperator.statusline.updateTabCount, false);
window.addEventListener("TabClose", updateStatusbar, false); window.addEventListener("TabClose", vimperator.statusline.updateTabCount, false);
window.addEventListener("TabSelect", function(event) window.addEventListener("TabSelect", function(event)
{ {
if (hah.currentMode == HINT_MODE_ALWAYS) if (hah.currentMode == HINT_MODE_ALWAYS)
@@ -601,7 +708,7 @@ function addEventListeners()
hah.disableHahMode(); hah.disableHahMode();
hah.enableHahMode(HINT_MODE_ALWAYS); hah.enableHahMode(HINT_MODE_ALWAYS);
} }
updateStatusbar(); vimperator.statusline.updateTabCount();
}, false); }, false);
// update our history cache when a new page is shown // update our history cache when a new page is shown
@@ -627,7 +734,7 @@ function addEventListeners()
// called when the window is scrolled. // called when the window is scrolled.
window.onscroll = function (event) window.onscroll = function (event)
{ {
showStatusbarMessage(createCursorPositionString(), STATUSFIELD_CURSOR_POSITION); vimperator.statusline.updateBufferPosition();
}; };
// adds listeners to buffer actions. // adds listeners to buffer actions.
@@ -673,9 +780,6 @@ var buffer_changed_listener =
return 0; return 0;
}, },
// This fires when the location bar changes i.e load event is confirmed
// or when the user switches tabs
onLocationChange: function(aProgress, aRequest, aURI) { /*alert('locchange');*/ setTimeout( updateBufferList, 250); return 0; }, onLocationChange: function(aProgress, aRequest, aURI) { /*alert('locchange');*/ setTimeout( updateBufferList, 250); return 0; },
onProgressChange:function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress){ return 0; }, onProgressChange:function(aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress){ return 0; },
onStatusChange: function() {return 0;}, onStatusChange: function() {return 0;},
@@ -684,79 +788,6 @@ var buffer_changed_listener =
} }
////////////////////////////////////////////////////////////////////////
// statusbar/progressbar ////////////////////////////////////////// {{{1
////////////////////////////////////////////////////////////////////////
/* the statusbar is currently divided into 5 fields, you can set
* each one independently */
function showStatusbarMessage(msg, field)
{
var bar = document.getElementById("vim-sb-field-" + field);
if (bar)
bar.value = msg;
}
function setStatusbarColor(color)
{
var bar = document.getElementById("vim-statusbar");
bar.setAttribute("style", "background-color: " + color);
}
function updateStatusbar(message)
{
var buffers = "[" + (gBrowser.tabContainer.selectedIndex + 1).toString() + "/" +
gBrowser.tabContainer.childNodes.length.toString() + "]";
showStatusbarMessage(message || getCurrentLocation(), STATUSFIELD_URL);
showStatusbarMessage(" " + g_inputbuffer + " ", STATUSFIELD_INPUTBUFFER);
showStatusbarMessage("", STATUSFIELD_PROGRESS);
showStatusbarMessage(buffers, STATUSFIELD_BUFFERS);
// required to postpone it a little, otherwise we could get the wrong cursor
// position when switching tabs
setTimeout(function() {
showStatusbarMessage(createCursorPositionString(), STATUSFIELD_CURSOR_POSITION);
} , 10);
}
/* aProgress is a float between 0 and 1 */
function createProgressBar(aProgress)
{
/* the progress field */
var progress;
if (aProgress <= 0)
progress = "[ Loading... ]";
else if (aProgress >= 1)
progress = "[====================]";
else
{
progress = /*(aProgress*100).round().toString() + "% */"[";
done = Math.floor(aProgress * 20);
for (i=0; i < done; i++)
progress = progress + "=";
progress = progress + ">";
for (i=19; i > done; i--)
progress = progress + " ";
progress = progress + "]";
}
return progress;
}
function createCursorPositionString()
{
var win = document.commandDispatcher.focusedWindow;
//var x = win.scrollMaxX == 0 ? 100 : Math.round(win.scrollX / win.scrollMaxX * 100);
var y = win.scrollMaxY == 0 ? -1 : Math.round(win.scrollY / win.scrollMaxY * 100);
var percent;
if (y < 0) percent = "All";
else if (y == 0) percent = "Top";
else if (y < 10) percent = " " + y.toString() + "%";
else if (y >= 100) percent = "Bot";
else percent = y.toString() + "%";
return(" " + percent);
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// text input functions /////////////////////////////////////////// {{{1 // text input functions /////////////////////////////////////////// {{{1
@@ -1003,4 +1034,19 @@ function Vimperator()
this.echo = this.commandline.echo; this.echo = this.commandline.echo;
this.echoerr = this.commandline.echoErr; this.echoerr = this.commandline.echoErr;
} }
// provides functions for working with tabs
function Tabs()
{
// @returns the index of the currently selected tab starting with 0
this.index = function()
{
return getBrowser().tabContainer.selectedIndex;
}
this.count = function()
{
return getBrowser().tabContainer.childNodes.length;
}
}
// vim: set fdm=marker sw=4 ts=4 et: // vim: set fdm=marker sw=4 ts=4 et:

View File

@@ -41,7 +41,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
<script type="application/x-javascript" src="help.js"/> <script type="application/x-javascript" src="help.js"/>
<script type="application/x-javascript" src="vimperator.js"/> <script type="application/x-javascript" src="vimperator.js"/>
<script type="application/x-javascript" src="commands.js"/> <script type="application/x-javascript" src="commands.js"/>
<script type="application/x-javascript" src="commandline.js"/> <script type="application/x-javascript" src="ui.js"/>
<script type="application/x-javascript" src="settings.js"/> <script type="application/x-javascript" src="settings.js"/>
<script type="application/x-javascript" src="completion.js"/> <script type="application/x-javascript" src="completion.js"/>
<script type="application/x-javascript" src="bookmarks.js"/> <script type="application/x-javascript" src="bookmarks.js"/>
@@ -74,17 +74,12 @@ the terms of any one of the MPL, the GPL or the LGPL.
</listcols> </listcols>
</listbox> </listbox>
<hbox id="vim-statusbar" flex="1" height="10" hidden="false" style="-moz-user-focus:ignore;"> <hbox id="vimperator-statusline" flex="1" height="10" hidden="false" style="-moz-user-focus:ignore;">
<textbox class="plain" id="vim-sb-field-1" flex="1" crop="right" value="about:blank" <textbox class="plain" id="vimperator-statusline-field-url" flex="1" readonly="true" style="font-family: monospace; background-color: transparent; -moz-user-focus:ignore;"/>
readonly="true" style="font-family: monospace; background-color: transparent; -moz-user-focus:ignore;"/> <label class="plain" id="vimperator-statusline-field-inputbuffer" flex="0" style="font-family: monospace; padding: 0px 0px 0px 8px"/>
<label class="plain" id="vim-sb-field-2" flex="0" crop="right" value="[===&gt; Loading... &lt;===]" <label class="plain" id="vimperator-statusline-field-progress" flex="0" style="font-family: monospace; padding: 0px 0px 0px 8px"/>
style="font-family: monospace"/> <label class="plain" id="vimperator-statusline-field-tabcount" flex="0" style="font-family: monospace; padding: 0px 0px 0px 8px"/>
<label class="plain" id="vim-sb-field-3" flex="0" crop="right" value="" <label class="plain" id="vimperator-statusline-field-bufferposition" flex="0" style="font-family: monospace; padding: 0px 0px 0px 8px"/>
style="font-family: monospace"/>
<label class="plain" id="vim-sb-field-4" flex="0" crop="right" value="[0/0]"
style="font-family: monospace"/>
<label class="plain" id="vim-sb-field-5" flex="0" crop="right" value=" Top"
style="font-family: monospace"/>
</hbox> </hbox>
<listbox id="vim-completion" class="plain" rows="1" flex="1" hidden="true" <listbox id="vim-completion" class="plain" rows="1" flex="1" hidden="true"