From b2bf7b133f9bea3d33e6ba600b99ce164ec1438b Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Mon, 27 Jul 2020 15:16:48 +0200 Subject: [PATCH] Added sample for `OutputChannel#show`. Signed-off-by: Akos Kitta --- .../sample-output-channel-with-severity.ts | 61 ++++++++++++++++++- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/examples/api-samples/src/browser/output/sample-output-channel-with-severity.ts b/examples/api-samples/src/browser/output/sample-output-channel-with-severity.ts index 26e23d1dd2445..8b8a38f6ae876 100644 --- a/examples/api-samples/src/browser/output/sample-output-channel-with-severity.ts +++ b/examples/api-samples/src/browser/output/sample-output-channel-with-severity.ts @@ -16,6 +16,10 @@ import { FrontendApplicationContribution } from '@theia/core/lib/browser'; import { inject, injectable, interfaces } from 'inversify'; import { OutputChannelManager, OutputChannelSeverity } from '@theia/output/lib/common/output-channel'; +import { CommandContribution, CommandRegistry } from '@theia/core/lib/common/command'; +import { OutputCommands } from '@theia/output/lib/browser/output-commands'; + +const SAMPLE_CHANNEL_NAME = 'API Sample: my test channel'; @injectable() export class SampleOutputChannelWithSeverity @@ -23,7 +27,7 @@ export class SampleOutputChannelWithSeverity @inject(OutputChannelManager) protected readonly outputChannelManager: OutputChannelManager; public onStart(): void { - const channel = this.outputChannelManager.getChannel('API Sample: my test channel'); + const channel = this.outputChannelManager.getChannel(SAMPLE_CHANNEL_NAME); channel.appendLine('hello info1'); // showed without color channel.appendLine('hello info2', OutputChannelSeverity.Info); channel.appendLine('hello error', OutputChannelSeverity.Error); @@ -31,11 +35,64 @@ export class SampleOutputChannelWithSeverity channel.append('inlineInfo1 '); channel.append('inlineWarning ', OutputChannelSeverity.Warning); channel.append('inlineError ', OutputChannelSeverity.Error); - channel.append('inlineInfo2', OutputChannelSeverity.Info); + channel.append('inlineInfo2\n', OutputChannelSeverity.Info); + } +} +@injectable() +export class SampleOutputChannelCommandContribution implements CommandContribution { + @inject(OutputChannelManager) + private readonly outputChannelManager: OutputChannelManager; + registerCommands(r: CommandRegistry): void { + r.registerCommand({ id: 'sample-output:show-command:preserve-focus', label: 'Show channel (command, explicit, preserve-focus)', category: 'API-Samples' }, { + execute: () => { + const channel = this.outputChannelManager.getChannel(SAMPLE_CHANNEL_NAME); + channel.appendLine('Show channel (command, explicit, preserve-focus) -> the Output widget should be revealed but must not be active.'); + r.executeCommand(OutputCommands.SHOW.id, { name: SAMPLE_CHANNEL_NAME, options: { preserveFocus: true } }); + } + }); + r.registerCommand({ id: 'sample-output:show-command:preserve-focus-implicit', label: 'Show channel (command, implicit, no preserve-focus)', category: 'API-Samples' }, { + execute: () => { + const channel = this.outputChannelManager.getChannel(SAMPLE_CHANNEL_NAME); + channel.appendLine('Show channel (command, implicit, no preserve-focus) -> the Output widget should be active.'); + r.executeCommand(OutputCommands.SHOW.id, { name: SAMPLE_CHANNEL_NAME }); + } + }); + r.registerCommand({ id: 'sample-output:show-command:no-preserve-focus-explicit', label: 'Show channel (command, explicit, no preserve-focus)', category: 'API-Samples' }, { + execute: () => { + const channel = this.outputChannelManager.getChannel(SAMPLE_CHANNEL_NAME); + channel.appendLine('Show channel (command, explicit, no preserve-focus) -> the Output widget should be active.'); + r.executeCommand(OutputCommands.SHOW.id, { name: SAMPLE_CHANNEL_NAME, options: { preserveFocus: false } }); + } + }); + + r.registerCommand({ id: 'sample-output:show-api:preserve-focus', label: 'Show channel (API, explicit, preserve-focus)', category: 'API-Samples' }, { + execute: () => { + const channel = this.outputChannelManager.getChannel(SAMPLE_CHANNEL_NAME); + channel.appendLine('Show channel (API, explicit, preserve-focus) -> the Output widget should be revealed but must not be active.'); + channel.show({ preserveFocus: true }); + } + }); + r.registerCommand({ id: 'sample-output:show-api:preserve-focus-implicit', label: 'Show channel (API, implicit, no preserve-focus)', category: 'API-Samples' }, { + execute: () => { + const channel = this.outputChannelManager.getChannel(SAMPLE_CHANNEL_NAME); + channel.appendLine('Show channel (API, implicit, no preserve-focus) -> the Output widget should be active.'); + channel.show(); + } + }); + r.registerCommand({ id: 'sample-output:show-api:no-preserve-focus-explicit', label: 'Show channel (API, explicit, no preserve-focus)', category: 'API-Samples' }, { + execute: () => { + const channel = this.outputChannelManager.getChannel(SAMPLE_CHANNEL_NAME); + channel.appendLine('Show channel (API, explicit, no preserve-focus) -> the Output widget should be active.'); + channel.show({ preserveFocus: false }); + } + }); } } export const bindSampleOutputChannelWithSeverity = (bind: interfaces.Bind) => { bind(FrontendApplicationContribution) .to(SampleOutputChannelWithSeverity) .inSingletonScope(); + bind(CommandContribution) + .to(SampleOutputChannelCommandContribution) + .inSingletonScope(); };