mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 17:22:48 -05:00
Merge from vscode 2b0b9136329c181a9e381463a1f7dc3a2d105a34 (#4880)
This commit is contained in:
@@ -12,7 +12,7 @@ import { URI } from 'vs/base/common/uri';
|
||||
import { isWindows } from 'vs/base/common/platform';
|
||||
import { ISaveDialogOptions, IOpenDialogOptions, IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
|
||||
import { REMOTE_HOST_SCHEME } from 'vs/platform/remote/common/remoteHosts';
|
||||
import { IWindowService, IURIToOpen, FileFilter } from 'vs/platform/windows/common/windows';
|
||||
import { IWindowService } from 'vs/platform/windows/common/windows';
|
||||
import { ILabelService } from 'vs/platform/label/common/label';
|
||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
@@ -40,7 +40,6 @@ export class RemoteFileDialog {
|
||||
private options: IOpenDialogOptions;
|
||||
private currentFolder: URI;
|
||||
private filePickBox: IQuickPick<FileQuickPickItem>;
|
||||
private filters: FileFilter[] | undefined;
|
||||
private hidden: boolean;
|
||||
private allowFileSelection: boolean;
|
||||
private allowFolderSelection: boolean;
|
||||
@@ -71,7 +70,7 @@ export class RemoteFileDialog {
|
||||
this.contextKey = RemoteFileDialogContext.bindTo(contextKeyService);
|
||||
}
|
||||
|
||||
public async showOpenDialog(options: IOpenDialogOptions = {}): Promise<IURIToOpen[] | undefined> {
|
||||
public async showOpenDialog(options: IOpenDialogOptions = {}): Promise<URI | undefined> {
|
||||
this.scheme = this.getScheme(options.defaultUri, options.availableFileSystems);
|
||||
const newOptions = await this.getOptions(options);
|
||||
if (!newOptions) {
|
||||
@@ -85,14 +84,7 @@ export class RemoteFileDialog {
|
||||
let fallbackLabel = options.canSelectFiles ? (options.canSelectFolders ? openFileFolderString : openFileString) : openFolderString;
|
||||
this.fallbackListItem = this.getFallbackFileSystem(fallbackLabel);
|
||||
|
||||
return this.pickResource().then(async fileFolderUri => {
|
||||
if (fileFolderUri) {
|
||||
const stat = await this.fileService.resolve(fileFolderUri);
|
||||
return <IURIToOpen[]>[{ uri: fileFolderUri, typeHint: stat.isDirectory ? 'folder' : 'file' }];
|
||||
|
||||
}
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
return this.pickResource();
|
||||
}
|
||||
|
||||
public async showSaveDialog(options: ISaveDialogOptions): Promise<URI | undefined> {
|
||||
@@ -195,7 +187,7 @@ export class RemoteFileDialog {
|
||||
this.filePickBox.buttons = [this.acceptButton];
|
||||
this.filePickBox.onDidTriggerButton(_ => {
|
||||
// accept button
|
||||
const resolveValue = this.remoteUriFrom(this.filePickBox.value);
|
||||
const resolveValue = this.addPostfix(this.remoteUriFrom(this.filePickBox.value));
|
||||
this.validate(resolveValue).then(validated => {
|
||||
if (validated) {
|
||||
isResolving = true;
|
||||
@@ -323,6 +315,7 @@ export class RemoteFileDialog {
|
||||
}
|
||||
|
||||
if (resolveValue) {
|
||||
resolveValue = this.addPostfix(resolveValue);
|
||||
if (await this.validate(resolveValue)) {
|
||||
return Promise.resolve(resolveValue);
|
||||
}
|
||||
@@ -387,6 +380,32 @@ export class RemoteFileDialog {
|
||||
}
|
||||
}
|
||||
|
||||
private addPostfix(uri: URI): URI {
|
||||
let result = uri;
|
||||
if (this.requiresTrailing && this.options.filters && this.options.filters.length > 0) {
|
||||
// Make sure that the suffix is added. If the user deleted it, we automatically add it here
|
||||
let hasExt: boolean = false;
|
||||
const currentExt = resources.extname(uri).substr(1);
|
||||
if (currentExt !== '') {
|
||||
for (let i = 0; i < this.options.filters.length; i++) {
|
||||
for (let j = 0; j < this.options.filters[i].extensions.length; j++) {
|
||||
if ((this.options.filters[i].extensions[j] === '*') || (this.options.filters[i].extensions[j] === currentExt)) {
|
||||
hasExt = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasExt) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!hasExt) {
|
||||
result = resources.joinPath(resources.dirname(uri), resources.basename(uri) + '.' + this.options.filters[0].extensions[0]);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private async validate(uri: URI): Promise<boolean> {
|
||||
let stat: IFileStat | undefined;
|
||||
let statDirname: IFileStat | undefined;
|
||||
@@ -545,11 +564,11 @@ export class RemoteFileDialog {
|
||||
}
|
||||
|
||||
private filterFile(file: URI): boolean {
|
||||
if (this.filters) {
|
||||
if (this.options.filters) {
|
||||
const ext = resources.extname(file);
|
||||
for (let i = 0; i < this.filters.length; i++) {
|
||||
for (let j = 0; j < this.filters[i].extensions.length; j++) {
|
||||
if (ext === ('.' + this.filters[i].extensions[j])) {
|
||||
for (let i = 0; i < this.options.filters.length; i++) {
|
||||
for (let j = 0; j < this.options.filters[i].extensions.length; j++) {
|
||||
if (ext === ('.' + this.options.filters[i].extensions[j])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user