Mercurial > addons > firefox-addons > tab-mover
diff background.js @ 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 | 6b4680867e49 |
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); });