未验证 提交 f63d6952 编写于 作者: A Alex Ross 提交者: GitHub

Fallback to userhome when no "file" scheme folders open (#110066)

Fixes https://github.com/github/codespaces/issues/1695 and fixes microsoft/vscode-remote-release#2536 
上级 0302b842
......@@ -218,20 +218,23 @@ export interface IFileDialogService {
/**
* The default path for a new file based on previously used files.
* @param schemeFilter The scheme of the file path. If no filter given, the scheme of the current window is used.
* Falls back to user home in the absence of enough information to find a better URI.
*/
defaultFilePath(schemeFilter?: string): URI | undefined;
defaultFilePath(schemeFilter?: string): Promise<URI>;
/**
* The default path for a new folder based on previously used folders.
* @param schemeFilter The scheme of the folder path. If no filter given, the scheme of the current window is used.
* Falls back to user home in the absence of enough information to find a better URI.
*/
defaultFolderPath(schemeFilter?: string): URI | undefined;
defaultFolderPath(schemeFilter?: string): Promise<URI>;
/**
* The default path for a new workspace based on previously used workspaces.
* @param schemeFilter The scheme of the workspace path. If no filter given, the scheme of the current window is used.
* Falls back to user home in the absence of enough information to find a better URI.
*/
defaultWorkspacePath(schemeFilter?: string, filename?: string): URI | undefined;
defaultWorkspacePath(schemeFilter?: string, filename?: string): Promise<URI>;
/**
* Shows a file-folder selection dialog and opens the selected entry.
......
......@@ -61,7 +61,7 @@ CommandsRegistry.registerCommand({
title: nls.localize('addFolderToWorkspaceTitle', "Add Folder to Workspace"),
canSelectFolders: true,
canSelectMany: true,
defaultUri: dialogsService.defaultFolderPath()
defaultUri: await dialogsService.defaultFolderPath()
});
if (!folders || !folders.length) {
......
......@@ -320,7 +320,7 @@ class DropOverlay extends Themable {
// Try to come up with a good file path for the untitled
// editor by asking the file dialog service for the default
let proposedFilePath: URI | undefined = undefined;
const defaultFilePath = this.fileDialogService.defaultFilePath();
const defaultFilePath = await this.fileDialogService.defaultFilePath();
if (defaultFilePath) {
proposedFilePath = joinPath(defaultFilePath, name);
}
......
......@@ -1227,10 +1227,8 @@ const downloadFileHandler = (accessor: ServicesAccessor) => {
else {
progress.report({ message: explorerItem.name });
let defaultUri = explorerItem.isDirectory ? fileDialogService.defaultFolderPath(Schemas.file) : fileDialogService.defaultFilePath(Schemas.file);
if (defaultUri) {
defaultUri = resources.joinPath(defaultUri, explorerItem.name);
}
let defaultUri = explorerItem.isDirectory ? await fileDialogService.defaultFolderPath(Schemas.file) : await fileDialogService.defaultFilePath(Schemas.file);
defaultUri = resources.joinPath(defaultUri, explorerItem.name);
const destination = await fileDialogService.showSaveDialog({
availableFileSystems: [Schemas.file],
......
......@@ -14,7 +14,6 @@ import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
import { INotebookEditorModelResolverService } from 'vs/workbench/contrib/notebook/common/notebookEditorModelResolverService';
import { IReference } from 'vs/base/common/lifecycle';
import { INotebookEditorModel } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IPathService } from 'vs/workbench/services/path/common/pathService';
interface NotebookEditorInputOptions {
startDirty?: boolean;
......@@ -39,7 +38,6 @@ export class NotebookEditorInput extends EditorInput {
@INotebookEditorModelResolverService private readonly _notebookModelResolverService: INotebookEditorModelResolverService,
@IFilesConfigurationService private readonly _filesConfigurationService: IFilesConfigurationService,
@IFileDialogService private readonly _fileDialogService: IFileDialogService,
@IPathService private readonly _pathService: IPathService,
@IInstantiationService private readonly _instantiationService: IInstantiationService
) {
super();
......@@ -145,7 +143,7 @@ ${patterns}
}
async suggestName(suggestedFilename: string) {
return joinPath(this._fileDialogService.defaultFilePath() || (await this._pathService.userHome()), suggestedFilename);
return joinPath(await this._fileDialogService.defaultFilePath(), suggestedFilename);
}
// called when users rename a notebook document
......
......@@ -276,7 +276,7 @@ export class SearchEditorInput extends EditorInput {
const searchFileName = (query.replace(/[^\w \-_]+/g, '_') || 'Search') + SEARCH_EDITOR_EXT;
return joinPath(this.fileDialogService.defaultFilePath(this.pathService.defaultUriScheme) || (await this.pathService.userHome()), searchFileName);
return joinPath(await this.fileDialogService.defaultFilePath(this.pathService.defaultUriScheme), searchFileName);
}
}
......
......@@ -24,6 +24,7 @@ import { trim } from 'vs/base/common/strings';
import { IModeService } from 'vs/editor/common/services/modeService';
import { ILabelService } from 'vs/platform/label/common/label';
import { IPathService } from 'vs/workbench/services/path/common/pathService';
import { Schemas } from 'vs/base/common/network';
export abstract class AbstractFileDialogService implements IFileDialogService {
......@@ -45,7 +46,7 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
@IPathService private readonly pathService: IPathService
) { }
defaultFilePath(schemeFilter = this.getSchemeFilterForWindow()): URI | undefined {
async defaultFilePath(schemeFilter = this.getSchemeFilterForWindow()): Promise<URI> {
// Check for last active file first...
let candidate = this.historyService.getLastActiveFile(schemeFilter);
......@@ -57,10 +58,14 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
candidate = candidate && resources.dirname(candidate);
}
return candidate || undefined;
if (!candidate) {
candidate = await this.pathService.userHome({ preferLocal: schemeFilter === Schemas.file });
}
return candidate;
}
defaultFolderPath(schemeFilter = this.getSchemeFilterForWindow()): URI | undefined {
async defaultFolderPath(schemeFilter = this.getSchemeFilterForWindow()): Promise<URI> {
// Check for last active file root first...
let candidate = this.historyService.getLastActiveWorkspaceRoot(schemeFilter);
......@@ -70,10 +75,14 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
candidate = this.historyService.getLastActiveFile(schemeFilter);
}
if (!candidate) {
candidate = await this.pathService.userHome({ preferLocal: schemeFilter === Schemas.file });
}
return candidate && resources.dirname(candidate) || undefined;
}
defaultWorkspacePath(schemeFilter = this.getSchemeFilterForWindow(), filename?: string): URI | undefined {
async defaultWorkspacePath(schemeFilter = this.getSchemeFilterForWindow(), filename?: string): Promise<URI> {
let defaultWorkspacePath: URI | undefined;
// Check for current workspace config file first...
if (this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE) {
......@@ -85,7 +94,7 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
// ...then fallback to default file path
if (!defaultWorkspacePath) {
defaultWorkspacePath = this.defaultFilePath(schemeFilter);
defaultWorkspacePath = await this.defaultFilePath(schemeFilter);
}
if (defaultWorkspacePath && filename) {
......
......@@ -15,7 +15,7 @@ export class FileDialogService extends AbstractFileDialogService implements IFil
const schema = this.getFileSystemSchema(options);
if (!options.defaultUri) {
options.defaultUri = this.defaultFilePath(schema);
options.defaultUri = await this.defaultFilePath(schema);
}
return this.pickFileFolderAndOpenSimplified(schema, options, false);
......@@ -25,7 +25,7 @@ export class FileDialogService extends AbstractFileDialogService implements IFil
const schema = this.getFileSystemSchema(options);
if (!options.defaultUri) {
options.defaultUri = this.defaultFilePath(schema);
options.defaultUri = await this.defaultFilePath(schema);
}
return this.pickFileAndOpenSimplified(schema, options, false);
......@@ -35,7 +35,7 @@ export class FileDialogService extends AbstractFileDialogService implements IFil
const schema = this.getFileSystemSchema(options);
if (!options.defaultUri) {
options.defaultUri = this.defaultFolderPath(schema);
options.defaultUri = await this.defaultFolderPath(schema);
}
return this.pickFolderAndOpenSimplified(schema, options);
......@@ -45,7 +45,7 @@ export class FileDialogService extends AbstractFileDialogService implements IFil
const schema = this.getFileSystemSchema(options);
if (!options.defaultUri) {
options.defaultUri = this.defaultWorkspacePath(schema);
options.defaultUri = await this.defaultWorkspacePath(schema);
}
return this.pickWorkspaceAndOpenSimplified(schema, options);
......
......@@ -68,7 +68,7 @@ export class FileDialogService extends AbstractFileDialogService implements IFil
const schema = this.getFileSystemSchema(options);
if (!options.defaultUri) {
options.defaultUri = this.defaultFilePath(schema);
options.defaultUri = await this.defaultFilePath(schema);
}
const shouldUseSimplified = this.shouldUseSimplified(schema);
......@@ -82,7 +82,7 @@ export class FileDialogService extends AbstractFileDialogService implements IFil
const schema = this.getFileSystemSchema(options);
if (!options.defaultUri) {
options.defaultUri = this.defaultFilePath(schema);
options.defaultUri = await this.defaultFilePath(schema);
}
const shouldUseSimplified = this.shouldUseSimplified(schema);
......@@ -96,7 +96,7 @@ export class FileDialogService extends AbstractFileDialogService implements IFil
const schema = this.getFileSystemSchema(options);
if (!options.defaultUri) {
options.defaultUri = this.defaultFolderPath(schema);
options.defaultUri = await this.defaultFolderPath(schema);
}
if (this.shouldUseSimplified(schema).useSimplified) {
......@@ -109,7 +109,7 @@ export class FileDialogService extends AbstractFileDialogService implements IFil
const schema = this.getFileSystemSchema(options);
if (!options.defaultUri) {
options.defaultUri = this.defaultWorkspacePath(schema);
options.defaultUri = await this.defaultWorkspacePath(schema);
}
if (this.shouldUseSimplified(schema).useSimplified) {
......
......@@ -459,7 +459,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex
// Try to place where last active file was if any
// Otherwise fallback to user home
return joinPath(this.fileDialogService.defaultFilePath() || (await this.pathService.userHome()), suggestedFilename);
return joinPath(await this.fileDialogService.defaultFilePath(), suggestedFilename);
}
suggestFilename(mode: string, untitledName: string) {
......
......@@ -54,7 +54,7 @@ export abstract class AbstractWorkspaceEditingService implements IWorkspaceEditi
saveLabel: mnemonicButtonLabel(nls.localize('save', "Save")),
title: nls.localize('saveWorkspace', "Save Workspace"),
filters: WORKSPACE_FILTER,
defaultUri: this.fileDialogService.defaultWorkspacePath(undefined, UNTITLED_WORKSPACE_FILENAME),
defaultUri: await this.fileDialogService.defaultWorkspacePath(undefined, UNTITLED_WORKSPACE_FILENAME),
availableFileSystems: this.environmentService.remoteAuthority ? [Schemas.vscodeRemote] : undefined
});
......
......@@ -150,7 +150,7 @@ export function workbenchInstantiationService(overrides?: {
instantiationService.stub(IDialogService, new TestDialogService());
const accessibilityService = new TestAccessibilityService();
instantiationService.stub(IAccessibilityService, accessibilityService);
instantiationService.stub(IFileDialogService, new TestFileDialogService());
instantiationService.stub(IFileDialogService, instantiationService.createInstance(TestFileDialogService));
instantiationService.stub(IModeService, instantiationService.createInstance(ModeServiceImpl));
instantiationService.stub(IHistoryService, new TestHistoryService());
instantiationService.stub(ITextResourcePropertiesService, new TestTextResourcePropertiesService(configService));
......@@ -389,9 +389,12 @@ export class TestFileDialogService implements IFileDialogService {
private confirmResult!: ConfirmResult;
defaultFilePath(_schemeFilter?: string): URI | undefined { return undefined; }
defaultFolderPath(_schemeFilter?: string): URI | undefined { return undefined; }
defaultWorkspacePath(_schemeFilter?: string): URI | undefined { return undefined; }
constructor(
@IPathService private readonly pathService: IPathService
) { }
async defaultFilePath(_schemeFilter?: string): Promise<URI> { return this.pathService.userHome(); }
async defaultFolderPath(_schemeFilter?: string): Promise<URI> { return this.pathService.userHome(); }
async defaultWorkspacePath(_schemeFilter?: string): Promise<URI> { return this.pathService.userHome(); }
pickFileFolderAndOpen(_options: IPickAndOpenOptions): Promise<any> { return Promise.resolve(0); }
pickFileAndOpen(_options: IPickAndOpenOptions): Promise<any> { return Promise.resolve(0); }
pickFolderAndOpen(_options: IPickAndOpenOptions): Promise<any> { return Promise.resolve(0); }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册