vscode.openFolder: allow to open a local window
This commit is contained in:
parent
318fe9ff80
commit
b36bcfe1b4
3 changed files with 29 additions and 11 deletions
|
@ -100,6 +100,7 @@ export interface IPickAndOpenOptions {
|
|||
defaultUri?: URI;
|
||||
telemetryExtraData?: ITelemetryData;
|
||||
availableFileSystems?: string[];
|
||||
remoteAuthority?: string | null;
|
||||
}
|
||||
|
||||
export interface ISaveDialogOptions {
|
||||
|
|
|
@ -17,7 +17,7 @@ import { IQuickInputService, IPickOptions, IQuickPickItem } from 'vs/platform/qu
|
|||
import { getIconClasses } from 'vs/editor/common/services/getIconClasses';
|
||||
import { IModelService } from 'vs/editor/common/services/modelService';
|
||||
import { IModeService } from 'vs/editor/common/services/modeService';
|
||||
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
|
||||
import { IFileDialogService, IPickAndOpenOptions } from 'vs/platform/dialogs/common/dialogs';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { IOpenWindowOptions, IWindowOpenable } from 'vs/platform/windows/common/windows';
|
||||
|
@ -130,21 +130,26 @@ interface IOpenFolderAPICommandOptions {
|
|||
forceNewWindow?: boolean;
|
||||
forceReuseWindow?: boolean;
|
||||
noRecentEntry?: boolean;
|
||||
remoteAuthority?: string;
|
||||
}
|
||||
|
||||
CommandsRegistry.registerCommand({
|
||||
id: 'vscode.openFolder',
|
||||
handler: (accessor: ServicesAccessor, uri?: URI, arg?: boolean | IOpenFolderAPICommandOptions) => {
|
||||
const commandService = accessor.get(ICommandService);
|
||||
|
||||
// Be compatible to previous args by converting to options
|
||||
if (typeof arg === 'boolean') {
|
||||
arg = { forceNewWindow: arg };
|
||||
}
|
||||
|
||||
// Without URI, ask to pick a folder or workpsace to open
|
||||
// Without URI, ask to pick a folder or workspace to open
|
||||
if (!uri) {
|
||||
return commandService.executeCommand('_files.pickFolderAndOpen', { forceNewWindow: arg?.forceNewWindow });
|
||||
const options: IPickAndOpenOptions = {
|
||||
forceNewWindow: arg?.forceNewWindow,
|
||||
availableFileSystems: arg?.remoteAuthority === null ? [Schemas.file] : undefined,
|
||||
remoteAuthority: arg?.remoteAuthority
|
||||
};
|
||||
return commandService.executeCommand('_files.pickFolderAndOpen', options);
|
||||
}
|
||||
|
||||
uri = URI.revive(uri);
|
||||
|
@ -152,7 +157,8 @@ CommandsRegistry.registerCommand({
|
|||
const options: IOpenWindowOptions = {
|
||||
forceNewWindow: arg?.forceNewWindow,
|
||||
forceReuseWindow: arg?.forceReuseWindow,
|
||||
noRecentEntry: arg?.noRecentEntry
|
||||
noRecentEntry: arg?.noRecentEntry,
|
||||
remoteAuthority: arg?.remoteAuthority
|
||||
};
|
||||
|
||||
const uriToOpen: IWindowOpenable = (hasWorkspaceFileExtension(uri) || uri.scheme === Schemas.untitled) ? { workspaceUri: uri } : { folderUri: uri };
|
||||
|
@ -161,8 +167,19 @@ CommandsRegistry.registerCommand({
|
|||
description: {
|
||||
description: 'Open a folder or workspace in the current window or new window depending on the newWindow argument. Note that opening in the same window will shutdown the current extension host process and start a new one on the given folder/workspace unless the newWindow parameter is set to true.',
|
||||
args: [
|
||||
{ name: 'uri', description: '(optional) Uri of the folder or workspace file to open. If not provided, a native dialog will ask the user for the folder', constraint: (value: any) => value === undefined || value instanceof URI },
|
||||
{ name: 'options', description: '(optional) Options. Object with the following properties: `forceNewWindow `: Whether to open the folder/workspace in a new window or the same. Defaults to opening in the same window. `noRecentEntry`: Whether the opened URI will appear in the \'Open Recent\' list. Defaults to true. Note, for backward compatibility, options can also be of type boolean, representing the `forceNewWindow` setting.', constraint: (value: any) => value === undefined || typeof value === 'object' || typeof value === 'boolean' }
|
||||
{
|
||||
name: 'uri', description: '(optional) Uri of the folder or workspace file to open. If not provided, a native dialog will ask the user for the folder',
|
||||
constraint: (value: any) => value === undefined || value === null || value instanceof URI
|
||||
},
|
||||
{
|
||||
name: 'options',
|
||||
description: '(optional) Options. Object with the following properties: ' +
|
||||
'`forceNewWindow`: Whether to open the folder/workspace in a new window or the same. Defaults to opening in the same window. ' +
|
||||
'`forceReuseWindow`: Whether to force opening the folder/workspace in the same window. Defaults to false. ' +
|
||||
'`noRecentEntry`: Whether the opened URI will appear in the \'Open Recent\' list. Defaults to false. ' +
|
||||
'Note, for backward compatibility, options can also be of type boolean, representing the `forceNewWindow` setting.',
|
||||
constraint: (value: any) => value === undefined || typeof value === 'object' || typeof value === 'boolean'
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
|
|
@ -163,7 +163,7 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
|
|||
}
|
||||
|
||||
if (stat.isDirectory || options.forceNewWindow || preferNewWindow) {
|
||||
return this.hostService.openWindow([toOpen], { forceNewWindow: options.forceNewWindow });
|
||||
return this.hostService.openWindow([toOpen], { forceNewWindow: options.forceNewWindow, remoteAuthority: options.remoteAuthority });
|
||||
} else {
|
||||
return this.openerService.open(uri, { fromUserGesture: true, editorOptions: { pinned: true } });
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
|
|||
this.workspacesService.addRecentlyOpened([{ fileUri: uri, label: this.labelService.getUriLabel(uri) }]);
|
||||
|
||||
if (options.forceNewWindow || preferNewWindow) {
|
||||
return this.hostService.openWindow([{ fileUri: uri }], { forceNewWindow: options.forceNewWindow });
|
||||
return this.hostService.openWindow([{ fileUri: uri }], { forceNewWindow: options.forceNewWindow, remoteAuthority: options.remoteAuthority });
|
||||
} else {
|
||||
return this.openerService.open(uri, { fromUserGesture: true, editorOptions: { pinned: true } });
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
|
|||
|
||||
const uri = await this.pickResource({ canSelectFiles: false, canSelectFolders: true, canSelectMany: false, defaultUri: options.defaultUri, title, availableFileSystems });
|
||||
if (uri) {
|
||||
return this.hostService.openWindow([{ folderUri: uri }], { forceNewWindow: options.forceNewWindow });
|
||||
return this.hostService.openWindow([{ folderUri: uri }], { forceNewWindow: options.forceNewWindow, remoteAuthority: options.remoteAuthority });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,7 +204,7 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
|
|||
|
||||
const uri = await this.pickResource({ canSelectFiles: true, canSelectFolders: false, canSelectMany: false, defaultUri: options.defaultUri, title, filters, availableFileSystems });
|
||||
if (uri) {
|
||||
return this.hostService.openWindow([{ workspaceUri: uri }], { forceNewWindow: options.forceNewWindow });
|
||||
return this.hostService.openWindow([{ workspaceUri: uri }], { forceNewWindow: options.forceNewWindow, remoteAuthority: options.remoteAuthority });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue