addons/firefox-addons/tab-mover

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 Feb 20 18:07:00 2017 +0100 (2017-02-20)
parents 5d7914307782
children e4391e12b799
files background.js
line diff
     1.1 --- a/background.js	Mon Feb 20 17:40:31 2017 +0100
     1.2 +++ b/background.js	Mon Feb 20 18:07:00 2017 +0100
     1.3 @@ -366,23 +366,33 @@
     1.4      }
     1.5  
     1.6      onMenuItemClicked(info, tab) {
     1.7 +        var windowId = parseInt(info.menuItemId);
     1.8 +
     1.9          if (info.parentMenuItemId === 'move-menu') {
    1.10              // move tab from the current window to the selected window
    1.11              browser.tabs.move(tab.id, {
    1.12 -                windowId: parseInt(info.menuItemId),
    1.13 +                windowId,
    1.14                  index: -1
    1.15              }).catch(error => {
    1.16                  console.log('Error:', error);
    1.17              });
    1.18          } else {
    1.19 -            // open the URL of the current tab in the selected window and close
    1.20 -            // the current tab
    1.21 +            // open the URL of the current tab in the destination window
    1.22              browser.tabs.create({
    1.23                  url: tab.url,
    1.24 -                windowId: parseInt(info.menuItemId),
    1.25 +                windowId,
    1.26                  index: -1
    1.27              }).then(newTab => {
    1.28 +                // close the current tab
    1.29                  return browser.tabs.remove(tab.id);
    1.30 +            }).then(() => {
    1.31 +                // get the new title of the destination window
    1.32 +                return browser.tabs.query({
    1.33 +                    active: true,
    1.34 +                    windowId
    1.35 +                });
    1.36 +            }).then(tabs => {
    1.37 +                this.model.updateWindowTitle(windowId, tabs[0].title)
    1.38              }).catch(error => {
    1.39                  console.log('Error:', error);
    1.40              });