Skip to content

Commit

Permalink
add registerProjectWizard API
Browse files Browse the repository at this point in the history
  • Loading branch information
yeweiasia committed Dec 1, 2022
1 parent 90e9004 commit 32273db
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"codearts",
"plugin"
],
"version": "0.4.6",
"version": "0.4.7",
"license": "SEE LICENSE IN LICENSE",
"description": "core plugin api of cloudide frontend and backend",
"repository": {
Expand Down
13 changes: 11 additions & 2 deletions src/browser/plugin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export class PluginPage {
* @param opts options to configure the webview
* @param override replace the webview with the same viewType
*/
public async createWebviewPanel(opts: WebviewOptions, override?: boolean): Promise<void> {
public async createWebviewPanel(opts: WebviewOptions, override?: boolean): Promise<boolean> {
return this.call('plugin.createWebviewPanel', opts, override);
}

Expand All @@ -336,10 +336,19 @@ export class PluginPage {
* @param opts options to configure the dynamic webview
* @param override replace the dynamic webview with the same viewType
*/
public async createWebviewViewDialog(opts: WebviewOptions & DialogOptions): Promise<void> {
public async createWebviewViewDialog(opts: WebviewOptions & DialogOptions): Promise<boolean> {
return this.call('plugin.createWebviewViewDialog', opts);
}

/**
* Register a provider for project wizard with webview view.
* @param opts options to create the webview provider
* @returns Pormose<void>
*/
public async registerProjectWizardProvider(opts: WebviewOptions): Promise<boolean> {
return this.call('plugin.registerProjectWizardProvider', opts);
}

/**
* Dispose webview with specific viewType
* @param viewType view type of the dynamic webview
Expand Down
37 changes: 37 additions & 0 deletions src/node/plugin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,35 @@ export class Plugin {
return dialog;
}

/**
* Register project wizard provider to the new project dialog
*
* @param opts options to create the webview provider
*
* opts.viewType will be the id of project wizard provider, the viewType should not
* conflict with others. opts.title will be the label of project wizard provider,
* which will be displayed in the left menu list.
*
* @returns cloudide.Disposable
*/
public registerProjectWizardProvider(opts: WebviewOptions): cloudide.Disposable | undefined {
const provider = new BaseWebviewDialogProvider(this.context, opts);
let disposable = undefined;
try {
disposable = (cloudide as any).window.registerProjectWizardProvider(opts.viewType, opts.title, provider, {
iconPath: opts.iconPath
});
} catch (e) {
this.log(LogLevel.ERROR, (<any>e).message);
return undefined;
}

Messaging.bind(provider, backendClientIdentifier);
this.container.set(opts.viewType, provider);
provider.onDispose(disposable.dispose.bind(disposable));
return disposable;
}

public dispatchMessage(sourceViewType: string, message: any): void {
this.container.forEach(async (webviewContainer, viewType) => {
if (viewType !== sourceViewType && !webviewContainer.disposed) {
Expand Down Expand Up @@ -758,6 +787,14 @@ class DefaultPluginApiHost extends AbstractBackend {
return true;
}

@expose('plugin.registerProjectWizardProvider')
public registerProjectWizardProvider(opts: WebviewOptions): boolean {
if (!Plugin.getInstance().registerProjectWizardProvider(opts)) {
return false;
}
return true;
}

@expose('plugin.api')
public getTheiaApi(...property: string[]): any {
const properties = {};
Expand Down

0 comments on commit 32273db

Please sign in to comment.