@@ -8,7 +8,7 @@ import { Event, Emitter } from 'vs/base/common/event';
88import { IDisposable , dispose , Disposable , toDisposable } from 'vs/base/common/lifecycle' ;
99import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
1010import { TPromise } from 'vs/base/common/winjs.base' ;
11- import { IAction , IActionItem , ActionRunner } from 'vs/base/common/actions' ;
11+ import { IAction , IActionItem , ActionRunner , Action } from 'vs/base/common/actions' ;
1212import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
1313import { IContextMenuService } from 'vs/platform/contextview/browser/contextView' ;
1414import { IMenuService , MenuId , MenuItemAction } from 'vs/platform/actions/common/actions' ;
@@ -36,26 +36,25 @@ import { ViewletPanel, IViewletPanelOptions } from 'vs/workbench/browser/parts/v
3636import { IMouseEvent } from 'vs/base/browser/mouseEvent' ;
3737import { localize } from 'vs/nls' ;
3838import { timeout } from 'vs/base/common/async' ;
39+ import { CollapseAllAction } from 'vs/base/parts/tree/browser/treeDefaults' ;
3940
4041export class CustomTreeViewPanel extends ViewletPanel {
4142
42- private menus : TitleMenus ;
4343 private treeViewer : ITreeViewer ;
4444
4545 constructor (
4646 options : IViewletViewOptions ,
4747 @INotificationService private notificationService : INotificationService ,
4848 @IKeybindingService keybindingService : IKeybindingService ,
4949 @IContextMenuService contextMenuService : IContextMenuService ,
50- @IInstantiationService private instantiationService : IInstantiationService ,
5150 @IConfigurationService configurationService : IConfigurationService ,
5251 @IViewsService viewsService : IViewsService ,
5352 ) {
5453 super ( { ...( options as IViewletPanelOptions ) , ariaHeaderLabel : options . title } , keybindingService , contextMenuService , configurationService ) ;
55- this . treeViewer = ( < ICustomViewDescriptor > ViewsRegistry . getView ( options . id ) ) . treeViewer ;
54+ const { treeViewer } = ( < ICustomViewDescriptor > ViewsRegistry . getView ( options . id ) ) ;
55+ this . treeViewer = treeViewer ;
56+ this . treeViewer . onDidChangeActions ( ( ) => this . updateActions ( ) , this , this . disposables ) ;
5657 this . disposables . push ( toDisposable ( ( ) => this . treeViewer . setVisibility ( false ) ) ) ;
57- this . menus = this . instantiationService . createInstance ( TitleMenus , this . id ) ;
58- this . menus . onDidChangeTitle ( ( ) => this . updateActions ( ) , this , this . disposables ) ;
5958 this . updateTreeVisibility ( ) ;
6059 }
6160
@@ -83,11 +82,11 @@ export class CustomTreeViewPanel extends ViewletPanel {
8382 }
8483
8584 getActions ( ) : IAction [ ] {
86- return [ ...this . menus . getTitleActions ( ) ] ;
85+ return [ ...this . treeViewer . getPrimaryActions ( ) ] ;
8786 }
8887
8988 getSecondaryActions ( ) : IAction [ ] {
90- return this . menus . getTitleSecondaryActions ( ) ;
89+ return [ ... this . treeViewer . getSecondaryActions ( ) ] ;
9190 }
9291
9392 getActionItem ( action : IAction ) : IActionItem {
@@ -180,13 +179,15 @@ export class CustomTreeViewer extends Disposable implements ITreeViewer {
180179 private activated : boolean = false ;
181180 private _hasIconForParentNode = false ;
182181 private _hasIconForLeafNode = false ;
182+ private _showCollapseAllAction = false ;
183183
184184 private domNode : HTMLElement ;
185185 private treeContainer : HTMLElement ;
186186 private message : HTMLDivElement ;
187187 private tree : FileIconThemableWorkbenchTree ;
188188 private root : ITreeItem ;
189189 private elementsToRefresh : ITreeItem [ ] = [ ] ;
190+ private menus : TitleMenus ;
190191
191192 private _dataProvider : ITreeViewDataProvider ;
192193
@@ -202,6 +203,9 @@ export class CustomTreeViewer extends Disposable implements ITreeViewer {
202203 private _onDidChangeVisibility : Emitter < boolean > = this . _register ( new Emitter < boolean > ( ) ) ;
203204 readonly onDidChangeVisibility : Event < boolean > = this . _onDidChangeVisibility . event ;
204205
206+ private _onDidChangeActions : Emitter < void > = this . _register ( new Emitter < void > ( ) ) ;
207+ readonly onDidChangeActions : Event < void > = this . _onDidChangeActions . event ;
208+
205209 constructor (
206210 private id : string ,
207211 private container : ViewContainer ,
@@ -214,6 +218,8 @@ export class CustomTreeViewer extends Disposable implements ITreeViewer {
214218 ) {
215219 super ( ) ;
216220 this . root = new Root ( ) ;
221+ this . menus = this . _register ( this . instantiationService . createInstance ( TitleMenus , this . id ) ) ;
222+ this . _register ( this . menus . onDidChangeTitle ( ( ) => this . _onDidChangeActions . fire ( ) ) ) ;
217223 this . _register ( this . themeService . onDidFileIconThemeChange ( ( ) => this . doRefresh ( [ this . root ] ) /** soft refresh **/ ) ) ;
218224 this . _register ( this . themeService . onThemeChange ( ( ) => this . doRefresh ( [ this . root ] ) /** soft refresh **/ ) ) ;
219225 this . _register ( this . configurationService . onDidChangeConfiguration ( e => {
@@ -263,6 +269,30 @@ export class CustomTreeViewer extends Disposable implements ITreeViewer {
263269 return this . isVisible ;
264270 }
265271
272+ get showCollapseAllAction ( ) : boolean {
273+ return this . _showCollapseAllAction ;
274+ }
275+
276+ set showCollapseAllAction ( showCollapseAllAction : boolean ) {
277+ if ( this . _showCollapseAllAction !== ! ! showCollapseAllAction ) {
278+ this . _showCollapseAllAction = ! ! showCollapseAllAction ;
279+ this . _onDidChangeActions . fire ( ) ;
280+ }
281+ }
282+
283+ getPrimaryActions ( ) : IAction [ ] {
284+ if ( this . showCollapseAllAction ) {
285+ const collapseAllAction = new Action ( 'vs.tree.collapse' , localize ( 'collapse' , "Collapse" ) , 'monaco-tree-action collapse-all' , true , ( ) => this . tree ? new CollapseAllAction ( this . tree , true ) . run ( ) : Promise . resolve ( ) ) ;
286+ return [ ...this . menus . getTitleActions ( ) , collapseAllAction ] ;
287+ } else {
288+ return this . menus . getTitleActions ( ) ;
289+ }
290+ }
291+
292+ getSecondaryActions ( ) : IAction [ ] {
293+ return this . menus . getTitleSecondaryActions ( ) ;
294+ }
295+
266296 setVisibility ( isVisible : boolean ) : void {
267297 isVisible = ! ! isVisible ;
268298 if ( this . isVisible === isVisible ) {
0 commit comments