1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-06 21:14:11 +01:00

First attempt in making vimperator object orietened.

For now only the CommandLine widget was made a real encapsulated object.
This commit is contained in:
Martin Stubenschrott
2007-05-11 12:42:17 +00:00
parent 0d7ff394b9
commit 7ac9a05803
10 changed files with 426 additions and 720 deletions

View File

@@ -2,7 +2,7 @@
TOP = $(shell pwd) TOP = $(shell pwd)
VERSION = 0.4.1 VERSION = 0.5
OS = $(shell uname -s) OS = $(shell uname -s)
BUILD_DATE = $(shell date "+%Y/%m/%d %H:%M:%S") BUILD_DATE = $(shell date "+%Y/%m/%d %H:%M:%S")

View File

@@ -240,4 +240,37 @@ function Bookmarks()
} }
var bookmarks = new Bookmarks(); // FIXME, must it really be here? doesn't work in vimperator.js var bookmarks = new Bookmarks(); // FIXME, must it really be here? doesn't work in vimperator.js
Vimperator.prototype.quickmarks = new function()
{
//logObject(vimperator);
//setTimeout(function() {logObject(vimperator)}, 1000);
//Vimperator.echo("test");
//alert(vimperator.getpr("hinttags"));
this.add = function() { alert('add');};
this.rem = function() { vimperator.echo("rem"); logObject(vimperator)};
logMessage("quickmarks initialized.");
}
function QM()
{
//logObject(vimperator);
logMessage(vimperator.getpr("complete"));
// var command_widget = document.getElementById('new-vim-commandbar');
// logMessage(command_widget);
//setTimeout(function() {logObject(vimperator)}, 1000);
//Vimperator.echo("test");
this.add = function() { alert('add');};
this.rem = function() { vimperator.echo("rem"); logObject(vimperator)};
this.zoom = function() { vimperator.zoom_to(200); logObject(vimperator)};
logMessage("QM initialized.");
}
// vim: set fdm=marker sw=4 ts=4 et: // vim: set fdm=marker sw=4 ts=4 et:

View File

