This repository has been archived by the owner on Jun 20, 2018. It is now read-only.
forked from eclipse-theia/theia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CHE-9836 add output channel API (#32)
Signed-off-by: Oleksii Orel <oorel@redhat.com>
- Loading branch information
Showing
9 changed files
with
256 additions
and
5 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
87 changes: 87 additions & 0 deletions
87
packages/plugin-ext/src/main/browser/output-channel-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,87 @@ | ||
/* | ||
* 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 {OUTPUT_WIDGET_KIND} from '@theia/output/lib/browser/output-widget'; | ||
import {OutputChannel, OutputChannelManager} from '@theia/output/lib/common/output-channel'; | ||
import {OutputChannelRegistryMain} from '../../api/plugin-api'; | ||
|
||
export class OutputChannelRegistryMainImpl implements OutputChannelRegistryMain { | ||
private delegate: OutputChannelManager; | ||
|
||
private channels: Map<string, OutputChannel> = new Map(); | ||
|
||
constructor(container: interfaces.Container) { | ||
this.delegate = container.get(OutputChannelManager); | ||
} | ||
|
||
$append(channelName: string, value: string): PromiseLike<void> { | ||
const outputChannel = this.getChannels(channelName); | ||
if (outputChannel) { | ||
outputChannel.append(value); | ||
} | ||
|
||
return Promise.resolve(); | ||
} | ||
|
||
$clear(channelName: string): PromiseLike<void> { | ||
const outputChannel = this.getChannels(channelName); | ||
if (outputChannel) { | ||
outputChannel.clear(); | ||
} | ||
|
||
return Promise.resolve(); | ||
} | ||
|
||
$dispose(channelName: string): PromiseLike<void> { | ||
this.delegate.deleteChannel(channelName); | ||
if (this.channels.has(channelName)) { | ||
this.channels.delete(channelName); | ||
} | ||
|
||
return Promise.resolve(); | ||
} | ||
|
||
$reveal(channelName: string, preserveFocus: boolean): PromiseLike<void> { | ||
const outputChannel = this.getChannels(channelName); | ||
if (outputChannel) { | ||
outputChannel.setVisibility(true); | ||
if (!preserveFocus) { | ||
this.setOutputChannelFocus(); | ||
} | ||
} | ||
|
||
return Promise.resolve(); | ||
} | ||
|
||
$close(channelName: string): PromiseLike<void> { | ||
const outputChannel = this.getChannels(channelName); | ||
if (outputChannel) { | ||
outputChannel.setVisibility(false); | ||
} | ||
|
||
return Promise.resolve(); | ||
} | ||
|
||
private getChannels(channelName: string): OutputChannel | undefined { | ||
let outputChannel: OutputChannel | undefined; | ||
if (this.channels.has(channelName)) { | ||
outputChannel = this.channels.get(channelName); | ||
} else { | ||
outputChannel = this.delegate.getChannel(channelName); | ||
this.channels.set(channelName, outputChannel); | ||
} | ||
|
||
return outputChannel; | ||
} | ||
|
||
private setOutputChannelFocus(): void { | ||
const outputWidget = document.getElementById(OUTPUT_WIDGET_KIND); | ||
if (outputWidget) { | ||
outputWidget.focus(); | ||
} | ||
} | ||
} |
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,30 @@ | ||
/* | ||
* 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 { | ||
PLUGIN_RPC_CONTEXT as Ext, OutputChannelRegistryMain | ||
} from '../api/plugin-api'; | ||
import { RPCProtocol } from '../api/rpc-protocol'; | ||
import * as theia from '@theia/plugin'; | ||
import { OutputChannelImpl } from './output-channel/output-channel-item'; | ||
|
||
export class OutputChannelRegistryExt { | ||
|
||
proxy: OutputChannelRegistryMain; | ||
|
||
constructor(rpc: RPCProtocol) { | ||
this.proxy = rpc.getProxy(Ext.OUTPUT_CHANNEL_REGISTRY_MAIN); | ||
} | ||
|
||
createOutputChannel(name: string): theia.OutputChannel { | ||
name = name.trim(); | ||
if (!name) { | ||
throw new Error('illegal argument \'name\'. must not be falsy'); | ||
} else { | ||
return new OutputChannelImpl(name, this.proxy); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
packages/plugin-ext/src/plugin/output-channel/output-channel-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,55 @@ | ||
/* | ||
* 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 * as theia from '@theia/plugin'; | ||
import {OutputChannelRegistryMain} from '../../api/plugin-api'; | ||
|
||
export class OutputChannelImpl implements theia.OutputChannel { | ||
|
||
private disposed: boolean; | ||
|
||
constructor(readonly name: string, private proxy: OutputChannelRegistryMain) { | ||
} | ||
|
||
dispose(): void { | ||
if (!this.disposed) { | ||
this.proxy.$dispose(this.name).then(() => { | ||
this.disposed = true; | ||
}); | ||
} | ||
} | ||
|
||
append(value: string): void { | ||
this.validate(); | ||
this.proxy.$append(this.name, value); | ||
} | ||
|
||
appendLine(value: string): void { | ||
this.validate(); | ||
this.append(value + '\n'); | ||
} | ||
|
||
clear(): void { | ||
this.validate(); | ||
this.proxy.$clear(this.name); | ||
} | ||
|
||
show(preserveFocus: boolean | undefined): void { | ||
this.validate(); | ||
this.proxy.$reveal(this.name, !!preserveFocus); | ||
} | ||
|
||
hide(): void { | ||
this.validate(); | ||
this.proxy.$close(this.name); | ||
} | ||
|
||
private validate(): void { | ||
if (this.disposed) { | ||
throw new Error('Channel has been closed'); | ||
} | ||
} | ||
} |
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
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