Skip to content

Commit b5833eb

Browse files
authored
Alternate dialog testing
1 parent 11416de commit b5833eb

2 files changed

Lines changed: 61 additions & 32 deletions

File tree

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
2121
import { RemoteFileDialog } from 'vs/workbench/services/dialogs/electron-browser/remoteFileDialog';
2222
import { WORKSPACE_EXTENSION } from 'vs/platform/workspaces/common/workspaces';
2323
import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts';
24+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2425

2526
interface IMassagedMessageBoxOptions {
2627

@@ -164,7 +165,8 @@ export class FileDialogService implements IFileDialogService {
164165
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
165166
@IHistoryService private readonly historyService: IHistoryService,
166167
@IEnvironmentService private readonly environmentService: IEnvironmentService,
167-
@IInstantiationService private readonly instantiationService: IInstantiationService
168+
@IInstantiationService private readonly instantiationService: IInstantiationService,
169+
@IConfigurationService private readonly configurationService: IConfigurationService,
168170
) { }
169171

170172
defaultFilePath(schemeFilter = this.getSchemeFilterForWindow()): URI | undefined {
@@ -217,16 +219,24 @@ export class FileDialogService implements IFileDialogService {
217219
};
218220
}
219221

222+
private shouldUseSimplified(schema: string): boolean {
223+
return (schema !== Schemas.file) || (this.configurationService.getValue('workbench.dialogs.useSimplified') === 'true');
224+
}
225+
226+
private ensureFileSchema(schema: string): string[] {
227+
return schema !== Schemas.file ? [schema, Schemas.file] : [schema];
228+
}
229+
220230
pickFileFolderAndOpen(options: IPickAndOpenOptions): Promise<any> {
221231
const schema = this.getFileSystemSchema(options);
222232

223233
if (!options.defaultUri) {
224234
options.defaultUri = this.defaultFilePath(schema);
225235
}
226236

227-
if (schema !== Schemas.file) {
237+
if (this.shouldUseSimplified(schema)) {
228238
const title = nls.localize('openFileOrFolder.title', 'Open File Or Folder');
229-
const availableFileSystems = [schema, Schemas.file]; // always allow file as well
239+
const availableFileSystems = this.ensureFileSchema(schema); // always allow file as well
230240
return this.pickRemoteResourceAndOpen({ canSelectFiles: true, canSelectFolders: true, canSelectMany: false, defaultUri: options.defaultUri, title, availableFileSystems }, !!options.forceNewWindow, true);
231241
}
232242

@@ -240,9 +250,9 @@ export class FileDialogService implements IFileDialogService {
240250
options.defaultUri = this.defaultFilePath(schema);
241251
}
242252

243-
if (schema !== Schemas.file) {
253+
if (this.shouldUseSimplified(schema)) {
244254
const title = nls.localize('openFile.title', 'Open File');
245-
const availableFileSystems = [schema, Schemas.file]; // always allow file as well
255+
const availableFileSystems = this.ensureFileSchema(schema); // always allow file as well
246256
return this.pickRemoteResourceAndOpen({ canSelectFiles: true, canSelectFolders: false, canSelectMany: false, defaultUri: options.defaultUri, title, availableFileSystems }, !!options.forceNewWindow, true);
247257
}
248258

@@ -256,9 +266,9 @@ export class FileDialogService implements IFileDialogService {
256266
options.defaultUri = this.defaultFolderPath(schema);
257267
}
258268

259-
if (schema !== Schemas.file) {
269+
if (this.shouldUseSimplified(schema)) {
260270
const title = nls.localize('openFolder.title', 'Open Folder');
261-
const availableFileSystems = [schema, Schemas.file]; // always allow file as well
271+
const availableFileSystems = this.ensureFileSchema(schema); // always allow file as well
262272
return this.pickRemoteResourceAndOpen({ canSelectFiles: false, canSelectFolders: true, canSelectMany: false, defaultUri: options.defaultUri, title, availableFileSystems }, !!options.forceNewWindow, false);
263273
}
264274

@@ -272,12 +282,11 @@ export class FileDialogService implements IFileDialogService {
272282
options.defaultUri = this.defaultWorkspacePath(schema);
273283
}
274284

275-
if (schema !== Schemas.file) {
285+
if (this.shouldUseSimplified(schema)) {
276286
const title = nls.localize('openWorkspace.title', 'Open Workspace');
277287
const filters: FileFilter[] = [{ name: nls.localize('filterName.workspace', 'Workspace'), extensions: [WORKSPACE_EXTENSION] }];
278-
const availableFileSystems = [schema, Schemas.file]; // always allow file as well
288+
const availableFileSystems = this.ensureFileSchema(schema); // always allow file as well
279289
return this.pickRemoteResourceAndOpen({ canSelectFiles: true, canSelectFolders: false, canSelectMany: false, defaultUri: options.defaultUri, title, filters, availableFileSystems }, !!options.forceNewWindow, false);
280-
281290
}
282291

283292
return this.windowService.pickWorkspaceAndOpen(this.toNativeOpenDialogOptions(options));
@@ -294,7 +303,7 @@ export class FileDialogService implements IFileDialogService {
294303

295304
showSaveDialog(options: ISaveDialogOptions): Promise<URI | undefined> {
296305
const schema = this.getFileSystemSchema(options);
297-
if (schema !== Schemas.file) {
306+
if (this.shouldUseSimplified(schema)) {
298307
if (!options.availableFileSystems) {
299308
options.availableFileSystems = [schema]; // by default only allow saving in the own file system
300309
}

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

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class RemoteFileDialog {
4040
private remoteAuthority: string | undefined;
4141
private requiresTrailing: boolean;
4242
private userValue: string;
43+
private scheme: string = REMOTE_HOST_SCHEME;
4344

4445
constructor(
4546
@IFileService private readonly remoteFileService: RemoteFileService,
@@ -56,9 +57,9 @@ export class RemoteFileDialog {
5657
}
5758

5859
public async showOpenDialog(options: IOpenDialogOptions = {}): Promise<IURIToOpen[] | undefined> {
59-
const defaultUri = options.defaultUri ? options.defaultUri : URI.from({ scheme: REMOTE_HOST_SCHEME, authority: this.remoteAuthority, path: '/' });
60-
if (!this.remoteFileService.canHandleResource(defaultUri)) {
61-
this.notificationService.info(nls.localize('remoteFileDialog.notConnectedToRemote', 'File system provider for {0} is not available.', defaultUri.toString()));
60+
this.scheme = options.defaultUri.scheme;
61+
const newOptions = this.getOptions(options);
62+
if (!newOptions) {
6263
return Promise.resolve(undefined);
6364
}
6465

@@ -67,9 +68,7 @@ export class RemoteFileDialog {
6768
const openFileFolderString = nls.localize('remoteFileDialog.localFileFolderFallback', 'Open Local File or Folder');
6869
let tooltip = options.canSelectFiles ? (options.canSelectFolders ? openFileFolderString : openFileString) : openFolderString;
6970
this.fallbackPickerButton = { iconPath: this.getDialogIcons('folder'), tooltip };
70-
const remoteOptions: IOpenDialogOptions = objects.deepClone(options);
71-
remoteOptions.defaultUri = defaultUri;
72-
return this.pickResource(remoteOptions).then(async fileFolderUri => {
71+
return this.pickResource(newOptions).then(async fileFolderUri => {
7372
if (fileFolderUri) {
7473
const stat = await this.remoteFileService.resolveFile(fileFolderUri);
7574
return <IURIToOpen[]>[{ uri: fileFolderUri, typeHint: stat.isDirectory ? 'folder' : 'file' }];
@@ -80,26 +79,38 @@ export class RemoteFileDialog {
8079
}
8180

8281
public showSaveDialog(options: ISaveDialogOptions): Promise<URI | undefined> {
82+
this.scheme = options.defaultUri.scheme;
8383
this.requiresTrailing = true;
84-
const defaultUri = options.defaultUri ? options.defaultUri : URI.from({ scheme: REMOTE_HOST_SCHEME, authority: this.remoteAuthority, path: '/' });
85-
if (!this.remoteFileService.canHandleResource(defaultUri)) {
86-
this.notificationService.info(nls.localize('remoteFileDialog.notConnectedToRemote', 'File system provider for {0} is not available.', defaultUri.toString()));
84+
const newOptions = this.getOptions(options);
85+
if (!newOptions) {
8786
return Promise.resolve(undefined);
8887
}
8988
this.fallbackPickerButton = { iconPath: this.getDialogIcons('folder'), tooltip: nls.localize('remoteFileDialog.localSaveFallback', 'Save Local File') };
90-
const remoteOptions: IOpenDialogOptions = objects.deepClone(options);
91-
remoteOptions.defaultUri = resources.dirname(defaultUri);
92-
remoteOptions.canSelectFolders = true;
93-
remoteOptions.canSelectFiles = true;
89+
newOptions.canSelectFolders = true;
90+
newOptions.canSelectFiles = true;
91+
const filename = resources.basename(newOptions.defaultUri);
92+
newOptions.defaultUri = resources.dirname(newOptions.defaultUri);
9493
return new Promise<URI | undefined>((resolve) => {
95-
this.pickResource(remoteOptions, resources.basename(defaultUri)).then(folderUri => {
94+
this.pickResource(newOptions, filename).then(folderUri => {
9695
resolve(folderUri);
9796
});
9897
});
9998
}
10099

100+
private getOptions(options: ISaveDialogOptions | IOpenDialogOptions): IOpenDialogOptions | undefined {
101+
const defaultUri = options.defaultUri ? options.defaultUri : URI.from({ scheme: REMOTE_HOST_SCHEME, authority: this.remoteAuthority, path: '/' });
102+
if (!this.remoteFileService.canHandleResource(defaultUri)) {
103+
this.notificationService.info(nls.localize('remoteFileDialog.notConnectedToRemote', 'File system provider for {0} is not available.', defaultUri.toString()));
104+
return undefined;
105+
}
106+
const newOptions: IOpenDialogOptions = objects.deepClone(options);
107+
newOptions.defaultUri = defaultUri;
108+
return newOptions;
109+
}
110+
101111
private remoteUriFrom(path: string): URI {
102-
return URI.from({ scheme: REMOTE_HOST_SCHEME, authority: this.remoteAuthority, path });
112+
path = path.replace(/\\/g, '/');
113+
return URI.from({ scheme: this.scheme, authority: this.remoteAuthority, path });
103114
}
104115

105116
private async pickResource(options: IOpenDialogOptions, trailing?: string): Promise<URI | undefined> {
@@ -149,7 +160,7 @@ export class RemoteFileDialog {
149160
});
150161

151162
this.filePickBox.title = options.title;
152-
this.filePickBox.value = this.labelService.getUriLabel(this.currentFolder);
163+
this.filePickBox.value = this.pathFromUri(this.currentFolder);
153164
this.filePickBox.items = [];
154165
this.filePickBox.onDidAccept(_ => {
155166
if (isAcceptHandled || this.filePickBox.busy) {
@@ -169,12 +180,12 @@ export class RemoteFileDialog {
169180
isAcceptHandled = false;
170181
});
171182

172-
this.filePickBox.onDidChangeValue(value => {
183+
this.filePickBox.onDidChangeValue(async value => {
173184
if (value !== this.userValue) {
174185
const trimmedPickBoxValue = ((this.filePickBox.value.length > 1) && this.endsWithSlash(this.filePickBox.value)) ? this.filePickBox.value.substr(0, this.filePickBox.value.length - 1) : this.filePickBox.value;
175186
const valueUri = this.remoteUriFrom(trimmedPickBoxValue);
176187
if (!resources.isEqual(this.currentFolder, valueUri)) {
177-
this.tryUpdateItems(value, valueUri);
188+
await this.tryUpdateItems(value, valueUri);
178189
}
179190
this.setActiveItems(value);
180191
this.userValue = value;
@@ -327,7 +338,7 @@ export class RemoteFileDialog {
327338

328339
private updateItems(newFolder: URI, trailing?: string) {
329340
this.currentFolder = newFolder;
330-
this.filePickBox.value = trailing ? this.labelService.getUriLabel(resources.joinPath(newFolder, trailing)) : this.labelService.getUriLabel(newFolder, { endWithSeparator: true });
341+
this.filePickBox.value = trailing ? this.pathFromUri(resources.joinPath(newFolder, trailing)) : this.pathFromUri(newFolder, true);
331342
this.filePickBox.busy = true;
332343
this.createItems(this.currentFolder).then(items => {
333344
this.filePickBox.items = items;
@@ -338,6 +349,15 @@ export class RemoteFileDialog {
338349
});
339350
}
340351

352+
private pathFromUri(uri: URI, endWithSeparator: boolean = false): string {
353+
const sep = this.labelService.getSeparator(uri.scheme, uri.authority);
354+
let result = uri.fsPath.replace(/\//g, sep);
355+
if (endWithSeparator && !this.endsWithSlash(result)) {
356+
result = result + sep;
357+
}
358+
return result;
359+
}
360+
341361
private isValidBaseName(name: string): boolean {
342362
if (!name || name.length === 0 || /^\s+$/.test(name)) {
343363
return false; // require a name that is not just whitespace
@@ -372,8 +392,8 @@ export class RemoteFileDialog {
372392
}
373393

374394
private basenameWithTrailingSlash(fullPath: URI): string {
375-
const child = this.labelService.getUriLabel(fullPath, { endWithSeparator: true });
376-
const parent = this.labelService.getUriLabel(resources.dirname(fullPath), { endWithSeparator: true });
395+
const child = this.pathFromUri(fullPath, true);
396+
const parent = this.pathFromUri(resources.dirname(fullPath), true);
377397
return child.substring(parent.length);
378398
}
379399

0 commit comments

Comments
 (0)