提交 70e8e31f 编写于 作者: B Benjamin Pasero

web - add API to execute command

上级 e6e87b51
......@@ -33,7 +33,7 @@ import { WorkspaceService } from 'vs/workbench/services/configuration/browser/co
import { ConfigurationCache } from 'vs/workbench/services/configuration/browser/configurationCache';
import { ISignService } from 'vs/platform/sign/common/sign';
import { SignService } from 'vs/platform/sign/browser/signService';
import { IWorkbenchConstructionOptions, IWorkspace } from 'vs/workbench/workbench.web.api';
import { IWorkbenchConstructionOptions, IWorkspace, IWorkbench } from 'vs/workbench/workbench.web.api';
import { FileUserDataProvider } from 'vs/workbench/services/userData/common/fileUserDataProvider';
import { BACKUPS } from 'vs/platform/environment/common/environment';
import { joinPath } from 'vs/base/common/resources';
......@@ -51,6 +51,7 @@ import { getWorkspaceIdentifier } from 'vs/workbench/services/workspaces/browser
import { coalesce } from 'vs/base/common/arrays';
import { InMemoryFileSystemProvider } from 'vs/platform/files/common/inMemoryFilesystemProvider';
import { WebResourceIdentityService, IResourceIdentityService } from 'vs/platform/resource/common/resourceIdentityService';
import { ICommandService } from 'vs/platform/commands/common/commands';
class BrowserMain extends Disposable {
......@@ -61,7 +62,7 @@ class BrowserMain extends Disposable {
super();
}
async open(): Promise<void> {
async open(): Promise<IWorkbench> {
const services = await this.initServices();
await domContentLoaded();
......@@ -86,7 +87,18 @@ class BrowserMain extends Disposable {
}
// Startup
workbench.startup();
const instantiationService = workbench.startup();
// Return API Facade
return instantiationService.invokeFunction(accessor => {
const commandService = accessor.get(ICommandService);
return {
commands: {
executeCommand: (command, ...args) => commandService.executeCommand(command, ...args)
}
};
});
}
private registerListeners(workbench: Workbench, storageService: BrowserStorageService): void {
......@@ -335,8 +347,8 @@ class BrowserMain extends Disposable {
}
}
export function main(domElement: HTMLElement, options: IWorkbenchConstructionOptions): Promise<void> {
const renderer = new BrowserMain(domElement, options);
export function main(domElement: HTMLElement, options: IWorkbenchConstructionOptions): Promise<IWorkbench> {
const workbench = new BrowserMain(domElement, options);
return renderer.open();
return workbench.open();
}
......@@ -338,7 +338,7 @@ class DesktopMain extends Disposable {
}
export function main(configuration: INativeWindowConfiguration): Promise<void> {
const renderer = new DesktopMain(configuration);
const workbench = new DesktopMain(configuration);
return renderer.open();
return workbench.open();
}
......@@ -35,33 +35,37 @@ interface IExternalUriResolver {
(uri: URI): Promise<URI>;
}
interface TunnelOptions {
interface ITunnelFactory {
(tunnelOptions: ITunnelOptions): Promise<ITunnel> | undefined;
}
interface ITunnelOptions {
remoteAddress: { port: number, host: string };
/**
* The desired local port. If this port can't be used, then another will be chosen.
*/
localAddressPort?: number;
label?: string;
}
interface Tunnel extends IDisposable {
interface ITunnel extends IDisposable {
remoteAddress: { port: number, host: string };
/**
* The complete local address(ex. localhost:1234)
*/
localAddress: string;
/**
* Implementers of Tunnel should fire onDidDispose when dispose is called.
*/
onDidDispose: Event<void>;
}
interface ITunnelFactory {
(tunnelOptions: TunnelOptions): Thenable<Tunnel> | undefined;
}
interface IShowCandidate {
(host: string, port: number, detail: string): Thenable<boolean>;
interface IShowPortCandidate {
(host: string, port: number, detail: string): Promise<boolean>;
}
interface ICommand {
......@@ -126,7 +130,7 @@ interface IWorkbenchConstructionOptions {
/**
* Support for filtering candidate ports
*/
readonly showCandidate?: IShowCandidate;
readonly showCandidate?: IShowPortCandidate;
//#endregion
......@@ -195,14 +199,30 @@ interface IWorkbenchConstructionOptions {
//#endregion
}
interface IWorkbench {
commands: {
/**
* Allows to execute any command if known with the provided arguments.
*
* @param command Identifier of the command to execute.
* @param rest Parameters passed to the command function.
* @return A promise that resolves to the returned value of the given command.
*/
executeCommand<T>(command: string, ...rest: any[]): Promise<T | undefined>;
}
}
/**
* Creates the workbench with the provided options in the provided container.
*
* @param domElement the container to create the workbench in
* @param options for setting up the workbench
*
* @returns the workbench API facade.
*/
let created = false;
async function create(domElement: HTMLElement, options: IWorkbenchConstructionOptions): Promise<void> {
async function create(domElement: HTMLElement, options: IWorkbenchConstructionOptions): Promise<IWorkbench> {
// Assert that the workbench is not created more than once. We currently
// do not support this and require a full context switch to clean-up.
......@@ -213,7 +233,7 @@ async function create(domElement: HTMLElement, options: IWorkbenchConstructionOp
}
// Startup workbench
await main(domElement, options);
const workbench = await main(domElement, options);
// Register commands if any
if (Array.isArray(options.commands)) {
......@@ -225,6 +245,8 @@ async function create(domElement: HTMLElement, options: IWorkbenchConstructionOp
});
}
}
return workbench;
}
export {
......@@ -232,6 +254,7 @@ export {
// Factory
create,
IWorkbenchConstructionOptions,
IWorkbench,
// Basic Types
URI,
......@@ -281,6 +304,14 @@ export {
// External Uris
IExternalUriResolver,
// Tunnel
ITunnelFactory,
ITunnel,
ITunnelOptions,
// Ports
IShowPortCandidate,
// Commands
ICommand
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册