Skip to content

Commit

Permalink
eclipse-theia#10696 Complete createStatusBarItem in window namespace …
Browse files Browse the repository at this point in the history
…from VSCode API

- Add createStatusBarItem overload in theia.d.ts to allow an item id as argument
- Extend createStatusBarItem implementation in plugin-context
- Adapt createStatusBarItem in status-bar-message-registry
- Adapat StatusBarItemImpl to accept external ids

Contributed on behalf of STMicroelectronics

Signed-off-by: Nina Doschek <ndoschek@eclipsesource.com>

Fixes eclipse-theia#10696
  • Loading branch information
ndoschek committed Feb 15, 2022
1 parent 40227dc commit 26ddd3e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [core] Removed method `attachGlobalShortcuts` from `ElectronMainApplication`. Attaching shortcuts in that way interfered with internal shortcuts. Use internal keybindings instead of global shortcuts. [#10704](https://github.com/eclipse-theia/theia/pull/10704)
- [plugin-ext] function `logMeasurement` of `PluginDeployerImpl` class and browser class `HostedPluginSupport` is replaced by `measure` using the new `Stopwatch` API [#10407](https://github.com/eclipse-theia/theia/pull/10407)
- [plugin-ext] the constructor of `BackendApplication` class no longer invokes the `initialize` method. Instead, the `@postConstruct configure` method now starts by calling `initialize` [#10407](https://github.com/eclipse-theia/theia/pull/10407)
- [plugin] Added support for `vscode.window.createStatusBarItem` [#10xxx](https://github.com/eclipse-theia/theia/pull/10xxx) - Contributed on behalf of STMicroelectronics

## v1.22.0 - 1/27/2022

Expand Down
18 changes: 16 additions & 2 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,22 @@ export function createAPIFactory(
showInputBox(options?: theia.InputBoxOptions, token?: theia.CancellationToken): PromiseLike<string | undefined> {
return quickOpenExt.showInput(options, token);
},
createStatusBarItem(alignment?: theia.StatusBarAlignment, priority?: number): theia.StatusBarItem {
return statusBarMessageRegistryExt.createStatusBarItem(alignment, priority);
createStatusBarItem(alignmentOrId?: theia.StatusBarAlignment | string, priorityOrAlignment?: number | theia.StatusBarAlignment,
priorityArg?: number): theia.StatusBarItem {
let id: string | undefined;
let alignment: number | undefined;
let priority: number | undefined;

if (typeof alignmentOrId === 'string') {
id = alignmentOrId;
alignment = priorityOrAlignment;
priority = priorityArg;
} else {
alignment = alignmentOrId;
priority = priorityOrAlignment;
}

return statusBarMessageRegistryExt.createStatusBarItem(alignment, priority, id);
},
createOutputChannel(name: string): theia.OutputChannel {
return outputChannelRegistryExt.createOutputChannel(name, pluginToPluginInfo(plugin));
Expand Down
7 changes: 4 additions & 3 deletions packages/plugin-ext/src/plugin/status-bar-message-registry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (C) 2018 Red Hat, Inc. and others.
* Copyright (C) 2018-2022 Red Hat, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -57,9 +57,10 @@ export class StatusBarMessageRegistryExt {

}

createStatusBarItem(alignment?: StatusBarAlignment, priority?: number): StatusBarItem {
return new StatusBarItemImpl(this.proxy, alignment, priority);
createStatusBarItem(alignment?: StatusBarAlignment, priority?: number, id?: string): StatusBarItem {
return new StatusBarItemImpl(this.proxy, alignment, priority, id);
}

}

// copied from https://github.com/Microsoft/vscode/blob/6c8f02b41db9ae5c4d15df767d47755e5c73b9d5/src/vs/workbench/api/node/extHostStatusBar.ts#L122
Expand Down
12 changes: 9 additions & 3 deletions packages/plugin-ext/src/plugin/status-bar/status-bar-item.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (C) 2018 Red Hat, Inc. and others.
* Copyright (C) 2018-2022 Red Hat, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -20,7 +20,7 @@ import { UUID } from '@theia/core/shared/@phosphor/coreutils';

export class StatusBarItemImpl implements theia.StatusBarItem {

private readonly id = StatusBarItemImpl.nextId();
private _id: string;

private _alignment: StatusBarAlignment;
private _priority: number;
Expand All @@ -37,10 +37,16 @@ export class StatusBarItemImpl implements theia.StatusBarItem {

constructor(_proxy: StatusBarMessageRegistryMain,
alignment: StatusBarAlignment = StatusBarAlignment.Left,
priority: number = 0) {
priority: number = 0,
id = StatusBarItemImpl.nextId()) {
this._proxy = _proxy;
this._alignment = alignment;
this._priority = priority;
this._id = id;
}

public get id(): string {
return this._id;
}

public get alignment(): theia.StatusBarAlignment {
Expand Down
14 changes: 12 additions & 2 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (C) 2018 Red Hat, Inc. and others.
* Copyright (C) 2018-2022 Red Hat, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -4553,14 +4553,24 @@ export module '@theia/plugin' {
export function setStatusBarMessage(text: string, hideWhenDone: PromiseLike<any>): Disposable;

/**
* Creates a status bar [item](#StatusBarItem).
* Creates a status bar {@link StatusBarItem item}.
*
* @param alignment The alignment of the item.
* @param priority The priority of the item. Higher values mean the item should be shown more to the left.
* @return A new status bar item.
*/
export function createStatusBarItem(alignment?: StatusBarAlignment, priority?: number): StatusBarItem;

/**
* Creates a status bar {@link StatusBarItem item}.
*
* @param id The unique identifier of the item.
* @param alignment The alignment of the item.
* @param priority The priority of the item. Higher values mean the item should be shown more to the left.
* @return A new status bar item.
*/
export function createStatusBarItem(id: string, alignment?: StatusBarAlignment, priority?: number): StatusBarItem;

/**
* Create a new [output channel](#OutputChannel) with the given name.
*
Expand Down

0 comments on commit 26ddd3e

Please sign in to comment.