Skip to content

Commit

Permalink
Allow "Command" type in status bar items
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Mäder <tmader@redhat.com>
  • Loading branch information
tsmaeder authored and akosyakov committed Jul 30, 2020
1 parent 77fa067 commit 4b3206e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
4 changes: 2 additions & 2 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ export interface StatusBarMessageRegistryMain {
alignment: theia.StatusBarAlignment,
color: string | undefined,
tooltip: string | undefined,
command: string | undefined): PromiseLike<void>;
$update(id: string, message: string): void;
command: string | undefined,
args: any[] | undefined): PromiseLike<void>;
$dispose(id: string): void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ export class StatusBarMessageRegistryMainImpl implements StatusBarMessageRegistr
alignment: number,
color: string | undefined,
tooltip: string | undefined,
command: string | undefined): Promise<void> {
command: string | undefined,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
args: any[] | undefined): Promise<void> {
const entry = {
text: text || '',
priority,
alignment: alignment === types.StatusBarAlignment.Left ? StatusBarAlignment.LEFT : StatusBarAlignment.RIGHT,
color: color && (this.colorRegistry.getCurrentColor(color) || color),
tooltip,
command
command,
args
};

this.entries.set(id, entry);
Expand All @@ -63,14 +66,6 @@ export class StatusBarMessageRegistryMainImpl implements StatusBarMessageRegistr
}
}

$update(id: string, message: string): void {
const entry = this.entries.get(id);
if (entry) {
entry.text = message;
this.delegate.setElement(id, entry);
}
}

$dispose(id: string): void {
const entry = this.entries.get(id);
if (entry) {
Expand Down
11 changes: 7 additions & 4 deletions packages/plugin-ext/src/plugin/status-bar/status-bar-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class StatusBarItemImpl implements theia.StatusBarItem {
private _text: string;
private _tooltip: string;
private _color: string | ThemeColor;
private _command: string;
private _command: string | theia.Command;

private _isVisible: boolean;
private _timeoutHandle: NodeJS.Timer | undefined;
Expand Down Expand Up @@ -63,7 +63,7 @@ export class StatusBarItemImpl implements theia.StatusBarItem {
return this._color;
}

public get command(): string {
public get command(): string | theia.Command {
return this._command;
}

Expand All @@ -82,7 +82,7 @@ export class StatusBarItemImpl implements theia.StatusBarItem {
this.update();
}

public set command(command: string) {
public set command(command: string | theia.Command) {
this._command = command;
this.update();
}
Expand Down Expand Up @@ -111,13 +111,16 @@ export class StatusBarItemImpl implements theia.StatusBarItem {
this._timeoutHandle = setTimeout(() => {
this._timeoutHandle = undefined;

const commandId = typeof this.command === 'object' ? this.command.command : this.command;
const args = typeof this.command === 'object' ? this.command.arguments : undefined;
// Set to status bar
this._proxy.$setMessage(this.id, this.text,
this.priority,
this.alignment,
typeof this.color === 'string' ? this.color : this.color && this.color.id,
this.tooltip,
this.command);
commandId,
args);
}, 0);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2366,7 +2366,7 @@ declare module '@theia/plugin' {
/**
* The identifier of a command to run on click.
*/
command: string | undefined;
command: string | Command | undefined;

/**
* Shows the entry in the status bar.
Expand Down

0 comments on commit 4b3206e

Please sign in to comment.