Skip to content

Commit

Permalink
[drop-me]: Added an example.
Browse files Browse the repository at this point in the history
Signed-off-by: Akos Kitta <[email protected]>
  • Loading branch information
Akos Kitta committed Apr 14, 2020
1 parent 6902633 commit fdd86b7
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion examples/api-samples/src/browser/api-samples-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,46 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { ContainerModule } from 'inversify';
import { ContainerModule, inject, injectable } from 'inversify';
import { bindDynamicLabelProvider } from './label/sample-dynamic-label-provider-command-contribution';
import { bindSampleUnclosableView } from './view/sample-unclosable-view-contribution';
import { CommandRegistry, CommandContribution } from '@theia/core/';
import { OutputChannelManager } from '@theia/output/lib/common/output-channel';

export default new ContainerModule(bind => {
bindDynamicLabelProvider(bind);
bindSampleUnclosableView(bind);
bind(CommandContribution).to(SampleOutputChannelsCommandContribution).inSingletonScope();
});

@injectable()
class SampleOutputChannelsCommandContribution implements CommandContribution {

@inject(OutputChannelManager)
private readonly ocm: OutputChannelManager;

private timers = new Map<string, number>();

registerCommands(commands: CommandRegistry): void {
for (const channelName of ['one', 'two', 'three']) {
const command = { id: `post-date-now-${channelName}`, label: `API Sample: Post Date.now() to the '${channelName}' channel.` };
commands.registerCommand(command, {
execute: () => {
const timer = this.timers.get(channelName);
if (timer === undefined) {
this.timers.set(channelName, window.setInterval(() => {
const channel = this.ocm.getChannel(channelName);
if (channel) {
channel.appendLine(`${channelName}: ${Date.now()}`);
}
}, 500));
} else {
window.clearInterval(timer);
this.timers.delete(channelName);
}
}
});
}
}

}

0 comments on commit fdd86b7

Please sign in to comment.