Merge from vscode a234f13c45b40a0929777cb440ee011b7549eed2 (#8911)

* Merge from vscode a234f13c45b40a0929777cb440ee011b7549eed2

* update distro

* fix layering

* update distro

* fix tests
This commit is contained in:
Anthony Dresser
2020-01-22 13:42:37 -08:00
committed by GitHub
parent 977111eb21
commit bd7aac8ee0
895 changed files with 24651 additions and 14520 deletions

View File

@@ -5,7 +5,7 @@
import * as nls from 'vs/nls';
import { IWindowOpenable } from 'vs/platform/windows/common/windows';
import { IPickAndOpenOptions, ISaveDialogOptions, IOpenDialogOptions, FileFilter, IFileDialogService, IDialogService, ConfirmResult, getConfirmMessage } from 'vs/platform/dialogs/common/dialogs';
import { IPickAndOpenOptions, ISaveDialogOptions, IOpenDialogOptions, FileFilter, IFileDialogService, IDialogService, ConfirmResult, getFileNamesMessage } from 'vs/platform/dialogs/common/dialogs';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
@@ -21,6 +21,9 @@ import { IFileService } from 'vs/platform/files/common/files';
import { IOpenerService } from 'vs/platform/opener/common/opener';
import { IHostService } from 'vs/workbench/services/host/browser/host';
import Severity from 'vs/base/common/severity';
import { coalesce } from 'vs/base/common/arrays';
import { trim } from 'vs/base/common/strings';
import { IModeService } from 'vs/editor/common/services/modeService';
export abstract class AbstractFileDialogService implements IFileDialogService {
@@ -35,7 +38,8 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
@IConfigurationService protected readonly configurationService: IConfigurationService,
@IFileService protected readonly fileService: IFileService,
@IOpenerService protected readonly openerService: IOpenerService,
@IDialogService private readonly dialogService: IDialogService
@IDialogService private readonly dialogService: IDialogService,
@IModeService private readonly modeService: IModeService
) { }
defaultFilePath(schemeFilter = this.getSchemeFilterForWindow()): URI | undefined {
@@ -90,10 +94,12 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
}
let message: string;
let detail = nls.localize('saveChangesDetail', "Your changes will be lost if you don't save them.");
if (fileNamesOrResources.length === 1) {
message = nls.localize('saveChangesMessage', "Do you want to save the changes you made to {0}?", typeof fileNamesOrResources[0] === 'string' ? fileNamesOrResources[0] : resources.basename(fileNamesOrResources[0]));
} else {
message = getConfirmMessage(nls.localize('saveChangesMessages', "Do you want to save the changes to the following {0} files?", fileNamesOrResources.length), fileNamesOrResources);
message = nls.localize('saveChangesMessages', "Do you want to save the changes to the following {0} files?", fileNamesOrResources.length);
detail = getFileNamesMessage(fileNamesOrResources) + '\n' + detail;
}
const buttons: string[] = [
@@ -104,7 +110,7 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
const { choice } = await this.dialogService.show(Severity.Warning, message, buttons, {
cancelId: 2,
detail: nls.localize('saveChangesDetail', "Your changes will be lost if you don't save them.")
detail
});
switch (choice) {
@@ -220,7 +226,56 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
abstract pickFileAndOpen(options: IPickAndOpenOptions): Promise<void>;
abstract pickFolderAndOpen(options: IPickAndOpenOptions): Promise<void>;
abstract pickWorkspaceAndOpen(options: IPickAndOpenOptions): Promise<void>;
abstract pickFileToSave(options: ISaveDialogOptions): Promise<URI | undefined>;
abstract showSaveDialog(options: ISaveDialogOptions): Promise<URI | undefined>;
abstract showOpenDialog(options: IOpenDialogOptions): Promise<URI[] | undefined>;
abstract pickFileToSave(defaultUri: URI, availableFileSystems?: string[]): Promise<URI | undefined>;
protected getPickFileToSaveDialogOptions(defaultUri: URI, availableFileSystems?: string[]): ISaveDialogOptions {
const options: ISaveDialogOptions = {
defaultUri,
title: nls.localize('saveAsTitle', "Save As"),
availableFileSystems,
};
interface IFilter { name: string; extensions: string[]; }
// Build the file filter by using our known languages
const ext: string | undefined = defaultUri ? resources.extname(defaultUri) : undefined;
let matchingFilter: IFilter | undefined;
const filters: IFilter[] = coalesce(this.modeService.getRegisteredLanguageNames().map(languageName => {
const extensions = this.modeService.getExtensions(languageName);
if (!extensions || !extensions.length) {
return null;
}
const filter: IFilter = { name: languageName, extensions: extensions.slice(0, 10).map(e => trim(e, '.')) };
if (ext && extensions.indexOf(ext) >= 0) {
matchingFilter = filter;
return null; // matching filter will be added last to the top
}
return filter;
}));
// Filters are a bit weird on Windows, based on having a match or not:
// Match: we put the matching filter first so that it shows up selected and the all files last
// No match: we put the all files filter first
const allFilesFilter = { name: nls.localize('allFiles', "All Files"), extensions: ['*'] };
if (matchingFilter) {
filters.unshift(matchingFilter);
filters.unshift(allFilesFilter);
} else {
filters.unshift(allFilesFilter);
}
// Allow to save file without extension
filters.push({ name: nls.localize('noExt', "No Extension"), extensions: [''] });
options.filters = filters;
return options;
}
}

View File

@@ -51,9 +51,9 @@ export class FileDialogService extends AbstractFileDialogService implements IFil
return this.pickWorkspaceAndOpenSimplified(schema, options);
}
async pickFileToSave(options: ISaveDialogOptions): Promise<URI | undefined> {
const schema = this.getFileSystemSchema(options);
return this.pickFileToSaveSimplified(schema, options);
async pickFileToSave(defaultUri: URI, availableFileSystems?: string[]): Promise<URI | undefined> {
const schema = this.getFileSystemSchema({ defaultUri, availableFileSystems });
return this.pickFileToSaveSimplified(schema, this.getPickFileToSaveDialogOptions(defaultUri, availableFileSystems));
}
async showSaveDialog(options: ISaveDialogOptions): Promise<URI | undefined> {

View File

@@ -35,6 +35,7 @@ import { ICommandHandler } from 'vs/platform/commands/common/commands';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { normalizeDriveLetter } from 'vs/base/common/labels';
import { SaveReason } from 'vs/workbench/common/editor';
import { IRemotePathService } from 'vs/workbench/services/path/common/remotePathService';
export namespace OpenLocalFileCommand {
export const ID = 'workbench.action.files.openLocalFile';
@@ -134,6 +135,7 @@ export class SimpleFileDialog {
@IModeService private readonly modeService: IModeService,
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
@IRemoteAgentService private readonly remoteAgentService: IRemoteAgentService,
@IRemotePathService private readonly remotePathService: IRemotePathService,
@IKeybindingService private readonly keybindingService: IKeybindingService,
@IContextKeyService contextKeyService: IContextKeyService,
) {
@@ -154,8 +156,8 @@ export class SimpleFileDialog {
public async showOpenDialog(options: IOpenDialogOptions = {}): Promise<URI | undefined> {
this.scheme = this.getScheme(options.availableFileSystems, options.defaultUri);
this.userHome = await this.getUserHome();
const newOptions = await this.getOptions(options);
this.userHome = await this.remotePathService.userHome;
const newOptions = this.getOptions(options);
if (!newOptions) {
return Promise.resolve(undefined);
}
@@ -165,9 +167,9 @@ export class SimpleFileDialog {
public async showSaveDialog(options: ISaveDialogOptions): Promise<URI | undefined> {
this.scheme = this.getScheme(options.availableFileSystems, options.defaultUri);
this.userHome = await this.getUserHome();
this.userHome = await this.remotePathService.userHome;
this.requiresTrailing = true;
const newOptions = await this.getOptions(options, true);
const newOptions = this.getOptions(options, true);
if (!newOptions) {
return Promise.resolve(undefined);
}
@@ -229,16 +231,6 @@ export class SimpleFileDialog {
return this.remoteAgentEnvironment;
}
private async getUserHome(): Promise<URI> {
if (this.scheme !== Schemas.file) {
const env = await this.getRemoteAgentEnvironment();
if (env) {
return env.userHome;
}
}
return URI.from({ scheme: this.scheme, path: this.environmentService.userHome });
}
private async pickResource(isSave: boolean = false): Promise<URI | undefined> {
this.allowFolderSelection = !!this.options.canSelectFolders;
this.allowFileSelection = !!this.options.canSelectFiles;