@@ -194,6 +194,16 @@ var gProfiles = {
194194 } ) ;
195195 } ,
196196
197+ async openTabsInProfile ( aEvent , tabsToOpen ) {
198+ let profile = await SelectableProfileService . getProfile (
199+ aEvent . target . getAttribute ( "profileid" )
200+ ) ;
201+ SelectableProfileService . launchInstance (
202+ profile ,
203+ tabsToOpen . map ( tab => tab . linkedBrowser . currentURI . spec )
204+ ) ;
205+ } ,
206+
197207 async handleCommand ( aEvent ) {
198208 switch ( aEvent . target . id ) {
199209 /* App menu button events */
@@ -247,6 +257,16 @@ var gProfiles = {
247257 this . launchProfile ( aEvent . sourceEvent ) ;
248258 break ;
249259 }
260+ case "Profiles:MoveTabsToProfile" : {
261+ let tabs ;
262+ if ( TabContextMenu . contextTab . multiselected ) {
263+ tabs = gBrowser . selectedTabs ;
264+ } else {
265+ tabs = [ TabContextMenu . contextTab ] ;
266+ }
267+ this . openTabsInProfile ( aEvent . sourceEvent , tabs ) ;
268+ break ;
269+ }
250270 }
251271 /* Subpanel profile events that may be triggered in FxA menu or app menu */
252272 if ( aEvent . target . classList . contains ( "profile-item" ) ) {
@@ -427,4 +447,50 @@ var gProfiles = {
427447 profilesList . appendChild ( button ) ;
428448 }
429449 } ,
450+
451+ async populateMoveTabMenu ( menuPopup ) {
452+ if ( ! SelectableProfileService . initialized ) {
453+ return ;
454+ }
455+
456+ const profiles = await SelectableProfileService . getAllProfiles ( ) ;
457+ const currentProfile = SelectableProfileService . currentProfile ;
458+
459+ const separator = document . getElementById ( "moveTabSeparator" ) ;
460+ separator . hidden = profiles . length < 2 ;
461+
462+ let existingItems = [
463+ ...menuPopup . querySelectorAll ( ":scope > menuitem[profileid]" ) ,
464+ ] ;
465+
466+ for ( let profile of profiles ) {
467+ if ( profile . id === currentProfile . id ) {
468+ continue ;
469+ }
470+
471+ let menuitem = existingItems . shift ( ) ;
472+ let isNewItem = ! menuitem ;
473+ if ( isNewItem ) {
474+ menuitem = document . createXULElement ( "menuitem" ) ;
475+ menuitem . setAttribute ( "tbattr" , "tabbrowser-multiple-visible" ) ;
476+ menuitem . setAttribute ( "data-l10n-id" , "move-to-new-profile" ) ;
477+ menuitem . setAttribute ( "command" , "Profiles:MoveTabsToProfile" ) ;
478+ }
479+
480+ menuitem . disabled = false ;
481+ menuitem . setAttribute ( "profileid" , profile . id ) ;
482+ menuitem . setAttribute (
483+ "data-l10n-args" ,
484+ JSON . stringify ( { profileName : profile . name } )
485+ ) ;
486+
487+ if ( isNewItem ) {
488+ menuPopup . appendChild ( menuitem ) ;
489+ }
490+ }
491+ // If there's any old item to remove, do so now.
492+ for ( let remaining of existingItems ) {
493+ remaining . remove ( ) ;
494+ }
495+ } ,
430496} ;
0 commit comments