comparison 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
comparison
equal deleted inserted replaced
11:5d7914307782 12:e32b90567f39
364 364
365 this.model.focusWindow(windowId); 365 this.model.focusWindow(windowId);
366 } 366 }
367 367
368 onMenuItemClicked(info, tab) { 368 onMenuItemClicked(info, tab) {
369 var windowId = parseInt(info.menuItemId);
370
369 if (info.parentMenuItemId === 'move-menu') { 371 if (info.parentMenuItemId === 'move-menu') {
370 // move tab from the current window to the selected window 372 // move tab from the current window to the selected window
371 browser.tabs.move(tab.id, { 373 browser.tabs.move(tab.id, {
372 windowId: parseInt(info.menuItemId), 374 windowId,
373 index: -1 375 index: -1
374 }).catch(error => { 376 }).catch(error => {
375 console.log('Error:', error); 377 console.log('Error:', error);
376 }); 378 });
377 } else { 379 } else {
378 // open the URL of the current tab in the selected window and close 380 // open the URL of the current tab in the destination window
379 // the current tab
380 browser.tabs.create({ 381 browser.tabs.create({
381 url: tab.url, 382 url: tab.url,
382 windowId: parseInt(info.menuItemId), 383 windowId,
383 index: -1 384 index: -1
384 }).then(newTab => { 385 }).then(newTab => {
386 // close the current tab
385 return browser.tabs.remove(tab.id); 387 return browser.tabs.remove(tab.id);
388 }).then(() => {
389 // get the new title of the destination window
390 return browser.tabs.query({
391 active: true,
392 windowId
393 });
394 }).then(tabs => {
395 this.model.updateWindowTitle(windowId, tabs[0].title)
386 }).catch(error => { 396 }).catch(error => {
387 console.log('Error:', error); 397 console.log('Error:', error);
388 }); 398 });
389 } 399 }
390 } 400 }