-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Oleksii Orel <oorel@redhat.com>
- Loading branch information
Showing
11 changed files
with
538 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/plugin-ext/src/main/browser/status-bar-message-registry-main.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (C) 2018 Red Hat, Inc. and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
import {interfaces} from 'inversify'; | ||
import * as types from '../../plugin/types-impl'; | ||
import {StatusBarMessageRegistryMain} from '../../api/plugin-api'; | ||
import {StatusBar, StatusBarAlignment} from '@theia/core/lib/browser/status-bar/status-bar'; | ||
|
||
const STATUS_BAR_MESSAGE_PRE = 'status-bar-entry'; | ||
|
||
export class StatusBarMessageRegistryMainImpl implements StatusBarMessageRegistryMain { | ||
private delegate: StatusBar; | ||
|
||
private ids: string[] = []; | ||
|
||
constructor(container: interfaces.Container) { | ||
this.delegate = container.get(StatusBar); | ||
} | ||
|
||
$setMessage(text: string, | ||
priority: number, | ||
alignment: number, | ||
color: string | undefined, | ||
tooltip: string | undefined, | ||
command: string | undefined): PromiseLike<string> { | ||
const id = this.uniqueId; | ||
this.ids.push(id); | ||
|
||
const entry = { | ||
text, | ||
priority, | ||
alignment: alignment === types.StatusBarAlignment.Left ? StatusBarAlignment.LEFT : StatusBarAlignment.RIGHT, | ||
color, | ||
tooltip, | ||
command | ||
}; | ||
|
||
return this.delegate.setElement(id, entry).then(() => Promise.resolve(id)); | ||
} | ||
|
||
$dispose(id: string): void { | ||
this.delegate.removeElement(id).then(() => { | ||
const index = this.ids.indexOf(id); | ||
if (index > -1) { | ||
this.ids.splice(index, 1); | ||
} | ||
}); | ||
} | ||
|
||
private get uniqueId(): string { | ||
let extensionId = STATUS_BAR_MESSAGE_PRE; | ||
for (let counter = 0; counter < 100; counter++) { | ||
extensionId = `${STATUS_BAR_MESSAGE_PRE}_id_${('0000' + (Math.random() * Math.pow(36, 4) << 0).toString(36)).slice(-4)}`; | ||
if (this.ids.indexOf(extensionId) === -1) { | ||
break; | ||
} | ||
} | ||
return extensionId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/plugin-ext/src/plugin/status-bar-message-registry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (C) 2018 Red Hat, Inc. and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
import {Disposable, StatusBarAlignment} from './types-impl'; | ||
import {StatusBarItem} from '@theia/plugin'; | ||
import { | ||
PLUGIN_RPC_CONTEXT as Ext, StatusBarMessageRegistryMain | ||
} from '../api/plugin-api'; | ||
import {RPCProtocol} from '../api/rpc-protocol'; | ||
import {StatusBarItemImpl} from "./status-bar/status-bar-item"; | ||
|
||
export class StatusBarMessageRegistryExt { | ||
|
||
proxy: StatusBarMessageRegistryMain; | ||
|
||
constructor(rpc: RPCProtocol) { | ||
this.proxy = rpc.getProxy(Ext.STATUS_BAR_MESSAGE_REGISTRY_MAIN); | ||
} | ||
|
||
setStatusBarMessage(text: string, arg?: number | PromiseLike<any>): Disposable { | ||
let id: string; | ||
this.proxy.$setMessage(text, 0, 1, undefined, undefined, undefined).then((messageId: string) => { | ||
id = messageId; | ||
}); | ||
let handle: NodeJS.Timer; | ||
|
||
if (typeof arg === 'number') { | ||
handle = setTimeout(() => this.dispose(id), <number>arg); | ||
} else if (typeof arg !== 'undefined') { | ||
arg.then(() => this.dispose(id), () => this.dispose(id)); | ||
} | ||
|
||
return Disposable.create(() => { | ||
this.dispose(id); | ||
if (handle) { | ||
clearTimeout(handle); | ||
} | ||
}); | ||
} | ||
|
||
private dispose(id: string): void { | ||
if (!id) { | ||
return; | ||
} | ||
this.proxy.$dispose(id); | ||
} | ||
|
||
createStatusBarItem(alignment?: StatusBarAlignment, priority?: number): StatusBarItem { | ||
return new StatusBarItemImpl(this.proxy, alignment, priority); | ||
} | ||
} |
140 changes: 140 additions & 0 deletions
140
packages/plugin-ext/src/plugin/status-bar/status-bar-item.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/* | ||
* Copyright (C) 2018 Red Hat, Inc. and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
import {StatusBarItem} from '@theia/plugin'; | ||
import {ThemeColor, StatusBarAlignment} from '../types-impl'; | ||
import {StatusBarMessageRegistryMain} from "../../api/plugin-api"; | ||
|
||
export class StatusBarItemImpl implements StatusBarItem { | ||
private _messageId: string; | ||
private _alignment: StatusBarAlignment; | ||
private _priority: number; | ||
|
||
private _text: string; | ||
private _tooltip: string; | ||
private _color: string | ThemeColor; | ||
private _command: string; | ||
|
||
private _isVisible: boolean; | ||
private _timeoutHandle: NodeJS.Timer | undefined; | ||
|
||
_proxy: StatusBarMessageRegistryMain; | ||
|
||
constructor(_proxy: StatusBarMessageRegistryMain, | ||
alignment: StatusBarAlignment = StatusBarAlignment.Left, | ||
priority: number = 0) { | ||
this._proxy = _proxy; | ||
this._alignment = alignment; | ||
this._priority = priority; | ||
} | ||
|
||
public get alignment(): StatusBarAlignment { | ||
return this._alignment; | ||
} | ||
|
||
public get priority(): number { | ||
return this._priority; | ||
} | ||
|
||
public get text(): string { | ||
return this._text; | ||
} | ||
|
||
public get tooltip(): string { | ||
return this._tooltip; | ||
} | ||
|
||
public get color(): string | ThemeColor { | ||
return this._color; | ||
} | ||
|
||
public get command(): string { | ||
return this._command; | ||
} | ||
|
||
public set text(text: string) { | ||
this._text = text; | ||
this.update(); | ||
} | ||
|
||
public set tooltip(tooltip: string) { | ||
this._tooltip = tooltip; | ||
this.update(); | ||
} | ||
|
||
public set color(color: string | ThemeColor) { | ||
this._color = color; | ||
this.update(); | ||
} | ||
|
||
public set command(command: string) { | ||
this._command = command; | ||
this.update(); | ||
} | ||
|
||
public show(): void { | ||
this._isVisible = true; | ||
this.update(); | ||
} | ||
|
||
public hide(): void { | ||
if (this._timeoutHandle) { | ||
clearTimeout(this._timeoutHandle); | ||
} | ||
if (this._messageId) { | ||
this._proxy.$dispose(this._messageId); | ||
} | ||
this._isVisible = false; | ||
} | ||
|
||
private update(): void { | ||
if (!this._isVisible) { | ||
return; | ||
} | ||
|
||
if (this._messageId) { | ||
this._proxy.$dispose(this._messageId); | ||
} | ||
|
||
if (this._timeoutHandle) { | ||
clearTimeout(this._timeoutHandle); | ||
} | ||
|
||
// Defer the update so that multiple changes to setters don't cause a redraw each | ||
this._timeoutHandle = setTimeout(() => { | ||
this._timeoutHandle = undefined; | ||
|
||
// Set to status bar | ||
this._proxy.$setMessage(this.text, | ||
this.priority, | ||
this.alignment, | ||
this.getColor(), | ||
this.tooltip, | ||
this.command).then((id: string) => { | ||
this._messageId = id; | ||
}); | ||
}, 0); | ||
} | ||
|
||
private getColor(): string | undefined { | ||
if (typeof this.color !== 'string') { | ||
const colorId = (<ThemeColor>this.color).id; | ||
// TODO implement ThemeColor for vs (redo it) | ||
const vsColorMap: Map<string, string> = new Map([ | ||
['statusBar.foreground', '--theia-layout-color4'], | ||
['editorOverviewRuler.errorForeground', '--theia-error-color0'], | ||
['editorOverviewRuler.warningForeground', '--theia-warn-color0'], | ||
['editorOverviewRuler.infoForeground', '--theia-info-color0'], | ||
]); | ||
return `var(${vsColorMap.has(colorId) ? vsColorMap.get(colorId) : colorId})`; | ||
} | ||
return this.color; | ||
} | ||
|
||
public dispose(): void { | ||
this.hide(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.