@@ -110,6 +110,10 @@ export const WorkbenchListHasSelectionOrFocus = new RawContextKey<boolean>('list
110
110
export const WorkbenchListDoubleSelection = new RawContextKey < boolean > ( 'listDoubleSelection' , false ) ;
111
111
export const WorkbenchListMultiSelection = new RawContextKey < boolean > ( 'listMultiSelection' , false ) ;
112
112
export 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 ) ;
113
117
export const WorkbenchListAutomaticKeyboardNavigationKey = 'listAutomaticKeyboardNavigation' ;
114
118
115
119
function createScopedContextKeyService ( contextKeyService : IContextKeyService , widget : ListWidget ) : IContextKeyService {
@@ -1087,6 +1091,10 @@ class WorkbenchTreeInternals<TInput, T, TFilterData> {
1087
1091
private hasSelectionOrFocus : IContextKey < boolean > ;
1088
1092
private hasDoubleSelection : IContextKey < boolean > ;
1089
1093
private hasMultiSelection : IContextKey < boolean > ;
1094
+ private treeElementCanCollapse : IContextKey < boolean > ;
1095
+ private treeElementHasParent : IContextKey < boolean > ;
1096
+ private treeElementCanExpand : IContextKey < boolean > ;
1097
+ private treeElementHasChild : IContextKey < boolean > ;
1090
1098
private _useAltAsMultipleSelectionModifier : boolean ;
1091
1099
private disposables : IDisposable [ ] = [ ] ;
1092
1100
private styler : IDisposable | undefined ;
@@ -1117,6 +1125,11 @@ class WorkbenchTreeInternals<TInput, T, TFilterData> {
1117
1125
this . hasDoubleSelection = WorkbenchListDoubleSelection . bindTo ( this . contextKeyService ) ;
1118
1126
this . hasMultiSelection = WorkbenchListMultiSelection . bindTo ( this . contextKeyService ) ;
1119
1127
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
+
1120
1133
this . _useAltAsMultipleSelectionModifier = useAltAsMultipleSelectionModifier ( configurationService ) ;
1121
1134
1122
1135
const interestingContextKeys = new Set ( ) ;
@@ -1132,6 +1145,20 @@ class WorkbenchTreeInternals<TInput, T, TFilterData> {
1132
1145
1133
1146
this . updateStyleOverrides ( overrideStyles ) ;
1134
1147
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
+
1135
1162
this . disposables . push (
1136
1163
this . contextKeyService ,
1137
1164
( listService as ListService ) . register ( tree ) ,
@@ -1150,7 +1177,10 @@ class WorkbenchTreeInternals<TInput, T, TFilterData> {
1150
1177
const focus = tree . getFocus ( ) ;
1151
1178
1152
1179
this . hasSelectionOrFocus . set ( selection . length > 0 || focus . length > 0 ) ;
1180
+ updateCollapseContextKeys ( ) ;
1153
1181
} ) ,
1182
+ tree . onDidChangeCollapseState ( updateCollapseContextKeys ) ,
1183
+ tree . onDidChangeModel ( updateCollapseContextKeys ) ,
1154
1184
configurationService . onDidChangeConfiguration ( e => {
1155
1185
let newOptions : IAbstractTreeOptionsUpdate = { } ;
1156
1186
if ( e . affectsConfiguration ( multiSelectModifierSettingKey ) ) {
0 commit comments