From 1704adc33453c6c6c4cdd7a04b24bdfb9f2724da Mon Sep 17 00:00:00 2001 From: Martin Stubenschrott Date: Sun, 24 Aug 2008 22:10:30 +0000 Subject: [PATCH] added :tabdetach, thanks Kris --- AUTHORS | 1 + Donators | 4 +++ NEWS | 1 + content/tabs.js | 78 ++++++++++++++++++++++++++++--------------- locale/en-US/tabs.txt | 20 +++++++++-- 5 files changed, 75 insertions(+), 29 deletions(-) diff --git a/AUTHORS b/AUTHORS index 72cc7699..2523e35d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -24,6 +24,7 @@ Patches (in no special order): * Lee Hinman (:open ./.. support) * Bart Trojanowski (Makefile) * Hannes Rist (:set titlestring support) + * Kris Maglione * Nikolai Weibull ($VIMPERATOR_HOME) * Joseph Xu (supporting multiple top level windows better) * Raimon Grau Cuscó (document relationship navigation - ]], [[) diff --git a/Donators b/Donators index f440507a..d7666f52 100644 --- a/Donators +++ b/Donators @@ -1,7 +1,11 @@
 Note: If you don't wish to appear on this list when making a donation, please tell me.
+Also drop me a note, if you want the donated amount to be displayed.
 
 2008:
+* Alexander Klink
+* Chaz McGarvey
+* Jesse Hathaway
 * Takayuki Tsukitani
 * Victor Nemkov
 * John Lusth
diff --git a/NEWS b/NEWS
index 5bac2996..60340eb5 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
 
 2008-08-16:
     * version 2.0 (probably)
+    * add :tabdetach command
     * new ;b extended hint mode (thanks Daniel Schaffrath)
     * many bug fixes
 
diff --git a/content/tabs.js b/content/tabs.js
index 6fafe267..f08712c7 100644
--- a/content/tabs.js
+++ b/content/tabs.js
@@ -94,6 +94,18 @@ liberator.Tabs = function () //{{{
         return position;
     }
 
+    function copyTab(to, from)
+    {
+        var ss = Components.classes["@mozilla.org/browser/sessionstore;1"].
+                 getService(Components.interfaces.nsISessionStore);
+
+        if (!from)
+            from = getBrowser().mTabContainer.selectedItem;
+
+        var tabState = ss.getTabState(from);
+        ss.setTabState(to, tabState);
+    }
+
     // hide tabs initially
     if (liberator.config.name == "Vimperator")
         getBrowser().mStrip.getElementsByClassName("tabbrowser-tabs")[0].collapsed = true;
@@ -471,6 +483,15 @@ liberator.Tabs = function () //{{{
             },
             { completer: function (filter) { return liberator.completion.url(filter); } });
 
+
+        liberator.commands.add(["tabde[tach]"],
+            "Detach current tab to its own window",
+            function (args, special, count)
+            {
+                liberator.tabs.detachTab(null);
+            },
+            { argCount: "0" });
+
         liberator.commands.add(["tabd[uplicate]"],
             "Duplicate current tab",
             function (args, special, count)
@@ -526,7 +547,6 @@ liberator.Tabs = function () //{{{
                     var completions = [];
                     for (var i = 0; i < undoItems.length; i++)
                     {
-                        // undoItems[i].image is also available if needed for favicons
                         var url = undoItems[i].state.entries[0].url;
                         var title = undoItems[i].title;
                         if (liberator.completion.match([url, title], filter, false))
@@ -879,42 +899,48 @@ liberator.Tabs = function () //{{{
 
         cloneTab: function (tab, activate)
         {
-            var ss = Components.classes["@mozilla.org/browser/sessionstore;1"].
-                     getService(Components.interfaces.nsISessionStore);
-
-            if (!tab)
-                tab = getBrowser().mTabContainer.selectedItem;
-
-            var tabState = ss.getTabState(tab);
             var newTab = getBrowser().addTab();
-            ss.setTabState(newTab, tabState);
+            copyTab(newTab, tab);
+
             if (activate)
                 getBrowser().mTabContainer.selectedItem = newTab;
 
             return newTab;
         },
 
+        detachTab: function (tab)
+        {
+            if (!tab)
+                tab = getBrowser().mTabContainer.selectedItem;
+
+            window.open();
+            var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+                .getService(Components.interfaces.nsIWindowMediator);
+            var win = wm.getMostRecentWindow("navigator:browser");
+
+            copyTab(win.getBrowser().mCurrentTab, tab);
+            this.remove(tab, 1, false, 1);
+        },
+
         selectAlternateTab: function ()
         {
-          if (liberator.tabs.alternate == null || liberator.tabs.getTab() == liberator.tabs.alternate)
-          {
-            liberator.echoerr("E23: No alternate page");
-            return;
-          }
+            if (liberator.tabs.alternate == null || liberator.tabs.getTab() == liberator.tabs.alternate)
+            {
+                liberator.echoerr("E23: No alternate page");
+                return;
+            }
 
-          // NOTE: this currently relies on v.tabs.index() returning the
-          // currently selected tab index when passed null
-          var index = liberator.tabs.index(liberator.tabs.alternate);
+            // NOTE: this currently relies on v.tabs.index() returning the
+            // currently selected tab index when passed null
+            var index = liberator.tabs.index(liberator.tabs.alternate);
 
-          // TODO: since a tab close is more like a bdelete for us we
-          // should probably reopen the closed tab when a 'deleted'
-          // alternate is selected
-          if (index == -1)
-            liberator.echoerr("E86: Buffer does not exist");  // TODO: This should read "Buffer N does not exist"
-          else
-            liberator.tabs.select(index);
-
-          return;
+            // TODO: since a tab close is more like a bdelete for us we
+            // should probably reopen the closed tab when a 'deleted'
+            // alternate is selected
+            if (index == -1)
+                liberator.echoerr("E86: Buffer does not exist");  // TODO: This should read "Buffer N does not exist"
+            else
+                liberator.tabs.select(index);
         },
 
         // NOTE: when restarting a session FF selects the first tab and then the
diff --git a/locale/en-US/tabs.txt b/locale/en-US/tabs.txt
index ba9b9ba5..88644bff 100644
--- a/locale/en-US/tabs.txt
+++ b/locale/en-US/tabs.txt
@@ -31,6 +31,13 @@ support it, currently:
 * [c]:tab downloads[c]
 ________________________________________________________________________________
 
+|:tabd[uplicate]| +
+|:[count]:tab[duplicate]
+________________________________________________________________________________
+Duplicate the current tab and switch to the duplicate. If [count] is given,
+duplicate the tab [count] times.
+________________________________________________________________________________
+
 //TODO: should the tab commands be moved back here?
 See help::open[browsing.html#opening] for other ways to open new tabs.
 
@@ -113,13 +120,20 @@ Switch to the last tab.
 ________________________________________________________________________________
 
 
+|:tabde[tach]| +
+||:tabde[tach]||
+________________________________________________________________________________
+Detach the current tab, and open it in its own window.
+________________________________________________________________________________
+
+
 |:tabm| |:tabmove|
 ||:tabm[ove] [N]|| +
 ||:tabm[ove][!] +N | -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. N can also be
-prefixed with "+" or "-" to indicate a relative movement. If [!] is
+Move the current tab to a position 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. 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.
 ________________________________________________________________________________