@@ -13,12 +13,13 @@ import { attachSelectBoxStyler, attachStylerCallback } from 'vs/platform/theme/c
1313import { IContextViewService } from 'vs/platform/contextview/browser/contextView' ;
1414import { SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme' ;
1515import { selectBorder } from 'vs/platform/theme/common/colorRegistry' ;
16- import { IRemoteExplorerService } from 'vs/workbench/services/remote/common/remoteExplorerService' ;
16+ import { IRemoteExplorerService , REMOTE_EXPLORER_TYPE_KEY } from 'vs/workbench/services/remote/common/remoteExplorerService' ;
1717import { ISelectOptionItem } from 'vs/base/browser/ui/selectBox/selectBox' ;
1818import { IViewDescriptor } from 'vs/workbench/common/views' ;
1919import { startsWith } from 'vs/base/common/strings' ;
2020import { isStringArray } from 'vs/base/common/types' ;
2121import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService' ;
22+ import { IStorageService , StorageScope } from 'vs/platform/storage/common/storage' ;
2223
2324export interface IRemoteSelectItem extends ISelectOptionItem {
2425 authority : string [ ] ;
@@ -34,7 +35,8 @@ export class SwitchRemoteViewItem extends SelectActionViewItem {
3435 @IThemeService private readonly themeService : IThemeService ,
3536 @IContextViewService contextViewService : IContextViewService ,
3637 @IRemoteExplorerService remoteExplorerService : IRemoteExplorerService ,
37- @IWorkbenchEnvironmentService environmentService : IWorkbenchEnvironmentService
38+ @IWorkbenchEnvironmentService environmentService : IWorkbenchEnvironmentService ,
39+ @IStorageService private readonly storageService : IStorageService
3840 ) {
3941 super ( null , action , optionsItems , 0 , contextViewService , { ariaLabel : nls . localize ( 'remotes' , 'Switch Remote' ) } ) ;
4042 this . _register ( attachSelectBoxStyler ( this . selectBox , themeService , {
@@ -45,26 +47,32 @@ export class SwitchRemoteViewItem extends SelectActionViewItem {
4547 }
4648
4749 private setSelectionForConnection ( optionsItems : IRemoteSelectItem [ ] , environmentService : IWorkbenchEnvironmentService , remoteExplorerService : IRemoteExplorerService ) {
48- // TODO: set from saved state
4950 if ( this . optionsItems . length > 0 ) {
50- const remoteAuthority = environmentService . configuration . remoteAuthority ;
5151 let index = 0 ;
52- if ( remoteAuthority ) {
53- const actualRemoteAuthority = remoteAuthority . split ( '+' ) [ 0 ] ;
54- for ( let optionIterator = 0 ; ( optionIterator < this . optionsItems . length ) && ( index === 0 ) ; optionIterator ++ ) {
55- for ( let authorityIterator = 0 ; authorityIterator < optionsItems [ optionIterator ] . authority . length ; authorityIterator ++ ) {
56- if ( optionsItems [ optionIterator ] . authority [ authorityIterator ] === actualRemoteAuthority ) {
57- index = optionIterator ;
58- break ;
59- }
60- }
61- }
52+ const remoteAuthority = environmentService . configuration . remoteAuthority ;
53+ const explorerType : string | undefined = remoteAuthority ? remoteAuthority . split ( '+' ) [ 0 ] :
54+ this . storageService . get ( REMOTE_EXPLORER_TYPE_KEY , StorageScope . WORKSPACE ) ?? this . storageService . get ( REMOTE_EXPLORER_TYPE_KEY , StorageScope . GLOBAL ) ;
55+ if ( explorerType ) {
56+ index = this . getOptionIndexForExplorerType ( optionsItems , explorerType ) ;
6257 }
6358 this . select ( index ) ;
6459 remoteExplorerService . targetType = optionsItems [ index ] . authority [ 0 ] ;
6560 }
6661 }
6762
63+ private getOptionIndexForExplorerType ( optionsItems : IRemoteSelectItem [ ] , explorerType : string ) : number {
64+ let index = 0 ;
65+ for ( let optionIterator = 0 ; ( optionIterator < this . optionsItems . length ) && ( index === 0 ) ; optionIterator ++ ) {
66+ for ( let authorityIterator = 0 ; authorityIterator < optionsItems [ optionIterator ] . authority . length ; authorityIterator ++ ) {
67+ if ( optionsItems [ optionIterator ] . authority [ authorityIterator ] === explorerType ) {
68+ index = optionIterator ;
69+ break ;
70+ }
71+ }
72+ }
73+ return index ;
74+ }
75+
6876 render ( container : HTMLElement ) {
6977 super . render ( container ) ;
7078 dom . addClass ( container , 'switch-remote' ) ;
0 commit comments