77import { TPromise } from 'vs/base/common/winjs.base' ;
88import nls = require( 'vs/nls' ) ;
99import { IAction , Action } from 'vs/base/common/actions' ;
10- import { IOutputService , OUTPUT_PANEL_ID , IOutputChannelRegistry , Extensions as OutputExt } from 'vs/workbench/parts/output/common/output' ;
10+ import { IOutputService , OUTPUT_PANEL_ID , IOutputChannelRegistry , Extensions as OutputExt , IOutputChannelIdentifier } from 'vs/workbench/parts/output/common/output' ;
1111import { SelectActionItem } from 'vs/base/browser/ui/actionbar/actionbar' ;
1212import { IPartService } from 'vs/workbench/services/part/common/partService' ;
1313import { IPanelService } from 'vs/workbench/services/panel/common/panelService' ;
@@ -17,6 +17,7 @@ import { attachSelectBoxStyler } from 'vs/platform/theme/common/styler';
1717import { IThemeService } from 'vs/platform/theme/common/themeService' ;
1818import { IContextViewService } from 'vs/platform/contextview/browser/contextView' ;
1919import { Registry } from 'vs/platform/registry/common/platform' ;
20+ import { groupBy } from 'vs/base/common/arrays' ;
2021
2122export class ToggleOutputAction extends TogglePanelAction {
2223
@@ -107,6 +108,8 @@ export class SwitchOutputAction extends Action {
107108
108109export class SwitchOutputActionItem extends SelectActionItem {
109110
111+ private static readonly SEPARATOR = '─────────' ;
112+
110113 constructor (
111114 action : IAction ,
112115 @IOutputService private outputService : IOutputService ,
@@ -116,34 +119,41 @@ export class SwitchOutputActionItem extends SelectActionItem {
116119 super ( null , action , [ ] , 0 , contextViewService ) ;
117120
118121 let outputChannelRegistry = < IOutputChannelRegistry > Registry . as ( OutputExt . OutputChannels ) ;
119- this . toDispose . push ( outputChannelRegistry . onDidRegisterChannel ( ( ) => this . updateOtions ( ) ) ) ;
120- this . toDispose . push ( outputChannelRegistry . onDidRemoveChannel ( ( ) => this . updateOtions ( ) ) ) ;
121- this . toDispose . push ( this . outputService . onActiveOutputChannel ( activeChannelId => this . setOptions ( this . getOptions ( ) , this . getSelected ( activeChannelId ) ) ) ) ;
122+ this . toDispose . push ( outputChannelRegistry . onDidRegisterChannel ( ( ) => this . updateOtions ( this . outputService . getActiveChannel ( ) . id ) ) ) ;
123+ this . toDispose . push ( outputChannelRegistry . onDidRemoveChannel ( ( ) => this . updateOtions ( this . outputService . getActiveChannel ( ) . id ) ) ) ;
124+ this . toDispose . push ( this . outputService . onActiveOutputChannel ( activeChannelId => this . updateOtions ( activeChannelId ) ) ) ;
122125 this . toDispose . push ( attachSelectBoxStyler ( this . selectBox , themeService ) ) ;
123126
124- this . setOptions ( this . getOptions ( ) , this . getSelected ( this . outputService . getActiveChannel ( ) . id ) ) ;
127+ this . updateOtions ( this . outputService . getActiveChannel ( ) . id ) ;
125128 }
126129
127130 protected getActionContext ( option : string ) : string {
128131 const channel = this . outputService . getChannels ( ) . filter ( channelData => channelData . label === option ) . pop ( ) ;
129-
130132 return channel ? channel . id : option ;
131133 }
132134
133- private getOptions ( ) : string [ ] {
134- return this . outputService . getChannels ( ) . map ( c => c . label ) ;
135- }
136-
137- private updateOtions ( ) : void {
138- const activeChannelIndex = this . getSelected ( this . outputService . getActiveChannel ( ) . id ) ;
139- this . setOptions ( this . getOptions ( ) , activeChannelIndex ) ;
140- }
141-
142- private getSelected ( outputId : string ) : number {
143- if ( ! outputId ) {
144- return undefined ;
135+ private updateOtions ( selectedChannel : string ) : void {
136+ const groups = groupBy ( this . outputService . getChannels ( ) , ( c1 : IOutputChannelIdentifier , c2 : IOutputChannelIdentifier ) => {
137+ if ( ! c1 . file && c2 . file ) {
138+ return - 1 ;
139+ }
140+ if ( c1 . file && ! c2 . file ) {
141+ return 1 ;
142+ }
143+ return 0 ;
144+ } ) ;
145+ const channels = groups [ 0 ] || [ ] ;
146+ const fileChannels = groups [ 1 ] || [ ] ;
147+ const showSeparator = channels . length && fileChannels . length ;
148+ const separatorIndex = showSeparator ? channels . length : - 1 ;
149+ const options : string [ ] = [ ...channels . map ( c => c . label ) , ...( showSeparator ? [ SwitchOutputActionItem . SEPARATOR ] : [ ] ) , ...fileChannels . map ( c => c . label ) ] ;
150+ let selected = 0 ;
151+ if ( selectedChannel ) {
152+ selected = channels . map ( c => c . id ) . indexOf ( selectedChannel ) ;
153+ if ( selected === - 1 ) {
154+ selected = separatorIndex + 1 + fileChannels . map ( c => c . id ) . indexOf ( selectedChannel ) ;
155+ }
145156 }
146-
147- return Math . max ( 0 , this . outputService . getChannels ( ) . map ( c => c . id ) . indexOf ( outputId ) ) ;
157+ this . setOptions ( options , Math . max ( 0 , selected ) , separatorIndex !== - 1 ? separatorIndex : void 0 ) ;
148158 }
149159}
0 commit comments