Skip to content

Commit

Permalink
#39638 Action to open channel in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Dec 14, 2017
1 parent 78cc1e9 commit 35369b7
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/vs/workbench/parts/output/browser/media/open_output.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/vs/workbench/parts/output/browser/media/output.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
background: url('clear_output_inverse.svg') center center no-repeat;
}

.monaco-workbench .output-action.open-output {
background: url('open_output.svg') center center no-repeat;
}

.vs-dark .monaco-workbench .output-action.open-output,
.hc-black .monaco-workbench .output-action.open-output {
background: url('open_output_inverse.svg') center center no-repeat;
}

.monaco-workbench .output-action.output-scroll-lock {
background: url('output_lock.svg') center center no-repeat;
}
Expand Down
17 changes: 17 additions & 0 deletions src/vs/workbench/parts/output/browser/outputActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ export class ClearOutputAction extends Action {
}
}

export class OpenInEditorAction extends Action {

public static readonly ID = 'workbench.output.action.openInEditor';
public static readonly LABEL = nls.localize('openInEditor', "Open in Editor");

constructor(
id: string, label: string,
@IOutputService private outputService: IOutputService
) {
super(id, label, 'output-action open-output');
}

public run(): TPromise<any> {
return this.outputService.showChannelInEditor(this.outputService.getActiveChannel().id);
}
}

export class ToggleOutputScrollLockAction extends Action {

public static readonly ID = 'workbench.output.action.toggleOutputScrollLock';
Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/parts/output/browser/outputPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { EditorInput, EditorOptions } from 'vs/workbench/common/editor';
import { TextResourceEditor } from 'vs/workbench/browser/parts/editor/textResourceEditor';
import { OUTPUT_PANEL_ID, IOutputService, CONTEXT_IN_OUTPUT } from 'vs/workbench/parts/output/common/output';
import { SwitchOutputAction, SwitchOutputActionItem, ClearOutputAction, ToggleOutputScrollLockAction } from 'vs/workbench/parts/output/browser/outputActions';
import { SwitchOutputAction, SwitchOutputActionItem, ClearOutputAction, ToggleOutputScrollLockAction, OpenInEditorAction } from 'vs/workbench/parts/output/browser/outputActions';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
Expand Down Expand Up @@ -55,6 +55,7 @@ export class OutputPanel extends TextResourceEditor {
this.actions = [
this.instantiationService.createInstance(SwitchOutputAction),
this.instantiationService.createInstance(ClearOutputAction, ClearOutputAction.ID, ClearOutputAction.LABEL),
this.instantiationService.createInstance(OpenInEditorAction, OpenInEditorAction.ID, OpenInEditorAction.LABEL),
this.instantiationService.createInstance(ToggleOutputScrollLockAction, ToggleOutputScrollLockAction.ID, ToggleOutputScrollLockAction.LABEL)
];

Expand Down
17 changes: 12 additions & 5 deletions src/vs/workbench/parts/output/browser/outputServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Position } from 'vs/editor/common/core/position';
import { IFileService, FileChangeType } from 'vs/platform/files/common/files';
import { IPanel } from 'vs/workbench/common/panel';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';

const OUTPUT_ACTIVE_CHANNEL_KEY = 'output.activechannel';

Expand Down Expand Up @@ -249,7 +250,8 @@ export class OutputService implements IOutputService {
@IPanelService private panelService: IPanelService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IModelService modelService: IModelService,
@ITextModelService textModelResolverService: ITextModelService
@ITextModelService textModelResolverService: ITextModelService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
) {
const channels = this.getChannels();
this.activeChannelId = this.storageService.get(OUTPUT_ACTIVE_CHANNEL_KEY, StorageScope.WORKSPACE, channels && channels.length > 0 ? channels[0].id : null);
Expand Down Expand Up @@ -279,6 +281,10 @@ export class OutputService implements IOutputService {
.then(() => this._onActiveOutputChannel.fire(id));
}

showChannelInEditor(channelId: string): TPromise<void> {
return this.editorService.openEditor(this.createInput(channelId)) as TPromise;
}

getChannel(id: string): IOutputChannel {
if (!this.channels.has(id)) {
const channelData = Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels).getChannel(id);
Expand Down Expand Up @@ -340,7 +346,7 @@ export class OutputService implements IOutputService {
return channel.show()
.then(() => {
this.storageService.store(OUTPUT_ACTIVE_CHANNEL_KEY, channelId, StorageScope.WORKSPACE);
this._outputPanel.setInput(this.createInput(this.getChannel(channelId)), EditorOptions.create({ preserveFocus: preserveFocus }));
this._outputPanel.setInput(this.createInput(channelId), EditorOptions.create({ preserveFocus: preserveFocus }));
if (!preserveFocus) {
this._outputPanel.focus();
}
Expand All @@ -354,9 +360,10 @@ export class OutputService implements IOutputService {
}
}

private createInput(channel: IOutputChannel): ResourceEditorInput {
const resource = URI.from({ scheme: OUTPUT_SCHEME, path: channel.id });
return this.instantiationService.createInstance(ResourceEditorInput, nls.localize('output', "Output"), channel ? nls.localize('channel', "for '{0}'", channel.label) : '', resource);
private createInput(channelId: string): ResourceEditorInput {
const channelData = Registry.as<IOutputChannelRegistry>(Extensions.OutputChannels).getChannel(channelId);
const resource = URI.from({ scheme: OUTPUT_SCHEME, path: channelData.id });
return this.instantiationService.createInstance(ResourceEditorInput, nls.localize('output', "{0} - Output", channelData.label), nls.localize('channel', "Output channel for '{0}'", channelData.label), resource);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/parts/output/common/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export interface IOutputService {
*/
showChannel(id: string, preserveFocus?: boolean): TPromise<void>;

/**
* Show the channel with the give id in editor
*/
showChannelInEditor(id: string): TPromise<void>;

/**
* Allows to register on Output events.
*/
Expand Down

0 comments on commit 35369b7

Please sign in to comment.