@@ -504,7 +504,15 @@ webui.SideBarView = function(mainView, noEventHandlers) {
504504 } )
505505 }
506506
507- self . changeContext = function ( ) {
507+ self . changeContextGet = function ( ) {
508+ $ . get ( "contexts" , function ( contextList ) {
509+ var contexts = JSON . parse ( contextList ) ;
510+ self . changeContext ( contexts ) ;
511+ } ) ;
512+ }
513+
514+ self . changeContext = function ( contexts ) {
515+
508516 function removePopup ( popup ) {
509517 $ ( popup ) . children ( ".modal-fade" ) . modal ( "hide" ) ;
510518 $ ( ".modal-backdrop" ) . remove ( ) ;
@@ -533,12 +541,20 @@ webui.SideBarView = function(mainView, noEventHandlers) {
533541 $ (
534542 '<div class="">' +
535543 '<h6>Select context for Git Source Control</h6>' +
536- '<select class="custom-select">' +
537- '<option selected>context!</option>' +
544+ '<select id="chosenContext" class="custom-select">' +
538545 '</select>' +
539546 '</div>'
540547 ) . appendTo ( popupBody ) ;
541548
549+ var selectDropdown = $ ( ".custom-select" , popupBody ) [ 0 ] ;
550+
551+ contexts . forEach ( function ( context ) {
552+ $ (
553+ '<option value="' + context + '" ' + ( context == self . currentContext ? "selected" : "" ) + ' >' + context + '</option>'
554+ ) . appendTo ( selectDropdown ) ;
555+ } )
556+
557+
542558 var popupFooter = $ ( ".modal-footer" , popup ) [ 0 ] ;
543559 webui . detachChildren ( popupFooter ) ;
544560
@@ -552,9 +568,36 @@ webui.SideBarView = function(mainView, noEventHandlers) {
552568 $ ( '#changeContextModal' ) . find ( '#cancelContextBtn' , '.close' ) . click ( function ( ) {
553569 removePopup ( popup ) ;
554570 } ) ;
571+
572+ $ ( "#chooseContextBtn" ) . on ( "click" , function ( ) {
573+ self . updateContext ( $ ( "#chosenContext" ) . val ( ) ) ;
574+ } ) ;
575+ }
576+
577+ self . getCurrentContext = function ( ) {
578+ var urlParts = window . location . href . split ( "/" ) ;
579+ if ( urlParts [ urlParts . length - 1 ] == "" ) {
580+ // return namespace as context
581+ return urlParts [ urlParts . length - 2 ] ;
582+ } else {
583+ // return package as context
584+ return urlParts [ urlParts . length - 1 ] ;
585+ }
586+ }
587+
588+ self . updateContext = function ( context ) {
589+ var urlParts = window . location . href . split ( "/" ) ;
590+ if ( context . indexOf ( ".ZPM" ) != - 1 ) {
591+ urlParts [ urlParts . length - 1 ] = context ;
592+ } else {
593+ urlParts [ urlParts . length - 1 ] = "" ;
594+ urlParts [ urlParts . length - 2 ] = context ;
595+ }
596+
597+ window . location = urlParts . join ( "/" ) ;
598+ self . currentContext = context ;
555599 }
556600
557-
558601 self . checkoutBranch = function ( branchType , refName ) {
559602 $ ( "#confirm-branch-checkout" ) . remove ( ) ;
560603
@@ -877,8 +920,10 @@ webui.SideBarView = function(mainView, noEventHandlers) {
877920 $ ( ".btn-add" , self . element ) . click ( self . createNewLocalBranch ) ;
878921 $ ( '.btn-prune-remote-branches' , self . element ) . click ( self . pruneRemoteBranches ) ;
879922 $ ( "#sidebar-settings" , self . element ) . click ( self . goToSettingsPage ) ;
880- $ ( "#sidebar-context" , self . element ) . click ( self . changeContext ) ;
923+ $ ( "#sidebar-context" , self . element ) . click ( self . changeContextGet ) ;
881924 }
925+
926+ self . currentContext = self . getCurrentContext ( ) ;
882927 self . getPackageVersion ( ) ;
883928 self . fetchSection ( $ ( "#sidebar-local-branches" , self . element ) [ 0 ] , "Local Branches" , "local-branches" , "branch --verbose --verbose" ) ;
884929 self . fetchSection ( $ ( "#sidebar-remote-branches" , self . element ) [ 0 ] , "Remote Branches" , "remote-branches" , "branch --remotes" ) ;
0 commit comments