Skip to content

Commit 79c115a

Browse files
Benjamin Paseroalexr00
andauthored
File dialog: IEnvironmentService#userHome is deprecated (microsoft#95219)
Part of microsoft#94506 Co-authored-by: Alex Ross <alros@microsoft.com>
1 parent e2bcc4d commit 79c115a

4 files changed

Lines changed: 66 additions & 10 deletions

File tree

src/vs/workbench/services/dialogs/browser/abstractFileDialogService.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,21 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
218218
}
219219

220220
private pickResource(options: IOpenDialogOptions): Promise<URI | undefined> {
221-
const simpleFileDialog = this.instantiationService.createInstance(SimpleFileDialog);
221+
const simpleFileDialog = this.createSimpleFileDialog();
222222

223223
return simpleFileDialog.showOpenDialog(options);
224224
}
225225

226226
private saveRemoteResource(options: ISaveDialogOptions): Promise<URI | undefined> {
227-
const remoteFileDialog = this.instantiationService.createInstance(SimpleFileDialog);
227+
const remoteFileDialog = this.createSimpleFileDialog();
228228

229229
return remoteFileDialog.showSaveDialog(options);
230230
}
231231

232+
protected createSimpleFileDialog(): SimpleFileDialog {
233+
return this.instantiationService.createInstance(SimpleFileDialog);
234+
}
235+
232236
protected getSchemeFilterForWindow(): string {
233237
return !this.environmentService.configuration.remoteAuthority ? Schemas.file : REMOTE_HOST_SCHEME;
234238
}

src/vs/workbench/services/dialogs/browser/simpleFileDialog.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class SimpleFileDialog {
108108
private remoteAuthority: string | undefined;
109109
private requiresTrailing: boolean = false;
110110
private trailing: string | undefined;
111-
private scheme: string = REMOTE_HOST_SCHEME;
111+
protected scheme: string = REMOTE_HOST_SCHEME;
112112
private contextKey: IContextKey<boolean>;
113113
private userEnteredPathSegment: string = '';
114114
private autoCompletePathSegment: string = '';
@@ -133,9 +133,9 @@ export class SimpleFileDialog {
133133
@IFileDialogService private readonly fileDialogService: IFileDialogService,
134134
@IModelService private readonly modelService: IModelService,
135135
@IModeService private readonly modeService: IModeService,
136-
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
136+
@IWorkbenchEnvironmentService protected readonly environmentService: IWorkbenchEnvironmentService,
137137
@IRemoteAgentService private readonly remoteAgentService: IRemoteAgentService,
138-
@IRemotePathService private readonly remotePathService: IRemotePathService,
138+
@IRemotePathService protected readonly remotePathService: IRemotePathService,
139139
@IKeybindingService private readonly keybindingService: IKeybindingService,
140140
@IContextKeyService contextKeyService: IContextKeyService,
141141
) {
@@ -231,11 +231,8 @@ export class SimpleFileDialog {
231231
return this.remoteAgentEnvironment;
232232
}
233233

234-
private async getUserHome(): Promise<URI> {
235-
if (this.scheme !== Schemas.file) {
236-
return this.remotePathService.userHome;
237-
}
238-
return this.environmentService.userHome!;
234+
protected async getUserHome(): Promise<URI> {
235+
return (await this.remotePathService.userHome) ?? URI.from({ scheme: this.scheme, authority: this.remoteAuthority, path: '/' });
239236
}
240237

241238
private async pickResource(isSave: boolean = false): Promise<URI | undefined> {

src/vs/workbench/services/dialogs/electron-browser/fileDialogService.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import { Schemas } from 'vs/base/common/network';
2222
import { IModeService } from 'vs/editor/common/services/modeService';
2323
import { IWorkspacesService } from 'vs/platform/workspaces/common/workspaces';
2424
import { ILabelService } from 'vs/platform/label/common/label';
25+
import { SimpleFileDialog } from 'vs/workbench/services/dialogs/browser/simpleFileDialog';
26+
import { NativeSimpleFileDialog } from 'vs/workbench/services/dialogs/electron-browser/simpleFileDialog';
2527

2628
export class FileDialogService extends AbstractFileDialogService implements IFileDialogService {
2729

@@ -190,6 +192,10 @@ export class FileDialogService extends AbstractFileDialogService implements IFil
190192
// Don't allow untitled schema through.
191193
return schema === Schemas.untitled ? [Schemas.file] : (schema !== Schemas.file ? [schema, Schemas.file] : [schema]);
192194
}
195+
196+
protected createSimpleFileDialog(): SimpleFileDialog {
197+
return this.instantiationService.createInstance(NativeSimpleFileDialog);
198+
}
193199
}
194200

195201
registerSingleton(IFileDialogService, FileDialogService, true);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { URI } from 'vs/base/common/uri';
7+
import { SimpleFileDialog } from 'vs/workbench/services/dialogs/browser/simpleFileDialog';
8+
import { Schemas } from 'vs/base/common/network';
9+
import { IFileService } from 'vs/platform/files/common/files';
10+
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
11+
import { ILabelService } from 'vs/platform/label/common/label';
12+
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
13+
import { INotificationService } from 'vs/platform/notification/common/notification';
14+
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
15+
import { IModelService } from 'vs/editor/common/services/modelService';
16+
import { IModeService } from 'vs/editor/common/services/modeService';
17+
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
18+
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
19+
import { IRemotePathService } from 'vs/workbench/services/path/common/remotePathService';
20+
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
21+
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
22+
import { INativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-browser/environmentService';
23+
24+
export class NativeSimpleFileDialog extends SimpleFileDialog {
25+
constructor(
26+
@IFileService fileService: IFileService,
27+
@IQuickInputService quickInputService: IQuickInputService,
28+
@ILabelService labelService: ILabelService,
29+
@IWorkspaceContextService workspaceContextService: IWorkspaceContextService,
30+
@INotificationService notificationService: INotificationService,
31+
@IFileDialogService fileDialogService: IFileDialogService,
32+
@IModelService modelService: IModelService,
33+
@IModeService modeService: IModeService,
34+
@IWorkbenchEnvironmentService protected environmentService: INativeWorkbenchEnvironmentService,
35+
@IRemoteAgentService remoteAgentService: IRemoteAgentService,
36+
@IRemotePathService protected remotePathService: IRemotePathService,
37+
@IKeybindingService keybindingService: IKeybindingService,
38+
@IContextKeyService contextKeyService: IContextKeyService
39+
) {
40+
super(fileService, quickInputService, labelService, workspaceContextService, notificationService, fileDialogService, modelService, modeService, environmentService, remoteAgentService, remotePathService, keybindingService, contextKeyService);
41+
}
42+
43+
protected async getUserHome(): Promise<URI> {
44+
if (this.scheme !== Schemas.file) {
45+
return super.getUserHome();
46+
}
47+
return this.environmentService.userHome;
48+
}
49+
}

0 commit comments

Comments
 (0)