diff --git a/packages/output/src/browser/output-contribution.ts b/packages/output/src/browser/output-contribution.ts index 2303d9a0ba17c..26ece2d8f5a28 100644 --- a/packages/output/src/browser/output-contribution.ts +++ b/packages/output/src/browser/output-contribution.ts @@ -19,6 +19,7 @@ import { AbstractViewContribution } from '@theia/core/lib/browser/shell/view-con import { Widget, KeybindingRegistry, KeybindingContext, ApplicationShell } from '@theia/core/lib/browser'; import { OUTPUT_WIDGET_KIND, OutputWidget } from './output-widget'; import { Command, CommandRegistry } from '@theia/core/lib/common'; +import { OutputChannelManager } from '../common/output-channel'; export namespace OutputCommands { @@ -37,6 +38,12 @@ export namespace OutputCommands { label: 'Select All' }; + export const SCROLL_LOCK: Command = { + id: 'output:scrollLock', + label: 'Toggle Auto Scroll in Selected Channel', + category: OUTPUT_CATEGORY + }; + } /** @@ -64,6 +71,9 @@ export class OutputContribution extends AbstractViewContribution { @inject(OutputWidgetIsActiveContext) protected readonly outputIsActiveContext: OutputWidgetIsActiveContext; + @inject(OutputChannelManager) + protected readonly outputChannelManager: OutputChannelManager; + constructor() { super({ widgetId: OUTPUT_WIDGET_KIND, @@ -88,6 +98,11 @@ export class OutputContribution extends AbstractViewContribution { isVisible: () => this.outputIsActiveContext.isEnabled(), execute: widget => this.withWidget(widget, outputWidget => outputWidget.selectAll()) }); + commands.registerCommand(OutputCommands.SCROLL_LOCK, { + isEnabled: () => this.outputIsActiveContext.isEnabled(), + isVisible: () => this.outputIsActiveContext.isEnabled(), + execute: () => this.outputChannelManager.toggleScrollLock() + }); } registerKeybindings(registry: KeybindingRegistry): void { diff --git a/packages/output/src/browser/output-frontend-module.ts b/packages/output/src/browser/output-frontend-module.ts index fdf9fdfb36489..b45f3cc75e7f0 100644 --- a/packages/output/src/browser/output-frontend-module.ts +++ b/packages/output/src/browser/output-frontend-module.ts @@ -16,7 +16,7 @@ import { ContainerModule } from 'inversify'; import { OutputWidget, OUTPUT_WIDGET_KIND } from './output-widget'; -import { WidgetFactory, bindViewContribution, KeybindingContext } from '@theia/core/lib/browser'; +import { WidgetFactory, bindViewContribution, KeybindingContext, FrontendApplicationContribution } from '@theia/core/lib/browser'; import { OutputContribution, OutputWidgetIsActiveContext } from './output-contribution'; import { OutputToolbarContribution } from './output-toolbar-contribution'; import { OutputChannelManager } from '../common/output-channel'; @@ -27,6 +27,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => { bindOutputPreferences(bind); bind(OutputWidget).toSelf(); bind(OutputChannelManager).toSelf().inSingletonScope(); + bind(FrontendApplicationContribution).toService(OutputChannelManager); bind(WidgetFactory).toDynamicValue(context => ({ id: OUTPUT_WIDGET_KIND, diff --git a/packages/output/src/browser/output-toolbar-contribution.tsx b/packages/output/src/browser/output-toolbar-contribution.tsx index 45a2cfd8b4197..7b0ec46a532cb 100644 --- a/packages/output/src/browser/output-toolbar-contribution.tsx +++ b/packages/output/src/browser/output-toolbar-contribution.tsx @@ -17,8 +17,9 @@ import { inject, injectable } from 'inversify'; import { OutputWidget } from './output-widget'; import { OutputChannelManager } from '../common/output-channel'; +import { DisposableCollection } from '@theia/core/lib/common/disposable'; import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar'; -import { OutputCommands } from './output-contribution'; +import { OutputCommands, OutputContribution } from './output-contribution'; import * as React from 'react'; @injectable() @@ -27,20 +28,30 @@ export class OutputToolbarContribution implements TabBarToolbarContribution { @inject(OutputChannelManager) protected readonly outputChannelManager: OutputChannelManager; + @inject(OutputContribution) + protected readonly outputContribution: OutputContribution; + async registerToolbarItems(toolbarRegistry: TabBarToolbarRegistry): Promise { toolbarRegistry.registerItem({ id: 'channels', render: () => this.renderChannelSelector(), - isVisible: widget => (widget instanceof OutputWidget), + isVisible: widget => widget instanceof OutputWidget, onDidChange: this.outputChannelManager.onListOrSelectionChange }); - toolbarRegistry.registerItem({ id: OutputCommands.CLEAR_OUTPUT_TOOLBAR.id, command: OutputCommands.CLEAR_OUTPUT_TOOLBAR.id, tooltip: 'Clear Output', priority: 1, }); + toolbarRegistry.registerItem({ + id: OutputCommands.SCROLL_LOCK.id, + render: () => , + isVisible: widget => widget instanceof OutputWidget, + priority: 2 + }); } protected readonly NONE = ''; @@ -55,8 +66,8 @@ export class OutputToolbarContribution implements TabBarToolbarContribution { } return