changeset 12:e32b90567f39

Update menu when reopening a tab Creating a tab changes the focused tab in the destination window, thus the menu item representing the destination window needs to be updated.
author Guido Berhoerster <guido+tab-mover@berhoerster.name>
date Mon, 20 Feb 2017 18:07:00 +0100
parents 5d7914307782
children e4391e12b799
files background.js
diffstat 1 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/background.js	Mon Feb 20 17:40:31 2017 +0100
+++ b/background.js	Mon Feb 20 18:07:00 2017 +0100
@@ -366,23 +366,33 @@
     }
 
     onMenuItemClicked(info, tab) {
+        var windowId = parseInt(info.menuItemId);
+
         if (info.parentMenuItemId === 'move-menu') {
             // move tab from the current window to the selected window
             browser.tabs.move(tab.id, {
-                windowId: parseInt(info.menuItemId),
+                windowId,
                 index: -1
             }).catch(error => {
                 console.log('Error:', error);
             });
         } else {
-            // open the URL of the current tab in the selected window and close
-            // the current tab
+            // open the URL of the current tab in the destination window
             browser.tabs.create({
                 url: tab.url,
-                windowId: parseInt(info.menuItemId),
+                windowId,
                 index: -1
             }).then(newTab => {
+                // close the current tab
                 return browser.tabs.remove(tab.id);
+            }).then(() => {
+                // get the new title of the destination window
+                return browser.tabs.query({
+                    active: true,
+                    windowId
+                });
+            }).then(tabs => {
+                this.model.updateWindowTitle(windowId, tabs[0].title)
             }).catch(error => {
                 console.log('Error:', error);
             });