@@ -110,6 +110,10 @@ export const WorkbenchListHasSelectionOrFocus = new RawContextKey<boolean>('list
110110export const WorkbenchListDoubleSelection = new RawContextKey < boolean > ( 'listDoubleSelection' , false ) ;
111111export const WorkbenchListMultiSelection = new RawContextKey < boolean > ( 'listMultiSelection' , false ) ;
112112export const WorkbenchListSelectionNavigation = new RawContextKey < boolean > ( 'listSelectionNavigation' , false ) ;
113+ export const WorkbenchTreeElementCanCollapse = new RawContextKey < boolean > ( 'treeElementCanCollapse' , false ) ;
114+ export const WorkbenchTreeElementHasParent = new RawContextKey < boolean > ( 'treeElementHasParent' , false ) ;
115+ export const WorkbenchTreeElementCanExpand = new RawContextKey < boolean > ( 'treeElementCanExpand' , false ) ;
116+ export const WorkbenchTreeElementHasChild = new RawContextKey < boolean > ( 'treeElementHasChild' , false ) ;
113117export const WorkbenchListAutomaticKeyboardNavigationKey = 'listAutomaticKeyboardNavigation' ;
114118
115119function createScopedContextKeyService ( contextKeyService : IContextKeyService , widget : ListWidget ) : IContextKeyService {
@@ -1087,6 +1091,10 @@ class WorkbenchTreeInternals<TInput, T, TFilterData> {
10871091 private hasSelectionOrFocus : IContextKey < boolean > ;
10881092 private hasDoubleSelection : IContextKey < boolean > ;
10891093 private hasMultiSelection : IContextKey < boolean > ;
1094+ private treeElementCanCollapse : IContextKey < boolean > ;
1095+ private treeElementHasParent : IContextKey < boolean > ;
1096+ private treeElementCanExpand : IContextKey < boolean > ;
1097+ private treeElementHasChild : IContextKey < boolean > ;
10901098 private _useAltAsMultipleSelectionModifier : boolean ;
10911099 private disposables : IDisposable [ ] = [ ] ;
10921100 private styler : IDisposable | undefined ;
@@ -1117,6 +1125,11 @@ class WorkbenchTreeInternals<TInput, T, TFilterData> {
11171125 this . hasDoubleSelection = WorkbenchListDoubleSelection . bindTo ( this . contextKeyService ) ;
11181126 this . hasMultiSelection = WorkbenchListMultiSelection . bindTo ( this . contextKeyService ) ;
11191127
1128+ this . treeElementCanCollapse = WorkbenchTreeElementCanCollapse . bindTo ( this . contextKeyService ) ;
1129+ this . treeElementHasParent = WorkbenchTreeElementHasParent . bindTo ( this . contextKeyService ) ;
1130+ this . treeElementCanExpand = WorkbenchTreeElementCanExpand . bindTo ( this . contextKeyService ) ;
1131+ this . treeElementHasChild = WorkbenchTreeElementHasChild . bindTo ( this . contextKeyService ) ;
1132+
11201133 this . _useAltAsMultipleSelectionModifier = useAltAsMultipleSelectionModifier ( configurationService ) ;
11211134
11221135 const interestingContextKeys = new Set ( ) ;
@@ -1132,6 +1145,20 @@ class WorkbenchTreeInternals<TInput, T, TFilterData> {
11321145
11331146 this . updateStyleOverrides ( overrideStyles ) ;
11341147
1148+ const updateCollapseContextKeys = ( ) => {
1149+ const focus = tree . getFocus ( ) [ 0 ] ;
1150+
1151+ if ( ! focus ) {
1152+ return ;
1153+ }
1154+
1155+ const node = tree . getNode ( focus ) ;
1156+ this . treeElementCanCollapse . set ( node . collapsible && ! node . collapsed ) ;
1157+ this . treeElementHasParent . set ( ! ! tree . getParentElement ( focus ) ) ;
1158+ this . treeElementCanExpand . set ( node . collapsible && node . collapsed ) ;
1159+ this . treeElementHasChild . set ( ! ! tree . getFirstElementChild ( focus ) ) ;
1160+ } ;
1161+
11351162 this . disposables . push (
11361163 this . contextKeyService ,
11371164 ( listService as ListService ) . register ( tree ) ,
@@ -1150,7 +1177,10 @@ class WorkbenchTreeInternals<TInput, T, TFilterData> {
11501177 const focus = tree . getFocus ( ) ;
11511178
11521179 this . hasSelectionOrFocus . set ( selection . length > 0 || focus . length > 0 ) ;
1180+ updateCollapseContextKeys ( ) ;
11531181 } ) ,
1182+ tree . onDidChangeCollapseState ( updateCollapseContextKeys ) ,
1183+ tree . onDidChangeModel ( updateCollapseContextKeys ) ,
11541184 configurationService . onDidChangeConfiguration ( e => {
11551185 let newOptions : IAbstractTreeOptionsUpdate = { } ;
11561186 if ( e . affectsConfiguration ( multiSelectModifierSettingKey ) ) {
0 commit comments