Skip to content

Commit a660498

Browse files
committed
Backup and restore last used remote for explorer
1 parent 12b7d0a commit a660498

2 files changed

Lines changed: 28 additions & 14 deletions

File tree

src/vs/workbench/contrib/remote/browser/explorerViewItems.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import { attachSelectBoxStyler, attachStylerCallback } from 'vs/platform/theme/c
1313
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
1414
import { SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme';
1515
import { 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';
1717
import { ISelectOptionItem } from 'vs/base/browser/ui/selectBox/selectBox';
1818
import { IViewDescriptor } from 'vs/workbench/common/views';
1919
import { startsWith } from 'vs/base/common/strings';
2020
import { isStringArray } from 'vs/base/common/types';
2121
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
22+
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
2223

2324
export 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');

src/vs/workbench/services/remote/common/remoteExplorerService.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
import { Event, Emitter } from 'vs/base/common/event';
77
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
88
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
9+
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
910

1011
export const IRemoteExplorerService = createDecorator<IRemoteExplorerService>('remoteExplorerService');
12+
export const REMOTE_EXPLORER_TYPE_KEY: string = 'remote.explorerType';
1113

1214
export interface IRemoteExplorerService {
1315
_serviceBrand: undefined;
@@ -21,9 +23,13 @@ class RemoteExplorerService implements IRemoteExplorerService {
2123
private _onDidChangeTargetType: Emitter<string> = new Emitter<string>();
2224
public onDidChangeTargetType: Event<string> = this._onDidChangeTargetType.event;
2325

26+
constructor(@IStorageService private readonly storageService: IStorageService) { }
27+
2428
set targetType(name: string) {
2529
if (this._targetType !== name) {
2630
this._targetType = name;
31+
this.storageService.store(REMOTE_EXPLORER_TYPE_KEY, this._targetType, StorageScope.WORKSPACE);
32+
this.storageService.store(REMOTE_EXPLORER_TYPE_KEY, this._targetType, StorageScope.GLOBAL);
2733
this._onDidChangeTargetType.fire(this._targetType);
2834
}
2935
}

0 commit comments

Comments
 (0)