diff --git a/ChangeLog b/ChangeLog index 26f5f82e..4214a7c9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@
 2007-05-02:
 	* version ???
+	* many help fixes (most of them by Doug Kearns)
+	* new :reloadall command
 	* :hardcopy works now and shows the printing dialog
 	* changed "R" to reload without cache instead of reload all due to popular request
 	* changed secure sites -> green, broken sites -> red in the statusbar
diff --git a/chrome/content/vimperator/commands.js b/chrome/content/vimperator/commands.js
index 7c7a5aae..00c28340 100644
--- a/chrome/content/vimperator/commands.js
+++ b/chrome/content/vimperator/commands.js
@@ -69,7 +69,7 @@ var g_commands = [/*{{{*/
         ["{count}bd[elete][!]"],
         "Delete current buffer (=tab)",
         "Count WILL be supported in future releases, then :2bd removes two tabs and the one the right is selected.
Do :bdelete! to select the tab to the left after removing the current tab.", - function (args, special, count) { tab_remove (count, special, 0); }, + function (args, special, count) { vimperator.tabs.remove(getBrowser().mCurrentTab, count, special, 0); }, null ], [ @@ -302,7 +302,7 @@ var g_commands = [/*{{{*/ ["q[uit]"], "Quit current tab or quit Vimperator if this was the last tab", "When quitting Vimperator, the session is not stored.", - function (args) { tab_remove(1, false, 1); }, + function (args) { vimperator.tabs.remove(getBrowser().mCurrentTab, 1, false, 1); }, null ], [ @@ -317,8 +317,16 @@ var g_commands = [/*{{{*/ ["re[load]"], ["re[load][!]"], "Reload current page", - "Forces reloading of the current page. If ! is given, byepass cache.", - function(args, special) { if (special) BrowserReloadSkipCache(); else reload(special); }, // FIXME + "Forces reloading of the current page. If ! is given, skip the cache.", + function(args, special) { reload(getBrowser().mCurrentTab, special); }, + null + ], + [ + ["reloada[ll]"], + ["reloada[ll][!]"], + "Reload all pages", + "Forces reloading of all pages. If ! is given, skip the cache.", + function(args, special) { reload_all(special); }, null ], [ @@ -384,7 +392,7 @@ var g_commands = [/*{{{*/ ["tabn[ext]"], "Switch to the next tab", "Cycles to the first tab, when the last is selected.", - function(args, special, count) { tab_go(0); }, + function(args, special, count) { vimperator.tabs.select("+1", true); }, null ], [ @@ -401,15 +409,16 @@ var g_commands = [/*{{{*/ ["tabo[nly]"], "Close all other tabs", null, - function() { getBrowser().removeAllTabsBut(getBrowser().mCurrentTab); }, + function() { vimperator.tabs.removeAllOthers(getBrowser().mCurrentTab); }, null ], [ - ["tabm[ove]"], - ["tabm[ove] [N]"], + ["tabmove", "tabm"], + ["tabm[ove] [N]", "tabm[ove][!] [+|-N]"], "Move the current tab after tab N", - "When N is 0 the current tab is made the first one. Without N the current tab is made the last one.", - tab_move, + "When N is 0 the current tab is made the first one. Without N the current tab is made the last one. " + + "N can also be prefixed with '+' or '-' to indicate a relative movement. If ! is specified the movement wraps around the start or end of the tab list.", + function(args, special) { vimperator.tabs.move(getBrowser().mCurrentTab, args, special); }, null ], [ @@ -417,7 +426,7 @@ var g_commands = [/*{{{*/ ["tabp[revious]", "tabN[ext]"], "Switch to the previous tab", "Cycles to the last tab, when the first is selected.", - function(args, count) { tab_go(-1); }, + function(args, count) { vimperator.tabs.select("-1", true); }, null ], [ @@ -425,7 +434,7 @@ var g_commands = [/*{{{*/ ["tabr[ewind]", "tabfir[st]"], "Switch to the first tab", null, - function(args, count) { tab_go(1); }, + function(args, count) { vimperator.tabs.select(0, false); }, null ], [ @@ -433,7 +442,7 @@ var g_commands = [/*{{{*/ ["tabl[ast]"], "Switch to the last tab", null, - function(args, count) { tab_go(getBrowser().mTabs.length); }, + function(args, count) { vimperator.tabs.select("$", false); }, null ], [ @@ -541,14 +550,14 @@ var g_mappings = [/*{{{*/ ["{count}d"], "Delete current buffer (=tab)", "Count WILL be supported in future releases, then 2d removes two tabs and the one the right is selected.", - function(count) { tab_remove(count, false, 0); } + function(count) { vimperator.tabs.remove(getBrowser().mCurrentTab, count, false, 0); } ], [ ["D"], ["{count}D"], "Delete current buffer (=tab)", "Count WILL be supported in future releases, then 2D removes two tabs and the one the left is selected.", - function(count) { tab_remove(count, true, 0); } + function(count) { vimperator.tabs.remove(getBrowser().mCurrentTab, count, true, 0); } ], /*[ ["ge"], @@ -585,7 +594,7 @@ var g_mappings = [/*{{{*/ "Go to next tab", "Cycles to the first tab, when the last is selected.
"+ "Count is supported, 3gt goes to the third tab.", - function(count) { tab_go(count > 0 ? count : 0); } + function(count) { vimperator.tabs.select(count > 0 ? count -1: "+1", count > 0 ? false : true); } ], [ ["gT", "", ""], @@ -593,7 +602,7 @@ var g_mappings = [/*{{{*/ "Go to previous tab", "Cycles to the last tab, when the first is selected.
"+ "Count is supported, 3gt goes to the third tab.", - function(count) { tab_go(count > 0 ? count :-1); } + function(count) { vimperator.tabs.select(count > 0 ? count -1: "-1", count > 0 ? false : true); } ], [ ["o"], @@ -629,14 +638,14 @@ var g_mappings = [/*{{{*/ ["r"], "Reload", "Forces reloading of the current page.", - function(count) { reload(false); } + function(count) { reload(getBrowser().mCurrentTab, false); } ], [ ["R"], ["R"], - "Reload all", - "Forces reloading of all open pages.", - function(count) { BrowserReloadSkipCache(); } + "Reload skipping the cache", + "Forces reloading of the current page skipping the cache.", + function(count) { reload(getBrowser().mCurrentTab, true); } ], [ ["t"], @@ -1061,14 +1070,14 @@ var g_hint_mappings = [ /*{{{*/ ["", "scrollBufferRelative(0, -1);", false, true], ["", "scrollBufferRelative(1, 0);", false, true], /* tab managment */ - ["", "tab_go(0)", true, true], // same as gt, but no count supported - ["", "tab_go(-1)", true, true], + ["", "vimperator.tabs.select('+1', true)", true, true], // same as gt, but no count supported + ["", "vimperator.tabs.select('-1', true)", true, true], /* navigation */ ["", "stepInHistory(g_count > 0 ? -1 * g_count : -1);", false, true], ["", "stepInHistory(g_count > 0 ? g_count : 1);", false, true], ["", "stepInHistory(g_count > 0 ? -1 * g_count : -1);", false, true], ["", "stepInHistory(g_count > 0 ? g_count : 1);", false, true], - ["", "tab_remove(g_count, false, 0);", true, true], + ["", "vimperator.tabs.remove(getBrowser().mCurrentTab, g_count, false, 0);", true, true], /* cancel hint mode keys */ ["", "", true, true], ["", "", true, true], @@ -1414,6 +1423,7 @@ function isDirectory(url) else return false; } + //////////////////////////////////////////////////////////////////////// // frame related functions //////////////////////////////////////// {{{1 //////////////////////////////////////////////////////////////////////// @@ -1635,66 +1645,16 @@ function tab() execute(arguments[0], null, null, {inTab: true}); } -/* if index = 0, advance on tab - * if index < 0, go one tab to the left - * otherwise, jump directly to tab - */ -function tab_go(index) -{ - if (index < 0) - getBrowser().mTabContainer.advanceSelectedTab(-1, true); - else if (index == 0) - getBrowser().mTabContainer.advanceSelectedTab(1, true); - else - { - if (getBrowser().mTabs.length < index) - beep(); - else - getBrowser().mTabContainer.selectedIndex = index-1; - } -} - -/* quit_on_last_tab = 1: quit without saving session - quit_on_last_tab = 2: quit and save session - */ -function tab_remove(count, focus_left_tab, quit_on_last_tab) -{ - if (count < 1) count = 1; - - if (quit_on_last_tab >= 1 && getBrowser().mTabs.length <= count) - quit(quit_on_last_tab == 2); - - var tab = getBrowser().mCurrentTab; - if(focus_left_tab && tab.previousSibling) - gBrowser.mTabContainer.selectedIndex--; - getBrowser().removeTab(tab); -} - -function tab_move(position) -{ - if (!position.match(/^(\d+|)$/)) - { - vimperator.echoerr("E488: Trailing characters"); - return; - } - - var last = getBrowser().mTabs.length - 1; - if (position == "" || position > last) - position = last; - - getBrowser().moveTabTo(getBrowser().mCurrentTab, parseInt(position)); -} - function buffer_switch(string) { var match; if (match = string.match(/^(\d+):?/)) - return tab_go(match[1]); + return vimperator.tabs.select(parseInt(match[1]) - 1, false); // make it zero-based for (var i = 0; i < getBrowser().browsers.length; i++) { var url = getBrowser().getBrowserAtIndex(i).contentDocument.location.href; if (url == string) - return tab_go(i); + return vimperator.tabs.select(i, false); } } @@ -1878,12 +1838,40 @@ function quit(save_session) goQuitApplication(); } -function reload(all_tabs) +function reload(tab, bypass_cache) { - if (all_tabs) - getBrowser().reloadAllTabs(); + if (bypass_cache) + { + const nsIWebNavigation = Components.interfaces.nsIWebNavigation; + const flags = nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY | nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE; + getBrowser().getBrowserForTab(tab).reloadWithFlags(flags); + } else - BrowserReload(); + { + getBrowser().reloadTab(tab); + } +} + +function reload_all(bypass_cache) +{ + if (bypass_cache) + { + for (var i = 0; i < getBrowser().mTabs.length; i++) + { + try + { + reload(getBrowser().mTabs[i], bypass_cache) + } + catch (e) { + // FIXME: can we do anything useful here without stopping the + // other tabs from reloading? + } + } + } + else + { + getBrowser().reloadAllTabs(); + } } function restart() diff --git a/chrome/content/vimperator/vimperator.js b/chrome/content/vimperator/vimperator.js index bee70383..e930bab5 100644 --- a/chrome/content/vimperator/vimperator.js +++ b/chrome/content/vimperator/vimperator.js @@ -1101,17 +1101,76 @@ function Vimperator() // provides functions for working with tabs function Tabs() { + //////////////////////////////////////////////////////////////////////////////// + ////////////////////// PRIVATE SECTION ///////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + /* spec can either be an absolute integer + * or "" for the current tab + * or "+1" for the next tab + * or "-3" for the tab, which is 3 positions left of the current + * or "$" for the last tab + */ + function indexFromSpec(spec, wrap) + { + var position = getBrowser().tabContainer.selectedIndex; + var length = getBrowser().mTabs.length; + var last = length - 1; + + if (typeof(spec) === "undefined" || spec === "") + return position; + + if (typeof(spec) === "number") + position = spec; + else if (spec === "$") + return last; + else if (!spec.match(/^([+-]?\d+|)$/)) + { + // TODO: move error reporting to ex-command? + vimperator.echoerr("E488: Trailing characters"); + return false; + } + else + { + if (spec.match(/^([+-]\d+)$/)) // relative position +/-N + position += parseInt(spec); + else // absolute position + position = parseInt(spec); + } + + if (position > last) + position = wrap ? position % length : last; + else if (position < 0) + position = wrap ? (position % length) + length: 0; + + return position; + } + + function indexFromTab(tab) + { + var length = getBrowser().mTabs.length; + for (var i = 0; i < length; i++) + { + if (getBrowser().mTabs[i] == tab) + return i; + } + return false; + } + + //////////////////////////////////////////////////////////////////////////////// + ////////////////////// PUBLIC SECTION ////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// // @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; + return getBrowser().mTabs.length; } + // TODO: implement filter + // @returns an array of buffers which match filter this.get = function(filter) { var buffers = []; @@ -1125,5 +1184,51 @@ function Tabs() } return buffers; } + + /* position == '' moves the tab to the last position as per Vim + * wrap causes the movement to wrap around the start and end of the tab list + * NOTE: position is a 0 based index + * FIXME: tabmove! N should probably produce an error + */ + this.move = function(tab, spec, wrap) + { + if (spec === "") + spec = "$"; // if not specified, move to the last tab -> XXX: move to ex handling? + + var index = indexFromSpec(spec, false); // XXX: really no wrap? + getBrowser().moveTabTo(tab, index); + } + + this.select = function(spec, wrap) + { + var index = indexFromSpec(spec, wrap); + if (index === false) + { + beep(); // XXX: move to ex-handling? + return false; + } + getBrowser().mTabContainer.selectedIndex = index; + } + + /* quit_on_last_tab = 1: quit without saving session + * quit_on_last_tab = 2: quit and save session + */ + this.remove = function(tab, count, focus_left_tab, quit_on_last_tab) + { + if (count < 1) count = 1; + + if (quit_on_last_tab >= 1 && getBrowser().mTabs.length <= count) + quit(quit_on_last_tab == 2); + + if(focus_left_tab && tab.previousSibling) + this.select("-1", false); + + getBrowser().removeTab(tab); + } + + this.removeAllOthers = function(tab) + { + getBrowser().removeAllTabsBut(tab); + } } // vim: set fdm=marker sw=4 ts=4 et: diff --git a/chrome/content/vimperator/vimperator.xul b/chrome/content/vimperator/vimperator.xul index cb89100c..98b6c4b7 100644 --- a/chrome/content/vimperator/vimperator.xul +++ b/chrome/content/vimperator/vimperator.xul @@ -83,7 +83,7 @@ the terms of any one of the MPL, the GPL or the LGPL.