From 4a0e9bfd84c0e2ecc6bf85fe74660018980dd412 Mon Sep 17 00:00:00 2001 From: Doug Kearns Date: Mon, 28 Sep 2009 17:49:24 +1000 Subject: [PATCH] Add :tabreattach. The name is not very convincing. --- common/content/liberator.js | 5 +++++ common/content/tabs.js | 37 +++++++++++++++++++++++++++++++ vimperator/NEWS | 1 + vimperator/locale/en-US/index.txt | 1 + vimperator/locale/en-US/tabs.txt | 10 +++++++++ xulmus/locale/en-US/index.txt | 1 + xulmus/locale/en-US/tabs.txt | 10 +++++++++ 7 files changed, 65 insertions(+) diff --git a/common/content/liberator.js b/common/content/liberator.js index f4f6e320..fb47c4d4 100644 --- a/common/content/liberator.js +++ b/common/content/liberator.js @@ -897,6 +897,11 @@ const liberator = (function () //{{{ context.keys = { text: function (item) item.getAttribute("toolbarname"), description: function () "" }; context.completions = buffer.evaluateXPath("./*[@toolbarname]", document, toolbox); }; + + completion.window = function window(context) { + context.title = ["Window", "Title"] + context.completions = [[i, win.document.title] for ([i, win] in Iterator(liberator.windows))]; + }; }); /////////////////////////////////////////////////////////////////////////////}}} diff --git a/common/content/tabs.js b/common/content/tabs.js index fec81609..a449f325 100644 --- a/common/content/tabs.js +++ b/common/content/tabs.js @@ -617,6 +617,43 @@ function Tabs() //{{{ bang: true, count: true }); + + // TODO: match window by title too? + // : accept the full :tabmove arg spec for the tab index arg? + // : better name or merge with :tabmove? + commands.add(["tabrea[ttach]"], + "Reattach the current tab to another window", + function (args) + { + if (args.length > 2 || args.some(function (i) i && !/^\d+$/.test(i))) + return void liberator.echoerr("E488: Trailing characters"); + + let [winIndex, tabIndex] = args; + let win = liberator.windows[winIndex]; + + if (!win) + return void liberator.echoerr("Window " + winIndex + " does not exist"); + else if (win == window) + return void liberator.echoerr("Can't reattach to the same window"); + + let browser = win.getBrowser(); + let dummy = browser.addTab("about:blank"); + let last = browser.mTabs.length - 1; + + browser.moveTabTo(dummy, util.Math.constrain(tabIndex || last, 0, last)); + browser.selectedTab = dummy; // required + browser.stop(); + browser.docShell; + browser.swapBrowsersAndCloseOther(dummy, getBrowser().mCurrentTab); + }, + { + argCount: "+", + completer: function (context, args) + { + if (args.completeArg == 0) + completion.window(context); + } + }); } if (liberator.has("tabs_undo")) diff --git a/vimperator/NEWS b/vimperator/NEWS index f97e7c9e..47e745ed 100644 --- a/vimperator/NEWS +++ b/vimperator/NEWS @@ -19,6 +19,7 @@ know if I like copying bugs) * IMPORTANT: 'popups' now takes a stringlist rather than a number. + * add [c]:tabattach[c] * add [c]:keepalt[c] * add [c]:styledisable[c], [c]:styleenable[c], and [c]:styletoggle[c] * add [c]:sanitize[c], 'sanitizetimespan' and 'sanitizeitems' diff --git a/vimperator/locale/en-US/index.txt b/vimperator/locale/en-US/index.txt index bbe9757a..edf9b649 100644 --- a/vimperator/locale/en-US/index.txt +++ b/vimperator/locale/en-US/index.txt @@ -259,6 +259,7 @@ section::Ex{nbsp}commands[ex-cmd-index,:index] ||[c]:tabonly[c]|| Close all other tabs + ||[c]:tabopen[c]|| Open one or more URLs in a new tab + ||[c]:tabprevious[c]|| Switch to the previous tab or go [count] tabs back + +||[c]:tabreattach[c]|| Reattach the current tab to another window + ||[c]:tabrewind[c]|| Switch to the first tab + ||[c]:time[c]|| Profile a piece of code or run a command multiple times + ||[c]toolbarhide[c]|| Hide the named toolbar + diff --git a/vimperator/locale/en-US/tabs.txt b/vimperator/locale/en-US/tabs.txt index ad7562ad..3ce5fc03 100644 --- a/vimperator/locale/en-US/tabs.txt +++ b/vimperator/locale/en-US/tabs.txt @@ -160,6 +160,16 @@ contain at least one tab it is not possible to detach the only tab in a window. Use [c]:tabduplicate[c] to copy the tab then call [c]:tabdetach[c]. ________________________________________________________________________________ + +|:tabrea| |:tabreattach| +||:tabrea[ttach] {window-index} [tab-index]|| + +________________________________________________________________________________ +Reattach the current tab to another window. {window-index} is an index into the +list of open windows and [a][tab-index][a] is the index at which to insert the +tab in the other window's tab list. If this is the last tab in a window, the +window will be closed. +________________________________________________________________________________ + section::Reordering{nbsp}tabs[reordering-tabs] |:tabm| |:tabmove| diff --git a/xulmus/locale/en-US/index.txt b/xulmus/locale/en-US/index.txt index 5776bc09..8cf923a1 100644 --- a/xulmus/locale/en-US/index.txt +++ b/xulmus/locale/en-US/index.txt @@ -305,6 +305,7 @@ section::Ex{nbsp}commands[ex-cmd-index,:index] ||[c]:tabonly[c]|| Close all other tabs + ||[c]:tabopen[c]|| Open one or more URLs in a new tab + ||[c]:tabprevious[c]|| Switch to the previous tab or go [count] tabs back + +||[c]:tabreattach[c]|| Reattach the current tab to another window + ||[c]:tabrewind[c]|| Switch to the first tab + ||[c]:time[c]|| Profile a piece of code or run a command multiple times + ||[c]toolbarhide[c]|| Hide the named toolbar + diff --git a/xulmus/locale/en-US/tabs.txt b/xulmus/locale/en-US/tabs.txt index 0fcf2bc6..590be804 100644 --- a/xulmus/locale/en-US/tabs.txt +++ b/xulmus/locale/en-US/tabs.txt @@ -151,6 +151,16 @@ contain at least one tab it is not possible to detach the only tab in a window. Use [c]:tabduplicate[c] to copy the tab then call [c]:tabdetach[c]. ________________________________________________________________________________ + +|:tabrea| |:tabreattach| +||:tabrea[ttach] {window-index} [tab-index]|| + +________________________________________________________________________________ +Reattach the current tab to another window. {window-index} is an index into the +list of open windows and [a][tab-index][a] is the index at which to insert the +tab in the other window's tab list. If this is the last tab in a window, the +window will be closed. +________________________________________________________________________________ + section::Reordering{nbsp}tabs[reordering-tabs] |:tabm| |:tabmove|