@@ -120,7 +120,7 @@ var g_commands = [/*{{{*/
"Go to buffer from buffer list", "Go to buffer from buffer list",
"Argument can be either the buffer index or the full URL.", "Argument can be either the buffer index or the full URL.",
buffer_switch, buffer_switch,
function (filter) {return get_buffer_completions(filter);} function (filter) { return get_buffer_completions(filter); }
], ],
[ [
["buffers", "files", "ls"], ["buffers", "files", "ls"],
@@ -219,7 +219,7 @@ var g_commands = [/*{{{*/
try { try {
eval(args); eval(args);
} catch(e) { } catch(e) {
echoerr(e.name + ": " + e.message); vimperator.echoerr(e.name + ": " + e.message);
} }
}, },
null null
@@ -470,7 +470,7 @@ var g_commands = [/*{{{*/
["ve[rsion][!]"], ["ve[rsion][!]"],
"Show version information", "Show version information",
"You can show the Firefox version page with <code class=\"command\">:version!</code>.", "You can show the Firefox version page with <code class=\"command\">:version!</code>.",
function (args, special) { if (special) openURLs("about:"); else echo("Vimperator version: " + g_vimperator_version); }, function (args, special) { if (special) openURLs("about:"); else vimperator.echo("Vimperator version: " + vimperator.ver); },
null null
], ],
[ [
@@ -478,7 +478,7 @@ var g_commands = [/*{{{*/
["win[open] [url] [| url]"], ["win[open] [url] [| url]"],
"Open an URL in a new window", "Open an URL in a new window",
"Not implemented yet", "Not implemented yet",
function () { echo("winopen not yet implemented"); }, function () { vimperator.echo("winopen not yet implemented"); },
null null
], ],
[ [
@@ -524,7 +524,7 @@ var g_mappings = [/*{{{*/
["b {number}"], ["b {number}"],
"Open a prompt to switch buffers", "Open a prompt to switch buffers",
"Typing the corresponding number opens switches to this buffer", "Typing the corresponding number opens switches to this buffer",
function (args) { bufshow("", true); openVimperatorBar('buffer '); } function (args) { bufshow("", true); vimperator.commandline.open(":", "buffer ", MODE_EX); }
], ],
[ [
["B"], ["B"],
@@ -547,14 +547,14 @@ var g_mappings = [/*{{{*/
"Count WILL be supported in future releases, then <code class=\"mapping\">2D</code> removes two tabs and the one the left is selected.", "Count WILL be supported in future releases, then <code class=\"mapping\">2D</code> removes two tabs and the one the left is selected.",
function(count) { tab_remove(count, true, 0); } function(count) { tab_remove(count, true, 0); }
], ],
[ /*[
["ge"], ["ge"],
["ge {cmd}"], ["ge {cmd}"],
"Execute an Ex command", "Execute an Ex command",
"<code>Go Execute</code> works like <code class=\"command\">:execute</code>.<br/>"+ "<code>Go Execute</code> works like <code class=\"command\">:execute</code>.<br/>"+
"This mapping is for debugging purposes, and may be removed in future.", "This mapping is for debugging purposes, and may be removed in future.",
function(count) { openVimperatorBar('execute '); } function(count) { openVimperatorBar('execute '); }
], ],*/
[ [
["gh"], ["gh"],
["gh"], ["gh"],
@@ -597,14 +597,14 @@ var g_mappings = [/*{{{*/
["o"], ["o"],
"Open one or more URLs in the current tab", "Open one or more URLs in the current tab",
"See <code class=\"command\">:open</code> for more details", "See <code class=\"command\">:open</code> for more details",
function(count) { openVimperatorBar('open '); } function(count) { vimperator.commandline.open(":", "open ", MODE_EX); }
], ],
[ [
["O"], ["O"],
["O"], ["O"],
"Open one ore more URLs in the current tab, based on current location", "Open one ore more URLs in the current tab, based on current location",
"Works like <code class=\"mapping\">o</code>, but preselects current URL in the <code class=\"command\">:open</code> query.", "Works like <code class=\"mapping\">o</code>, but preselects current URL in the <code class=\"command\">:open</code> query.",
function(count) { openVimperatorBar('open ' + getCurrentLocation()); } function(count) { vimperator.commandline.open(":", "open " + getCurrentLocation(), MODE_EX); }
], ],
[ [
["p", "<MiddleMouse>"], ["p", "<MiddleMouse>"],
@@ -641,14 +641,14 @@ var g_mappings = [/*{{{*/
"Open one or more URLs in a new tab", "Open one or more URLs in a new tab",
"Like <code class=\"mapping\">o</code> but open URLs in a new tab.<br/>"+ "Like <code class=\"mapping\">o</code> but open URLs in a new tab.<br/>"+
"See <code class=\"command\">:tabopen</code> for more details", "See <code class=\"command\">:tabopen</code> for more details",
function(count) { openVimperatorBar('tabopen '); } function(count) { vimperator.commandline.open(":", "tabopen ", MODE_EX); }
], ],
[ [
["T"], ["T"],
["T"], ["T"],
"Open one ore more URLs in a new tab, based on current location", "Open one ore more URLs in a new tab, based on current location",
"Works like <code class=\"mapping\">t</code>, but preselects current URL in the <code class=\"command\">:tabopen</code> query.", "Works like <code class=\"mapping\">t</code>, but preselects current URL in the <code class=\"command\">:tabopen</code> query.",
function(count) { openVimperatorBar('tabopen ' + getCurrentLocation()); } function(count) { vimperator.commandline.open(":", "tabopen " + getCurrentLocation(), MODE_EX); }
], ],
[ [
["u"], ["u"],
@@ -879,21 +879,26 @@ var g_mappings = [/*{{{*/
], ],
/* search managment */ /* search managment */
[
["g/"],
["g/"],
"Open search dialog",
"",
function(count) { vimperator.search.openSearchDialog(); }
],
[ [
["n"], ["n"],
["n"], ["n"],
"Find next", "Find next",
"Repeat the last \"/\" 1 time (until count is supported).", "Repeat the last \"/\" 1 time (until count is supported).",
// don't use a closure for this, is just DoesNotWork (TM) function(count) { vimperator.search.findNext(); }
function(count) { gFindBar.onFindAgainCmd(); } // this does not work, why?: goDoCommand('cmd_findAgain'); }
], ],
[ [
["N"], ["N"],
["N"], ["N"],
"Find previous", "Find previous",
"Repeat the last \"/\" 1 time (until count is supported) in the opposite direction.", "Repeat the last \"/\" 1 time (until count is supported) in the opposite direction.",
// don't use a closure for this, is just DoesNotWork (TM) function(count) { vimperator.search.findPrevious(); }
function(count) { gFindBar.onFindPreviousCmd(); } // this does not work, why?: goDoCommand('cmd_findPrevious'); }
], ],
/* vimperator managment */ /* vimperator managment */
@@ -909,7 +914,7 @@ var g_mappings = [/*{{{*/
[":"], [":"],
"Start command line mode", "Start command line mode",
"In command line mode, you can perform extended commands, which may require arguments.", "In command line mode, you can perform extended commands, which may require arguments.",
function(count) { openVimperatorBar(null); } function(count) { vimperator.commandline.open(":", "", MODE_EX); }
], ],
[ [
["I"], ["I"],
@@ -1019,14 +1024,14 @@ var g_mappings = [/*{{{*/
] ]
];/*}}}*/ ];/*}}}*/
var g_insert_mappings = [ /*{{{*/ // var g_insert_mappings = [ /*{{{*/
["xxx", "todo"], // ["xxx", "todo"],
["<C-w>", "delete word"], // ["<C-w>", "delete word"],
["<C-u>", "delete beginning"], // ["<C-u>", "delete beginning"],
["<C-a>", "go beginning"], // ["<C-a>", "go beginning"],
["<C-e>", "go end"], // ["<C-e>", "go end"],
["<C-c>", "cancel"] // ["<C-c>", "cancel"]
]; /*}}}*/ // ]; /*}}}*/
/* [command, action, cancel_hint_mode, always_active] */ /* [command, action, cancel_hint_mode, always_active] */
var g_hint_mappings = [ /*{{{*/ var g_hint_mappings = [ /*{{{*/
@@ -1034,11 +1039,11 @@ var g_hint_mappings = [ /*{{{*/
["o", "hah.openHints(false, false);", true, false], ["o", "hah.openHints(false, false);", true, false],
["t", "hah.openHints(true, false);", true, false], ["t", "hah.openHints(true, false);", true, false],
["<C-w>", "hah.openHints(false, true );", true, false], ["<C-w>", "hah.openHints(false, true );", true, false],
["s", "echoerr('Saving of links not yet implemented');", true, false], ["s", "vimperator.echoerr('Saving of links not yet implemented');", true, false],
["y", "hah.yankUrlHints();", true, false], ["y", "hah.yankUrlHints();", true, false],
["Y", "hah.yankTextHints();", true, false], ["Y", "hah.yankTextHints();", true, false],
[",", "g_inputbuffer+=','; hah.setCurrentState(0);", false, true], [",", "g_inputbuffer+=','; hah.setCurrentState(0);", false, true],
[":", "openVimperatorBar(null);", false, true], [":", "vimperator.commandline.open(':', '', MODE_EX);", false, true],
/* movement keys */ /* movement keys */
["<C-e>", "scrollBufferRelative(0, 1);", false, true], ["<C-e>", "scrollBufferRelative(0, 1);", false, true],
["<C-y>", "scrollBufferRelative(0, -1);", false, true], ["<C-y>", "scrollBufferRelative(0, -1);", false, true],
@@ -1094,10 +1099,10 @@ g_modemessages[MODE_INSERT] = "INSERT";
g_modemessages[MODE_VISUAL] = "VISUAL"; g_modemessages[MODE_VISUAL] = "VISUAL";
// returns null, if the cmd cannot be found in our g_commands array, or // returns null, if the cmd cannot be found in our g_commands array, or
// otherwise a refernce to our command // otherwise a reference to our command
function get_command(cmd) // {{{ function get_command(cmd) // {{{
{ {
commands = []; var commands = [];
var added; var added;
for (var i = 0; i < g_commands.length; i++, added = false) for (var i = 0; i < g_commands.length; i++, added = false)
{ {
@@ -1117,15 +1122,20 @@ function get_command(cmd) // {{{
} }
} }
} }
// return an unambigious command even if it was only given partly
if (commands.length == 1) if (commands.length == 1)
return commands[0]; return commands[0];
return null; return null;
} // }}} } // }}}
function execute_command(count, cmd, special, args, modifiers) // {{{ function execute_command(count, cmd, special, args, modifiers) // {{{
{ {
if (!cmd) return; if (!cmd)
if (!modifiers) modifiers = {}; return;
if (!modifiers)
modifiers = {};
var command = get_command(cmd); var command = get_command(cmd);
if (command === null) if (command === null)
{ {
@@ -1145,11 +1155,13 @@ function execute_command(count, cmd, special, args, modifiers) // {{{
} // }}} } // }}}
// return [null, null, null, null, heredoc_tag || false];
// [count, cmd, special, args] = match;
function tokenize_ex(string, tag) function tokenize_ex(string, tag)
{ {
// removing comments // removing comments
string.replace(/\s*".*$/, ''); string.replace(/\s*".*$/, '');
if (tag) if (tag) // we already have a multiline heredoc construct
{ {
if (string == tag) if (string == tag)
return [null, null, null, null, false]; return [null, null, null, null, false];
@@ -1159,68 +1171,34 @@ function tokenize_ex(string, tag)
// 0 - count, 1 - cmd, 2 - special, 3 - args, 4 - heredoc tag // 0 - count, 1 - cmd, 2 - special, 3 - args, 4 - heredoc tag
var matches = string.match(/^:*(\d+)?([a-zA-Z]+)(!)?(?:\s+(.*?))?$/); var matches = string.match(/^:*(\d+)?([a-zA-Z]+)(!)?(?:\s+(.*?))?$/);
if (!matches) return [null, null, null, null, null]; if (!matches)
return [null, null, null, null, null];
matches.shift(); matches.shift();
// parse count
if (matches[0]) if (matches[0])
{ {
matches[0] = parseInt(matches[0]); matches[0] = parseInt(matches[0]);
if (isNaN(matches[0])) matches[0] = 0; if (isNaN(matches[0]))
matches[0] = 0; // 0 is the default if no count given
} }
else matches[0] = 0; else
matches[0] = 0;
matches[2] = !!matches[2]; matches[2] = !!matches[2];
matches.push(null); matches.push(null);
if (matches[3]) if (matches[3])
{ {
tag = matches[3].match(/<<\s*(\w+)/); tag = matches[3].match(/<<\s*(\w+)\s*$/);
if (tag && tag[1]) if (tag && tag[1])
matches[4] = tag[1]; matches[4] = tag[1];
} }
else matches[3] = ''; else
matches[3] = '';
return matches; return matches;
} }
function multiliner(line, prev_match, heredoc)
{
var end = true;
var match = tokenize_ex(line, prev_match[4]);
if (prev_match[3] === undefined) prev_match[3] = '';
if (match[4] === null)
{
focusContent(false, true); // also sets comp_tab_index to -1
execute_command.apply(this, match);
}
else
{
if (match[4] === false)
{
prev_match[3] = prev_match[3].replace(new RegExp('<<\s*' + prev_match[4]), heredoc.replace(/\n$/, ''));
focusContent(false, true); // also sets comp_tab_index to -1
execute_command.apply(this, prev_match);
prev_match = new Array(5);
prev_match[3] = '';
heredoc = '';
}
else
{
end = false;
if (!prev_match[3])
{
prev_match[0] = match[0];
prev_match[1] = match[1];
prev_match[2] = match[2];
prev_match[3] = match[3];
prev_match[4] = match[4];
}
else
{
heredoc += match[3] + '\n';
}
}
}
return [prev_match, heredoc, end];
}
function execute(string) function execute(string)
{ {
@@ -1235,33 +1213,33 @@ function execute(string)
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// statusbar/commandbar handling ////////////////////////////////// {{{1 // statusbar/commandbar handling ////////////////////////////////// {{{1
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
function echo(msg) function echo(msg)
{ {
/* In Mozilla, the XUL textbox is implemented as a wrapper around an HTML /* In Mozilla, the XUL textbox is implemented as a wrapper around an HTML
* input element. The read only property '.inputField' holds a reference to this inner * input element. The read only property '.inputField' holds a reference to this inner
* input element. */ * input element. */
var bar = command_line.inputField; var bar = command_line.inputField;
var focused = document.commandDispatcher.focusedElement; var focused = document.commandDispatcher.focusedElement;
if (focused && focused == bar) if (focused && focused == bar)
return; return;
bar.setAttribute("style","font-family: monospace;"); bar.setAttribute("style","font-family: monospace;");
bar.value = msg; bar.value = msg;
} }
function echoerr(msg) function echoerr(msg)
{ {
/* In Mozilla, the XUL textbox is implemented as a wrapper around an HTML /* In Mozilla, the XUL textbox is implemented as a wrapper around an HTML
* input element. The read only property '.inputField' holds a reference to this inner * input element. The read only property '.inputField' holds a reference to this inner
* input element. */ * input element. */
var bar = command_line.inputField; var bar = command_line.inputField;
var focused = document.commandDispatcher.focusedElement; var focused = document.commandDispatcher.focusedElement;
if (focused && focused == bar) if (focused && focused == bar)
return; return;
bar.setAttribute("style", "font-family: monospace; color:white; background-color:red; font-weight: bold"); bar.setAttribute("style", "font-family: monospace; color:white; background-color:red; font-weight: bold");
bar.value = msg; bar.value = msg;
} }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// navigation functions /////////////////////////////////////////// {{{1 // navigation functions /////////////////////////////////////////// {{{1
@@ -1276,7 +1254,7 @@ function stepInHistory(steps)
else else
{ {
beep(); beep();
if(index<0) if(index < 0)
echo("Cannot go past beginning of history"); echo("Cannot go past beginning of history");
else else
echo("Cannot go past end of history"); echo("Cannot go past end of history");
@@ -1706,9 +1684,10 @@ function bufshow(filter, in_comp_window)
{ {
if (in_comp_window) // fill the completion list if (in_comp_window) // fill the completion list
{ {
g_completions = get_buffer_completions(filter); // FIXME
completion_fill_list(0); // g_completions = get_buffer_completions(filter);
completion_show_list(); // completion_fill_list(0);
// completion_show_list();
} }
else // in the preview window else // in the preview window
{ {
@@ -1856,7 +1835,8 @@ function zoom_in(factor)
} }
} }
function zoom_to(value) function zoom_to(value) {};
Vimperator.prototype.zoom_to = function(value)
{ {
var zoomMgr = ZoomManager.prototype.getInstance(); var zoomMgr = ZoomManager.prototype.getInstance();
value = parseInt(value); value = parseInt(value);
@@ -2281,6 +2261,9 @@ function removeMode(mode)
function showMode() function showMode()
{ {
// XXX: remove
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

@@ -30,180 +30,6 @@ var g_completions = new Array();
// The completion substrings, used for showing the longest common match // The completion substrings, used for showing the longest common match
var g_substrings = []; var g_substrings = [];
var comp_tab_index = COMPLETION_UNINITIALIZED; // the index in the internal g_completions array
var comp_tab_list_offset = 0; // how many items is the displayed list shifted from the internal tab index
var comp_tab_startstring = "";
var comp_history = new Array();
var comp_history_index = -1;
/* uses the entries in g_completions to fill the listbox
* starts at index 'startindex', and shows COMPLETION_MAXITEMS
* returns the number of items */
function completion_fill_list(startindex)/*{{{*/
{
// remove all old items first
var items = completion_list.getElementsByTagName("listitem");
while (items.length > 0) { completion_list.removeChild(items[0]);}
// find start index
//var i = index - 3; // 3 lines of context
if (startindex + COMPLETION_MAXITEMS > g_completions.length)
startindex = g_completions.length - COMPLETION_MAXITEMS;
if (startindex < 0)
startindex = 0;
for(i=startindex; i<g_completions.length && i < startindex + COMPLETION_MAXITEMS; i++)
{
completion_add_to_list(g_completions[i], false);
}
//completion_list.hidden = true;
// completion_list.setAttribute("rows", (i-startindex).toString());
// showStatusbarMessage ( (i-startindex).toString(), 1);
// if ( i-startindex > 0) // XXX: respect completetopt setting
// completion_list.hidden = false;
// else
// completion_list.hidden = true;
// completion_list.setAttribute("rows", (i-startindex).toString());
return (i-startindex);
}/*}}}*/
function completion_show_list()/*{{{*/
{
var items = g_completions.length;
if (items > COMPLETION_MAXITEMS)
items = COMPLETION_MAXITEMS;
if (items > 1) // FIXME
{
completion_list.setAttribute("rows", items.toString());
completion_list.hidden = false;
}
else
completion_list.hidden = true;
}/*}}}*/
/* add a single completion item to the list */
function completion_add_to_list(completion_item, at_beginning)/*{{{*/
{
var item = document.createElement("listitem");
var cell1 = document.createElement("listcell");
var cell2 = document.createElement("listcell");
cell1.setAttribute("label", completion_item[0]);
cell1.setAttribute("width", "200");
cell2.setAttribute("label", completion_item[1]);
cell2.setAttribute("style", "color:green; font-family: sans");
item.appendChild(cell1);
item.appendChild(cell2);
if (at_beginning == true)
{
var items = completion_list.getElementsByTagName("listitem");
if (items.length > 0)
completion_list.insertBefore(item, items[0]);
else
completion_list.appendChild(item);
}
else
completion_list.appendChild(item);
}/*}}}*/
/* select the next index, refill list if necessary
*
* changes 'comp_tab_index' */
function completion_select_next_item(has_list, has_full, has_longest)/*{{{*/
{
if (has_full)
comp_tab_index++;
has_list = has_list || (!completion_list.hidden && (has_full || has_longest));
if (comp_tab_index >= g_completions.length) /* wrap around */
{
comp_tab_index = -1;
if (has_list && has_full)
completion_list.selectedIndex = -1;
return;
}
if (has_full)
showStatusbarMessage(" match " + (comp_tab_index + 1).toString() + " of " + g_completions.length.toString() + " ", STATUSFIELD_PROGRESS);
if (!has_list) return;
if (comp_tab_index < 1) // at the top of the list
{
completion_fill_list(0);
comp_tab_list_offset = 0;
}
var listindex = comp_tab_index - comp_tab_list_offset;
// only move the list, if there are still items we can move
if (listindex >= COMPLETION_MAXITEMS - COMPLETION_CONTEXTLINES &&
comp_tab_list_offset < g_completions.length - COMPLETION_MAXITEMS)
{
// for speed reason: just remove old item, and add new at the end of the list
var items = completion_list.getElementsByTagName("listitem");
completion_list.removeChild(items[0]);
completion_add_to_list(g_completions[comp_tab_index + COMPLETION_CONTEXTLINES], false);
comp_tab_list_offset++;
}
if (has_full)
{
listindex = comp_tab_index - comp_tab_list_offset;
completion_list.selectedIndex = listindex;
}
}/*}}}*/
/* select the previous index, refill list if necessary
*
* changes 'comp_tab_index' */
function completion_select_previous_item(has_list, has_full, has_longest)/*{{{*/
{
if (has_full)
comp_tab_index--;
has_list = has_list || (!completion_list.hidden && (has_full || has_longest));
if (comp_tab_index == -1)
{
if (has_list && has_full)
completion_list.selectedIndex = -1;
return;
}
if (has_full)
showStatusbarMessage("match " + (comp_tab_index+1).toString() + " of " + g_completions.length.toString(), STATUSFIELD_PROGRESS);
if (comp_tab_index < -1) // go to the end of the list
{
comp_tab_index = g_completions.length -1;
if (!has_list) return;
completion_fill_list(g_completions.length - COMPLETION_MAXITEMS);
comp_tab_list_offset = g_completions.length - COMPLETION_MAXITEMS;//COMPLETION_MAXITEMS - 1;
if (comp_tab_list_offset < 0)
comp_tab_list_offset = 0;
}
if (!has_list) return;
var listindex = comp_tab_index - comp_tab_list_offset;
// only move the list, if there are still items we can move
if (listindex < COMPLETION_CONTEXTLINES && comp_tab_list_offset > 0)
{
// for speed reason: just remove old item, and add new at the end of the list
if (has_list)
{
var items = completion_list.getElementsByTagName("listitem");
completion_list.removeChild(items[items.length-1]);
completion_add_to_list(g_completions[comp_tab_index - COMPLETION_CONTEXTLINES], true);
}
comp_tab_list_offset--;
}
if (has_full)
{
listindex = comp_tab_index - comp_tab_list_offset;
completion_list.selectedIndex = listindex;
}
}/*}}}*/
/* /*
* returns the longest common substring * returns the longest common substring
@@ -224,7 +50,7 @@ function get_longest_substring()/*{{{*/
return longest; return longest;
}/*}}}*/ }/*}}}*/
// function is case insensitive // function uses smartcase
// list = [ [['com1', 'com2'], 'text'], [['com3', 'com4'], 'text'] ] // list = [ [['com1', 'com2'], 'text'], [['com3', 'com4'], 'text'] ]
function build_longest_common_substring(list, filter)/*{{{*/ function build_longest_common_substring(list, filter)/*{{{*/
{ {
@@ -271,7 +97,7 @@ function build_longest_common_substring(list, filter)/*{{{*/
return filtered; return filtered;
}/*}}}*/ }/*}}}*/
/* this function is case senstitive */ /* this function is case sensitive */
function build_longest_starting_substring(list, filter)/*{{{*/ function build_longest_starting_substring(list, filter)/*{{{*/
{ {
var filtered = []; var filtered = [];
@@ -691,27 +517,42 @@ function get_buffer_completions(filter)/*{{{*/
return build_longest_common_substring(items, filter); return build_longest_common_substring(items, filter);
}/*}}}*/ }/*}}}*/
////////// COMMAND HISTORY HANDLING ////////////
function add_to_command_history(str)
// return [startindex, [[itemtext, itemhelp],...]]
function exTabCompletion(str)
{ {
/* add string to the command line history */ var [count, cmd, special, args] = tokenize_ex(str);
if (str.length >= 2 && comp_history.push(str) > COMMAND_LINE_HISTORY_SIZE) var completions = new Array;
comp_history.shift(); var start = 0;
} var s = 0; //FIXME, command specific start setting
function save_history() // if there is no space between the command name and the cursor
{ // then get completions of the command name
set_pref("comp_history", comp_history.join("\n")); var matches = str.match(/^(:*\d*)\w*$/);
if(matches)
{
completions = get_command_completions(cmd);
start = matches[1].length;
}
else // dynamically get completions as specified in the g_commands array
{
var command = get_command(cmd);
if (command && command[COMPLETEFUNC])
{
completions = command[COMPLETEFUNC].call(this, args);
// if (command[COMMANDS][0] == "open" ||
// command[COMMANDS][0] == "tabopen" ||
// command[COMMANDS][0] == "winopen")
// start = str.search(/^:*\d*\w+(\s+|.*\|)/); // up to the last | or the first space
// else
matches = str.match(/^:*\d*\w+\s+/); // up to the first spaces only
start = matches[0].length;
}
}
return [start, completions];
} }
function load_history()
{
var hist = get_pref("comp_history", "");
comp_history = hist.split("\n");
}
///////// PREVIEW WINDOW ////////////////////// ///////// PREVIEW WINDOW //////////////////////
/* uses the entries in completions to fill the listbox */ /* uses the entries in completions to fill the listbox */

View File

@@ -30,7 +30,7 @@ function help(section, easter)
{ {
if (easter) if (easter)
{ {
echoerr("E478: Don't panic!"); vimperator.echoerr("E478: Don't panic!");
return; return;
} }
if ((arguments[3] && arguments[3].inTab))// || !window.content.document.open) if ((arguments[3] && arguments[3].inTab))// || !window.content.document.open)
@@ -238,7 +238,7 @@ function help(section, easter)
var element = doc.getElementById(section); var element = doc.getElementById(section);
if (!element) if (!element)
{ {
echoerr("E149: Sorry, no help for " + section); vimperator.echoerr("E149: Sorry, no help for " + section);
return; return;
} }
var pos = cumulativeOffset(element.parentNode); var pos = cumulativeOffset(element.parentNode);

View File

@@ -430,7 +430,7 @@ function hit_a_hint()
linkNumString = ''; linkNumString = '';
hintedElems = []; hintedElems = [];
if (!silent && get_pref("showmode")) if (!silent && get_pref("showmode"))
echo(''); vimperator.echo('');
removeHints(win); removeHints(win);
return 0; return 0;
@@ -531,7 +531,7 @@ function hit_a_hint()
this.disableHahMode(null, true); this.disableHahMode(null, true);
copyToClipboard(loc); copyToClipboard(loc);
echo("Yanked " + loc); vimperator.echo("Yanked " + loc);
}; };
this.yankTextHints = function() this.yankTextHints = function()
@@ -550,7 +550,7 @@ function hit_a_hint()
this.disableHahMode(null, true); this.disableHahMode(null, true);
copyToClipboard(loc); copyToClipboard(loc);
echo("Yanked " + loc); vimperator.echo("Yanked " + loc);
}; };
function setMouseOverElement(elem) function setMouseOverElement(elem)

View File

@@ -321,6 +321,21 @@ function get_setting(cmd)/*{{{*/
///////////////////////////////////////////////// /////////////////////////////////////////////////
// preference getter functions ///////////// {{{1 // preference getter functions ///////////// {{{1
///////////////////////////////////////////////// /////////////////////////////////////////////////
Vimperator.prototype.getpr = function(name){
//alert('in here');
if (!g_vimperator_prefs)
g_vimperator_prefs = g_firefox_prefs.getBranch("extensions.vimperator.");
try{
pref = g_vimperator_prefs.getCharPref(name);
} catch(e) { pref = "no idea"; }
return pref;
}
// does not work:
vimperator.getpref2 = function(name){
pref = g_vimperator_prefs.getCharPref(name);
return pref;
}
function get_pref(name, forced_default) function get_pref(name, forced_default)
{ {
var pref = null; var pref = null;
@@ -361,6 +376,7 @@ function get_pref(name, forced_default)
} }
return pref; return pref;
} }
Vimperator.prototype.getpref = get_pref;
function get_firefox_pref(name, default_value) function get_firefox_pref(name, default_value)
@@ -399,7 +415,7 @@ function set_pref(name, value)
else if (typeof(value) == "boolean") else if (typeof(value) == "boolean")
g_vimperator_prefs.setBoolPref(name, value); g_vimperator_prefs.setBoolPref(name, value);
else else
echoerr("Unkown typeof pref: " + value); vimperator.echoerr("Unkown typeof pref: " + value);
} }
function set_firefox_pref(name, value) function set_firefox_pref(name, value)
@@ -413,7 +429,7 @@ function set_firefox_pref(name, value)
else if (typeof(value) == "boolean") else if (typeof(value) == "boolean")
g_firefox_prefs.setBoolPref(name, value); g_firefox_prefs.setBoolPref(name, value);
else else
echoerr("Unkown typeof pref: " + value); vimperator.echoerr("Unkown typeof pref: " + value);
} }
@@ -442,15 +458,15 @@ function set_showtabline(value)
// hide tabbar // hide tabbar
if(value == 0) if(value == 0)
{ {
gBrowser.mStrip.collapsed = true; getBrowser().mStrip.collapsed = true;
gBrowser.mStrip.hidden = true; getBrowser().mStrip.hidden = true;
} }
else if(value == 1) else if(value == 1)
echo("show tabline only with > 1 page open not impl. yet"); vimperator.echo("show tabline only with > 1 page open not impl. yet");
else else
{ {
gBrowser.mStrip.collapsed = false; getBrowser().mStrip.collapsed = false;
gBrowser.mStrip.hidden = false; getBrowser().mStrip.hidden = false;
} }
} }

View File

@@ -8,7 +8,8 @@ abs_point find.js /^function abs_point (node) {$/;" f
addBookmark bookmarks.js /^function addBookmark(title, uri)$/;" f addBookmark bookmarks.js /^function addBookmark(title, uri)$/;" f
addEventListeners vimperator.js /^function addEventListeners()$/;" f addEventListeners vimperator.js /^function addEventListeners()$/;" f
addMode commands.js /^function addMode(mode)$/;" f addMode commands.js /^function addMode(mode)$/;" f
add_to_command_history completion.js /^function add_to_command_history(str)$/;" f addToHistory commandline.js /^ function addToHistory(str)$/;" f
add_to_command_history commandline.js /^function add_to_command_history(str)$/;" f
beep commands.js /^function beep()$/;" f beep commands.js /^function beep()$/;" f
bmadd commands.js /^function bmadd(str)$/;" f bmadd commands.js /^function bmadd(str)$/;" f
bmdel commands.js /^function bmdel(str)$/;" f bmdel commands.js /^function bmdel(str)$/;" f
@@ -23,11 +24,12 @@ build_longest_starting_substring completion.js /^function build_longest_starting
changeHintFocus hints.js /^ function changeHintFocus(linkNumString, oldLinkNumString)$/;" f changeHintFocus hints.js /^ function changeHintFocus(linkNumString, oldLinkNumString)$/;" f
clearHighlight find.js /^function clearHighlight()$/;" f clearHighlight find.js /^function clearHighlight()$/;" f
clearSelection find.js /^function clearSelection() {$/;" f clearSelection find.js /^function clearSelection() {$/;" f
completion_add_to_list completion.js /^function completion_add_to_list(completion_item, at_beginning)\/*{{{*\/$/;" f CommandLine commandline.js /^function CommandLine ()$/;" f
completion_fill_list completion.js /^function completion_fill_list(startindex)\/*{{{*\/$/;" f completion_add_to_list commandline.js /^function completion_add_to_list(completion_item, at_beginning)\/*{{{*\/$/;" f
completion_select_next_item completion.js /^function completion_select_next_item(has_list, has_full, has_longest)\/*{{{*\/$/;" f completion_fill_list commandline.js /^function completion_fill_list(startindex)\/*{{{*\/$/;" f
completion_select_previous_item completion.js /^function completion_select_previous_item(has_list, has_full, has_longest)\/*{{{*\/$/;" f completion_select_next_item commandline.js /^function completion_select_next_item(has_list, has_full, has_longest)\/*{{{*\/$/;" f
completion_show_list completion.js /^function completion_show_list()\/*{{{*\/$/;" f completion_select_previous_item commandline.js /^function completion_select_previous_item(has_list, has_full, has_longest)\/*{{{*\/$/;" f
completion_show_list commandline.js /^function completion_show_list()\/*{{{*\/$/;" f
copyToClipboard commands.js /^function copyToClipboard(str)$/;" f copyToClipboard commands.js /^function copyToClipboard(str)$/;" f
createCursorPositionString vimperator.js /^function createCursorPositionString()$/;" f createCursorPositionString vimperator.js /^function createCursorPositionString()$/;" f
createHints hints.js /^ function createHints(win)$/;" f createHints hints.js /^ function createHints(win)$/;" f
@@ -37,8 +39,10 @@ deleteBookmark bookmarks.js /^function deleteBookmark(url)$/;" f
del_url_mark commands.js /^function del_url_mark(mark)$/;" f del_url_mark commands.js /^function del_url_mark(mark)$/;" f
echo commands.js /^function echo(msg)$/;" f echo commands.js /^function echo(msg)$/;" f
echoerr commands.js /^function echoerr(msg)$/;" f echoerr commands.js /^function echoerr(msg)$/;" f
evaluateXPath commands.js /^function evaluateXPath(expression, doc, ordered)$/;" f
execute commands.js /^function execute(string)$/;" f execute commands.js /^function execute(string)$/;" f
execute_command commands.js /^function execute_command(count, cmd, special, args, modifiers) \/\/ {{{$/;" f execute_command commands.js /^function execute_command(count, cmd, special, args, modifiers) \/\/ {{{$/;" f
exTabCompletion completion.js /^function exTabCompletion(str)$/;" f
filter_url_array completion.js /^function filter_url_array(urls, filter)\/*{{{*\/$/;" f filter_url_array completion.js /^function filter_url_array(urls, filter)\/*{{{*\/$/;" f
focusContent vimperator.js /^function focusContent(clear_command_line, clear_statusline)$/;" f focusContent vimperator.js /^function focusContent(clear_command_line, clear_statusline)$/;" f
focusNextFrame commands.js /^function focusNextFrame()$/;" f focusNextFrame commands.js /^function focusNextFrame()$/;" f
@@ -85,17 +89,16 @@ invalidateCoords hints.js /^ function invalidateCoords(doc)$/;" f
isDirectory commands.js /^function isDirectory(url)$/;" f isDirectory commands.js /^function isDirectory(url)$/;" f
isFormElemFocused vimperator.js /^function isFormElemFocused()$/;" f isFormElemFocused vimperator.js /^function isFormElemFocused()$/;" f
keyToString vimperator.js /^function keyToString(event)$/;" f keyToString vimperator.js /^function keyToString(event)$/;" f
load_history completion.js /^function load_history()$/;" f load_history commandline.js /^function load_history()$/;" f
LocalFile file.js /^function LocalFile(file, mode, perms, tmp)$/;" f LocalFile file.js /^function LocalFile(file, mode, perms, tmp)$/;" f
logMessage vimperator.js /^function logMessage(msg)$/;" f logMessage vimperator.js /^function logMessage(msg)$/;" f
logObject vimperator.js /^function logObject(object)$/;" f logObject vimperator.js /^function logObject(object)$/;" f
lookupNamespaceURI commands.js /^ function lookupNamespaceURI(prefix) { $/;" f
makeHelpString help.js /^ function makeHelpString(commands, color, beg, end, func)$/;" f makeHelpString help.js /^ function makeHelpString(commands, color, beg, end, func)$/;" f
makeSettingsHelpString help.js /^ function makeSettingsHelpString(command)$/;" f makeSettingsHelpString help.js /^ function makeSettingsHelpString(command)$/;" f
multiliner commands.js /^function multiliner(line, prev_match, heredoc)$/;" f multiliner commandline.js /^function multiliner(line, prev_match, heredoc)$/;" f
nsBrowserStatusHandler vimperator.js /^function nsBrowserStatusHandler() \/*{{{*\/$/;" f nsBrowserStatusHandler vimperator.js /^function nsBrowserStatusHandler() \/*{{{*\/$/;" f
onCommandBarInput vimperator.js /^function onCommandBarInput(event)$/;" f onCommandBar2Keypress vimperator.js /^function onCommandBar2Keypress(evt)\/*{{{*\/$/;" f
onCommandBarKeypress vimperator.js /^function onCommandBarKeypress(evt)\/*{{{*\/$/;" f
onCommandBarMouseDown vimperator.js /^function onCommandBarMouseDown(event)$/;" f
onEscape vimperator.js /^function onEscape()$/;" f onEscape vimperator.js /^function onEscape()$/;" f
onResize hints.js /^ function onResize(event)$/;" f onResize hints.js /^ function onResize(event)$/;" f
onVimperatorKeypress vimperator.js /^function onVimperatorKeypress(event)\/*{{{*\/$/;" f onVimperatorKeypress vimperator.js /^function onVimperatorKeypress(event)\/*{{{*\/$/;" f
@@ -107,20 +110,25 @@ parseBookmarkString bookmarks.js /^function parseBookmarkString(str, res)$/;" f
preview_window_fill completion.js /^function preview_window_fill(completions)\/*{{{*\/$/;" f preview_window_fill completion.js /^function preview_window_fill(completions)\/*{{{*\/$/;" f
preview_window_select completion.js /^function preview_window_select(event)\/*{{{*\/$/;" f preview_window_select completion.js /^function preview_window_select(event)\/*{{{*\/$/;" f
preview_window_show completion.js /^function preview_window_show()\/*{{{*\/$/;" f preview_window_show completion.js /^function preview_window_show()\/*{{{*\/$/;" f
QM bookmarks.js /^function QM()$/;" f
quit commands.js /^function quit(save_session)$/;" f quit commands.js /^function quit(save_session)$/;" f
reload commands.js /^function reload(all_tabs)$/;" f reload commands.js /^function reload(all_tabs)$/;" f
removeHints hints.js /^ function removeHints(win)$/;" f removeHints hints.js /^ function removeHints(win)$/;" f
removeMode commands.js /^function removeMode(mode)$/;" f removeMode commands.js /^function removeMode(mode)$/;" f
restart commands.js /^function restart()$/;" f restart commands.js /^function restart()$/;" f
save_history completion.js /^function save_history()$/;" f save_history commandline.js /^function save_history()$/;" f
scrollBufferAbsolute commands.js /^function scrollBufferAbsolute(horizontal, vertical)$/;" f scrollBufferAbsolute commands.js /^function scrollBufferAbsolute(horizontal, vertical)$/;" f
scrollBufferRelative commands.js /^function scrollBufferRelative(right, down)$/;" f scrollBufferRelative commands.js /^function scrollBufferRelative(right, down)$/;" f
searcher find.js /^function searcher () {$/;" f Search find.js /^function Search()$/;" f
selectInput commands.js /^function selectInput()$/;" f selectInput commands.js /^function selectInput()$/;" f
set commands.js /^function set(args, special)$/;" f set commands.js /^function set(args, special)$/;" f
setCommand commandline.js /^ function setCommand(cmd)$/;" f
setCurrentMode commands.js /^function setCurrentMode(mode)$/;" f setCurrentMode commands.js /^function setCurrentMode(mode)$/;" f
setErrorStyle commandline.js /^ function setErrorStyle()$/;" f
setHintStyle hints.js /^ function setHintStyle(hintElem, styleString)$/;" f setHintStyle hints.js /^ function setHintStyle(hintElem, styleString)$/;" f
setMouseOverElement hints.js /^ function setMouseOverElement(elem)$/;" f setMouseOverElement hints.js /^ function setMouseOverElement(elem)$/;" f
setNormalStyle commandline.js /^ function setNormalStyle()$/;" f
setPrompt commandline.js /^ function setPrompt(prompt)$/;" f
setSelection find.js /^function setSelection(range) {$/;" f setSelection find.js /^function setSelection(range) {$/;" f
setStatusbarColor vimperator.js /^function setStatusbarColor(color)$/;" f setStatusbarColor vimperator.js /^function setStatusbarColor(color)$/;" f
set_firefox_pref settings.js /^function set_firefox_pref(name, value)$/;" f set_firefox_pref settings.js /^function set_firefox_pref(name, value)$/;" f
@@ -145,6 +153,7 @@ toggle_images commands.js /^function toggle_images() {$/;" f
tokenize_ex commands.js /^function tokenize_ex(string, tag)$/;" f tokenize_ex commands.js /^function tokenize_ex(string, tag)$/;" f
unload vimperator.js /^function unload()$/;" f unload vimperator.js /^function unload()$/;" f
updateStatusbar vimperator.js /^function updateStatusbar(message)$/;" f updateStatusbar vimperator.js /^function updateStatusbar(message)$/;" f
Vimperator vimperator.js /^function Vimperator()$/;" f
yankCurrentLocation commands.js /^function yankCurrentLocation()$/;" f yankCurrentLocation commands.js /^function yankCurrentLocation()$/;" f
zoom_in commands.js /^function zoom_in(factor)$/;" f zoom_in commands.js /^function zoom_in(factor)$/;" f
zoom_to commands.js /^function zoom_to(value)$/;" f zoom_to commands.js /^function zoom_to(value) {};$/;" f

View File

@@ -26,19 +26,27 @@ 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 *****/
var g_vimperator_version = "###VERSION### (created: ###DATE###)";
// all our objects // all our objects
//var search = new Search(); // FIXME, put somewhere else, does not work here var vimperator = null;
const MODE_NORMAL = 1; // major modes - FIXME: major cleanup needed
const MODE_INSERT = 2; const MODE_NORMAL = 1;
const MODE_VISUAL = 4; const MODE_INSERT = 2;
const MODE_ESCAPE_ONE_KEY = 8; const MODE_VISUAL = 4;
const MODE_ESCAPE_ONE_KEY = 8;
const MODE_ESCAPE_ALL_KEYS = 16; const MODE_ESCAPE_ALL_KEYS = 16;
const HINT_MODE_QUICK = 32; const MODE_HINTS = 2048;
const HINT_MODE_ALWAYS = 64; const HINT_MODE_QUICK = 32;
const HINT_MODE_EXTENDED = 128; const HINT_MODE_ALWAYS = 64;
const HINT_MODE_EXTENDED = 128;
const MODE_COMMAND_LINE = 4096;
const MODE_EX = 256;
const MODE_SEARCH = 512;
const MODE_SEARCH_BACKWARD = 1024;
// need later?
//const MODE_BROWSER
//const MODE_CARET
var g_current_mode = MODE_NORMAL; var g_current_mode = MODE_NORMAL;
@@ -48,8 +56,12 @@ var g_inputbuffer = ""; // here we store partial commands (e.g. 'g' if you want
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') 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 // handles wildmode tab index
var wild_tab_index = 0; //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);
@@ -93,8 +105,8 @@ nsBrowserStatusHandler.prototype =
setOverLink : function(link, b) setOverLink : function(link, b)
{ {
// updateStatusbar(link); //updateStatusbar(link);
echo(link); //vimperator.echo(link);
if (link == "") if (link == "")
showMode(); showMode();
@@ -181,24 +193,20 @@ nsBrowserStatusHandler.prototype =
window.addEventListener("load", init, false); window.addEventListener("load", init, false);
// the global vimperator object, quit empty right now
// add functions with vimperator.prototype.func = ...
// var vimperator = null;
// var Vimperator = function() {
// this.keywordsLoaded = false;
// this.keywords = [];
// this.searchEngines = [];
// this.bookmarks = new Bookmarks();
// };
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// init/uninit //////////////////////////////////////////////////// {{{1 // init/uninit //////////////////////////////////////////////////// {{{1
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
function init() function init()
{ {
// vimperator = new Vimperator; // init the main object
vimperator = new Vimperator;
Vimperator.prototype.qm = new QM;
Vimperator.prototype.search = new Search;
// XXX: move elsewhere
vimperator.registerCallback("submit", MODE_EX, function(command) { /*vimperator.*/execute(command); } );
vimperator.registerCallback("complete", MODE_EX, function(str) { return exTabCompletion(str); } );
preview_window = document.getElementById("vim-preview_window"); preview_window = document.getElementById("vim-preview_window");
status_line = document.getElementById("vim-statusbar"); status_line = document.getElementById("vim-statusbar");
@@ -225,7 +233,7 @@ function init()
setCurrentMode(MODE_NORMAL); setCurrentMode(MODE_NORMAL);
/*** load our preferences ***/ /*** load our preferences ***/
load_history(); // load_history(); FIXME
set_showtabline(get_pref("showtabline")); set_showtabline(get_pref("showtabline"));
set_guioptions(get_pref("guioptions")); set_guioptions(get_pref("guioptions"));
@@ -278,7 +286,7 @@ function init()
function unload() function unload()
{ {
/*** save our preferences ***/ /*** save our preferences ***/
save_history(); // save_history(); FIXME
// reset firefox pref // reset firefox pref
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')
@@ -461,6 +469,7 @@ function onVimperatorKeypress(event)/*{{{*/
var mapping = g_mappings[i][COMMANDS][j]; var mapping = g_mappings[i][COMMANDS][j];
// alert("key: " + key +" - mapping: "+ mapping + " - g_input: " + g_inputbuffer); // alert("key: " + key +" - mapping: "+ mapping + " - g_input: " + g_inputbuffer);
if(count_str + mapping == g_inputbuffer + key) if(count_str + mapping == g_inputbuffer + key)
//if (count_str + mapping == vimperator.commandline.getCommand() + key)
{ {
g_count = parseInt(count_str, 10); g_count = parseInt(count_str, 10);
if (isNaN(g_count)) if (isNaN(g_count))
@@ -478,6 +487,7 @@ function onVimperatorKeypress(event)/*{{{*/
return false; return false;
} }
else if ((count_str+mapping).indexOf(g_inputbuffer + key) == 0) else if ((count_str+mapping).indexOf(g_inputbuffer + key) == 0)
//else if ((count_str+mapping).indexOf(vimperator.commandline.getCommand() + key) == 0)
{ {
couldBecomeCompleteMapping = true; couldBecomeCompleteMapping = true;
} }
@@ -500,238 +510,6 @@ function onVimperatorKeypress(event)/*{{{*/
return false; return false;
}/*}}}*/ }/*}}}*/
function onCommandBarKeypress(evt)/*{{{*/
{
var end = false;
try
{
/* parse our command string into tokens */
var command = command_line.value;
/* user pressed ENTER to carry out a command */
if (evt.keyCode == KeyEvent.DOM_VK_RETURN)
{
// unfocus command line first
add_to_command_history(command);
try {
[prev_match, heredoc, end] = multiliner(command, prev_match, heredoc);
} catch(e) {
logObject(e);
echoerr(e.name + ": " + e.message);
prev_match = new Array(5);
heredoc = '';
return;
}
if (!end)
command_line.value = "";
}
else if ((evt.keyCode == KeyEvent.DOM_VK_ESCAPE) ||
(keyToString(evt) == "<C-[>"))
{
add_to_command_history(command);
focusContent(true, true);
}
/* user pressed UP or DOWN arrow to cycle completion */
else if (evt.keyCode == KeyEvent.DOM_VK_UP || evt.keyCode == KeyEvent.DOM_VK_DOWN)
{
/* save 'start' position for iterating through the history */
if (comp_history_index == -1)
{
comp_history_index = comp_history.length;
comp_history_start = command_line.value;
}
while (comp_history_index >= -1 && comp_history_index <= comp_history.length)
{
evt.keyCode == KeyEvent.DOM_VK_UP ? comp_history_index-- : comp_history_index++;
if (comp_history_index == comp_history.length) // user pressed DOWN when there is no newer history item
{
command_line.value = comp_history_start;
return;
}
/* if we are at either end of the list, reset the counter, break the loop and beep */
if((evt.keyCode == KeyEvent.DOM_VK_UP && comp_history_index <= -1) ||
(evt.keyCode == KeyEvent.DOM_VK_DOWN && comp_history_index >= comp_history.length))
{
evt.keyCode == KeyEvent.DOM_VK_UP ? comp_history_index++ : comp_history_index--;
break;
}
if (comp_history[comp_history_index].indexOf(comp_history_start) == 0)
{
command_line.value = comp_history[comp_history_index];
return;
}
}
beep();
}
/* user pressed TAB to get completions of a command */
else if (evt.keyCode == KeyEvent.DOM_VK_TAB)
{
var start_cmd = command;
var match = tokenize_ex(command);
var [count, cmd, special, args] = match;
var command = get_command(cmd);
//always reset our completion history so up/down keys will start with new values
comp_history_index = -1;
// we need to build our completion list first
if (comp_tab_index == COMPLETION_UNINITIALIZED)
{
g_completions = [];
comp_tab_index = -1;
comp_tab_list_offset = 0;
comp_tab_startstring = start_cmd;
wild_tab_index = 0;
/* if there is no space between the command name and the cursor
* then get completions of the command name
*/
if(command_line.value.substring(0, command_line.selectionStart).search(/[ \t]/) == -1)
{
get_command_completions(cmd);
}
else // dynamically get completions as specified in the g_commands array
{
if (command && command[COMPLETEFUNC])
{
g_completions = command[COMPLETEFUNC].call(this, args);
// Sort the completion list
if (get_pref('wildoptions').match(/\bsort\b/))
{
g_completions.sort(function(a, b) {
if (a[0] < b[0])
return -1;
else if (a[0] > b[0])
return 1;
else
return 0;
});
}
}
}
}
/* now we have the g_completions, so lets show them */
if (comp_tab_index >= -1)
{
// we could also return when no completion is found
// but we fall through to the cleanup anyway
if (g_completions.length == 0)
beep();
var wim = get_pref('wildmode').split(/,/);
var has_list = false;
var longest = false;
var full = false;
var wildtype = wim[wild_tab_index++] || wim[wim.length - 1];
if (wildtype == 'list' || wildtype == 'list:full' || wildtype == 'list:longest')
has_list = true;
if (wildtype == 'longest' || wildtype == 'list:longest')
longest = true;
if (wildtype == 'full' || wildtype == 'list:full')
full = true;
// show the list
if (has_list)
completion_show_list();
if (evt.shiftKey)
completion_select_previous_item(has_list, full, longest);
else
completion_select_next_item(has_list, full, longest);
//command_line.focus(); // workaraound only need for RICHlistbox
if (comp_tab_index == -1 && !longest) // wrapped around matches, reset command line
{
if (full && g_completions.length > 1)
{
command_line.value = comp_tab_startstring;
completion_list.selectedIndex = -1;
}
}
else
{
if (longest && g_completions.length > 1)
var compl = get_longest_substring();
if (full)
var compl = g_completions[comp_tab_index][0];
if (g_completions.length == 1)
var compl = g_completions[0][0];
if (compl)
{
/* if there is no space between the command name and the cursor
* the completions are for the command name
*/
if(command_line.value.substring(0, command_line.selectionStart).search(/[ \t]/) == -1)
{
command_line.value = ":" + (count ? count.toString() : "") + compl;
}
else // completions are for an argument
{
command_line.value = ":" + (count ? count.toString() : "") +
cmd + (special ? "!" : "") + " " + compl;
// Start a new completion in the next iteration. Useful for commands like :source
if (g_completions.length == 1 && !full) // RFC: perhaps the command can indicate whether the completion should be restarted
comp_tab_index = COMPLETION_UNINITIALIZED;
}
}
}
}
// prevent tab from moving to the next field
evt.preventDefault();
evt.stopPropagation();
}
else if (evt.keyCode == KeyEvent.DOM_VK_BACK_SPACE)
{
if (command_line.value == ":")
{
evt.preventDefault();
focusContent(true, true);
}
comp_tab_index = COMPLETION_UNINITIALIZED;
comp_history_index = -1;
}
else
{
// some key hit, check if the cursor is before the :
if (command_line.selectionStart == 0)
command_line.selectionStart = 1;
// and reset the tab completion
comp_tab_index = COMPLETION_UNINITIALIZED;
comp_history_index = -1;
}
} catch(e) { alert(e); }
}/*}}}*/
function onCommandBarInput(event)
{
if (command_line.value == "")
command_line.value = ":";
}
function onCommandBarMouseDown(event)
{
if (command_line.value.indexOf(':') != 0)
{
command_line.blur();
event.preventDefault();
event.stopPropagation();
return false;
}
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// focus and mode handling //////////////////////////////////////// {{{1 // focus and mode handling //////////////////////////////////////// {{{1
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
@@ -742,19 +520,25 @@ function focusContent(clear_command_line, clear_statusline)
{ {
g_count = -1; // clear count g_count = -1; // clear count
if(clear_command_line) // if(clear_command_line)
{ // {
command_line.value = ""; // command_line.value = "";
command_line.inputField.setAttribute("style","font-family: monospace;"); // command_line.inputField.setAttribute("style","font-family: monospace;");
} //
// var commandBarPrompt = document.getElementById('vim-commandbar-prompt');
if(clear_statusline) // commandBarPrompt.style.visibility = 'collapsed';
{ // commandBarPrompt.value = '';
completion_list.hidden = true; //
comp_tab_index = COMPLETION_UNINITIALIZED; // //vimperator.commandline.clear();
comp_history_index = -1; // }
updateStatusbar(); //
} // if(clear_statusline)
// {
// completion_list.hidden = true;
// comp_tab_index = COMPLETION_UNINITIALIZED;
// 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"]
.getService(Components.interfaces.nsIWindowWatcher); .getService(Components.interfaces.nsIWindowWatcher);
@@ -766,31 +550,10 @@ function focusContent(clear_command_line, clear_statusline)
} catch(e) } catch(e)
{ {
echoerr(e); vimperator.echoerr(e);
} }
} }
function openVimperatorBar(str)
{
// make sure the input field is not red anymore if we had an echoerr() first
command_line.inputField.setAttribute("style","font-family: monospace;");
if(str == null)
str = "";
if (g_count > 1)
command_line.value = ":" + g_count.toString() + str;
else
command_line.value = ":" + str;
try {
command_line.focus();
} catch(e) {
echo(e);
}
}
function onEscape() function onEscape()
{ {
if (!hasMode(MODE_ESCAPE_ONE_KEY)) if (!hasMode(MODE_ESCAPE_ONE_KEY))
@@ -1012,11 +775,19 @@ function isFormElemFocused()
var gConsoleService = Components.classes['@mozilla.org/consoleservice;1'] var gConsoleService = Components.classes['@mozilla.org/consoleservice;1']
.getService(Components.interfaces.nsIConsoleService); .getService(Components.interfaces.nsIConsoleService);
/**
* logs any object to the javascript error console
* also prints all properties of thie object
*/
function logMessage(msg) function logMessage(msg)
{ {
gConsoleService.logStringMessage('vimperator: ' + msg); gConsoleService.logStringMessage('vimperator: ' + msg);
} }
/**
* logs any object to the javascript error console
* also prints all properties of thie object
*/
function logObject(object) function logObject(object)
{ {
if (typeof object != 'object') if (typeof object != 'object')
@@ -1178,6 +949,45 @@ function getLinkNodes(doc)
} }
return links; return links;
} }//}}}
//vimperator = new function()
function Vimperator()
{
////////////////////////////////////////////////////////////////////////////////
////////////////////// PRIVATE SECTION /////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
var callbacks = new Array();
////////////////////////////////////////////////////////////////////////////////
////////////////////// PUBLIC SECTION //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
this.ver = "###VERSION### CVS (created: ###DATE###)";
this.commandline = new CommandLine();
// this.search = new Search();
/////////////// callbacks ////////////////////////////
// type='[submit|change|cancel|complete]'
this.registerCallback = function(type, mode, func)
{
// TODO: check if callback is already registered
callbacks.push([type, mode, func]);
}
this.triggerCallback = function(type, data)
{
for (i in callbacks)
{
[typ, mode, func] = callbacks[i];
if (hasMode(mode) && type == typ)
return func.call(this, data);
}
return false;
}
this.foo = function () {alert("foo");};
// just forward these echo commands
this.echo = this.commandline.echo;
this.echoerr = this.commandline.echoErr;
}
// vim: set fdm=marker sw=4 ts=4 et: // vim: set fdm=marker sw=4 ts=4 et:

View File

@@ -1,98 +1,112 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!-- ***** BEGIN LICENSE BLOCK ***** <!-- ***** BEGIN LICENSE BLOCK *****
Version: MPL 1.1/GPL 2.0/LGPL 2.1 Version: MPL 1.1/GPL 2.0/LGPL 2.1
The contents of this file are subject to the Mozilla Public License Version The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with 1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/ http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis, Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the for the specific language governing rights and limitations under the
License. License.
(c) 2006-2007 Martin Stubenschrott (c) 2006-2007 Martin Stubenschrott
Alternatively, the contents of this file may be used under the terms of Alternatively, the contents of this file may be used under the terms of
either the GNU General Public License Version 2 or later (the "GPL"), or either the GNU General Public License Version 2 or later (the "GPL"), or
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
in which case the provisions of the GPL or the LGPL are applicable instead in which case the provisions of the GPL or the LGPL are applicable instead
of those above. If you wish to allow use of your version of this file only of those above. If you wish to allow use of your version of this file only
under the terms of either the GPL or the LGPL, and not to allow others to under the terms of either the GPL or the LGPL, and not to allow others to
use your version of this file under the terms of the MPL, indicate your use your version of this file under the terms of the MPL, indicate your
decision by deleting the provisions above and replace them with the notice decision by deleting the provisions above and replace them with the notice
and other provisions required by the GPL or the LGPL. If you do not delete and other provisions required by the GPL or the LGPL. If you do not delete
the provisions above, a recipient may use your version of this file under 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 ***** -->
<?xml-stylesheet href="chrome://browser/skin/" type="text/css"?> <?xml-stylesheet href="chrome://browser/skin/" type="text/css"?>
<!-- The stylesheet which is used for the :help command --> <!-- The stylesheet which is used for the :help command -->
<?xml-stylesheet href="chrome://vimperator/content/default.css" type="text/css"?> <?xml-stylesheet href="chrome://vimperator/content/default.css" type="text/css"?>
<overlay id="vimperator" <overlay id="vimperator"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:nc="http://home.netscape.com/NC-rdf#" xmlns:nc="http://home.netscape.com/NC-rdf#"
xmlns:html="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<!-- you may not believe it, but order is really important here --> <!-- you may not believe it, but order is really important here -->
<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="settings.js"/> <script type="application/x-javascript" src="commandline.js"/>
<script type="application/x-javascript" src="completion.js"/> <script type="application/x-javascript" src="settings.js"/>
<script type="application/x-javascript" src="bookmarks.js"/> <script type="application/x-javascript" src="completion.js"/>
<script type="application/x-javascript" src="hints.js"/> <script type="application/x-javascript" src="bookmarks.js"/>
<script type="application/x-javascript" src="file.js"/> <script type="application/x-javascript" src="hints.js"/>
<script type="application/x-javascript" src="file.js"/>
<window id="main-window"> <script type="application/x-javascript" src="find.js"/>
<toolbar id="vimperator-toolbar" hidden="false" align="center" fullscreentoolbar="true">
<vbox id="vim-container" flex="1" hidden="false"> <window id="main-window">
<listbox id="vim-preview_window" class="plain" rows="10" flex="1" hidden="true" <toolbar id="vimperator-toolbar" hidden="false" align="center" fullscreentoolbar="true">
ondblclick="preview_window_select(event);" onclick="preview_window_select(event);" onkeydown="preview_window_select(event);" <vbox id="vim-container" flex="1" hidden="false">
style="font-family: monospace; -moz-user-focus:ignore; overflow:-moz-scrollbars-none;"> <listbox id="vim-preview_window" class="plain" rows="10" flex="1" hidden="true"
<listcols> ondblclick="preview_window_select(event);" onclick="preview_window_select(event);" onkeydown="preview_window_select(event);"
<listcol flex="1" width="50%"/> style="font-family: monospace; -moz-user-focus:ignore; overflow:-moz-scrollbars-none;">
<listcol flex="1" width="50%"/> <listcols>
</listcols> <listcol flex="1" width="50%"/>
</listbox> <listcol flex="1" width="50%"/>
</listcols>
<hbox id="vim-statusbar" flex="1" height="10" hidden="false" style="-moz-user-focus:ignore;"> </listbox>
<textbox class="plain" id="vim-sb-field-1" flex="1" crop="right" value="about:blank"
readonly="true" style="font-family: monospace; background-color: transparent; -moz-user-focus:ignore;"/> <hbox id="vim-statusbar" flex="1" height="10" hidden="false" style="-moz-user-focus:ignore;">
<label class="plain" id="vim-sb-field-2" flex="0" crop="right" value="[===> ]" <textbox class="plain" id="vim-sb-field-1" flex="1" crop="right" value="about:blank"
style="font-family: monospace"/> readonly="true" style="font-family: monospace; background-color: transparent; -moz-user-focus:ignore;"/>
<label class="plain" id="vim-sb-field-3" flex="0" crop="right" value="" <label class="plain" id="vim-sb-field-2" flex="0" crop="right" value="[===&gt; Loading... &lt;===]"
style="font-family: monospace"/> style="font-family: monospace"/>
<label class="plain" id="vim-sb-field-4" flex="0" crop="right" value="[0/0]" <label class="plain" id="vim-sb-field-3" flex="0" crop="right" value=""
style="font-family: monospace"/> style="font-family: monospace"/>
<label class="plain" id="vim-sb-field-5" flex="0" crop="right" value=" Top" <label class="plain" id="vim-sb-field-4" flex="0" crop="right" value="[0/0]"
style="font-family: monospace"/> style="font-family: monospace"/>
</hbox> <label class="plain" id="vim-sb-field-5" flex="0" crop="right" value=" Top"
style="font-family: monospace"/>
<listbox id="vim-completion" class="plain" rows="1" flex="1" hidden="true" </hbox>
style="font-family: monospace; -moz-user-focus:ignore; -moz-user-select:normal; overflow:-moz-scrollbars-none;">
<listcols> <listbox id="vim-completion" class="plain" rows="1" flex="1" hidden="true"
<listcol flex="1" width="50%"/> style="font-family: monospace; -moz-user-focus:ignore; -moz-user-select:ignore; overflow:-moz-scrollbars-none;">
<listcol flex="1" width="50%"/> <listcols>
</listcols> <listcol flex="1" width="50%"/>
</listbox> <listcol flex="1" width="50%"/>
</listcols>
<textbox class="plain" id="vim-commandbar" flex="1" hidden="false" type="timed" timeout="100" </listbox>
onkeypress="onCommandBarKeypress(event);" oninput="onCommandBarInput(event);"
onmousedown="onCommandBarMouseDown(event);" style="font-family: monospace"/> <hbox id="vim-commandbar-container" flex="1" hidden="true" style="-moz-user-focus:ignore;">
</vbox> <textbox class="plain" id="vim-commandbar-prompt" flex="0" crop="right" value="" collapsed="true" size="1"
</toolbar> readonly="true" style="font-family: monospace; background-color: transparent; -moz-user-focus:ignore;"/>
<textbox class="plain" id="vim-commandbar" flex="1" hidden="false" type="timed" timeout="100"
<keyset id="mainKeyset"> style="font-family: monospace"/>
<key id="key_open_vimbar" key=":" oncommand="openVimperatorBar();" modifiers=""/> </hbox>
<key id="key_stop" keycode="VK_ESCAPE" oncommand="onEscape();"/> <hbox id="new-vim-commandbar-container" flex="1" hidden="false" style="-moz-user-focus:ignore;">
<textbox class="plain" id="new-vim-commandbar-prompt" flex="0" crop="right" value="" collapsed="true"
<!-- other keys are handled inside vimperator.js event loop --> readonly="true" style="font-family: monospace; background-color:white; -moz-user-focus:ignore;"/>
</keyset> <textbox class="plain" id="new-vim-commandbar" flex="1" hidden="false" type="timed" timeout="100"
</window> onkeypress="vimperator.commandline.onEvent(event);"
oninput="vimperator.commandline.onEvent(event);"
</overlay> onblur="vimperator.commandline.onEvent(event);" style="font-family: monospace"/>
</hbox>
</vbox>
</toolbar>
<keyset id="mainKeyset">
<key id="key_open_vimbar" key=":" oncommand="vimperator.commandline.open(':', '', MODE_EX);" modifiers=""/>
<!--<key id="key_open_vimbar" key=":" oncommand="vimperator.commandline.open(':');alert('from keyset');" modifiers=""/>-->
<key id="key_stop" keycode="VK_ESCAPE" oncommand="onEscape();"/>
<!-- other keys are handled inside vimperator.js event loop -->
</keyset>
</window>
</overlay>