5
5
6
6
import './media/statusbarpart.css' ;
7
7
import { localize } from '../../../../nls.js' ;
8
- import { Disposable , DisposableStore , dispose , disposeIfDisposable , IDisposable , MutableDisposable , toDisposable } from '../../../../base/common/lifecycle.js' ;
8
+ import { Disposable , DisposableStore , disposeIfDisposable , IDisposable , MutableDisposable , toDisposable } from '../../../../base/common/lifecycle.js' ;
9
9
import { MultiWindowParts , Part } from '../../part.js' ;
10
10
import { EventType as TouchEventType , Gesture , GestureEvent } from '../../../../base/browser/touch.js' ;
11
11
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js' ;
12
- import { StatusbarAlignment , IStatusbarService , IStatusbarEntry , IStatusbarEntryAccessor , IStatusbarStyleOverride , isStatusbarEntryLocation , IStatusbarEntryLocation , isStatusbarEntryPriority , IStatusbarEntryPriority } from '../../../services/statusbar/browser/statusbar.js' ;
12
+ import { StatusbarAlignment , IStatusbarService , IStatusbarEntry , IStatusbarEntryAccessor , IStatusbarStyleOverride , isStatusbarEntryLocation , IStatusbarEntryLocation , isStatusbarEntryPriority , IStatusbarEntryPriority , IStatusbarEntryOverride } from '../../../services/statusbar/browser/statusbar.js' ;
13
13
import { IContextMenuService } from '../../../../platform/contextview/browser/contextView.js' ;
14
14
import { IAction , Separator , toAction } from '../../../../base/common/actions.js' ;
15
15
import { IThemeService } from '../../../../platform/theme/common/themeService.js' ;
@@ -75,6 +75,12 @@ export interface IStatusbarEntryContainer extends IDisposable {
75
75
*/
76
76
updateEntryVisibility ( id : string , visible : boolean ) : void ;
77
77
78
+ /**
79
+ * Allows to override the appearance of an entry with the provided ID. Only a subset
80
+ * of properties is allowed to be overridden.
81
+ */
82
+ overrideEntry ( id : string , override : IStatusbarEntryOverride ) : IDisposable ;
83
+
78
84
/**
79
85
* Focused the status bar. If one of the status bar entries was focused, focuses it directly.
80
86
*/
@@ -134,6 +140,9 @@ class StatusbarPart extends Part implements IStatusbarEntryContainer {
134
140
private readonly _onWillDispose = this . _register ( new Emitter < void > ( ) ) ;
135
141
readonly onWillDispose = this . _onWillDispose . event ;
136
142
143
+ private readonly onDidOverrideEntry = this . _register ( new Emitter < string > ( ) ) ;
144
+ private readonly entryOverrides = new Map < string , IStatusbarEntryOverride > ( ) ;
145
+
137
146
private leftItemsContainer : HTMLElement | undefined ;
138
147
private rightItemsContainer : HTMLElement | undefined ;
139
148
@@ -173,6 +182,28 @@ class StatusbarPart extends Part implements IStatusbarEntryContainer {
173
182
this . _register ( this . contextService . onDidChangeWorkbenchState ( ( ) => this . updateStyles ( ) ) ) ;
174
183
}
175
184
185
+ overrideEntry ( id : string , override : IStatusbarEntryOverride ) : IDisposable {
186
+ this . entryOverrides . set ( id , override ) ;
187
+ this . onDidOverrideEntry . fire ( id ) ;
188
+
189
+ return toDisposable ( ( ) => {
190
+ const currentOverride = this . entryOverrides . get ( id ) ;
191
+ if ( currentOverride === override ) {
192
+ this . entryOverrides . delete ( id ) ;
193
+ this . onDidOverrideEntry . fire ( id ) ;
194
+ }
195
+ } ) ;
196
+ }
197
+
198
+ private withEntryOverride ( entry : IStatusbarEntry , id : string ) : IStatusbarEntry {
199
+ const override = this . entryOverrides . get ( id ) ;
200
+ if ( override ) {
201
+ entry = { ...entry , ...override } ;
202
+ }
203
+
204
+ return entry ;
205
+ }
206
+
176
207
addEntry ( entry : IStatusbarEntry , id : string , alignment : StatusbarAlignment , priorityOrLocation : number | IStatusbarEntryLocation | IStatusbarEntryPriority = 0 ) : IStatusbarEntryAccessor {
177
208
let priority : IStatusbarEntryPriority ;
178
209
if ( isStatusbarEntryPriority ( priorityOrLocation ) ) {
@@ -220,10 +251,11 @@ class StatusbarPart extends Part implements IStatusbarEntryContainer {
220
251
}
221
252
222
253
private doAddEntry ( entry : IStatusbarEntry , id : string , alignment : StatusbarAlignment , priority : IStatusbarEntryPriority ) : IStatusbarEntryAccessor {
254
+ const disposables = new DisposableStore ( ) ;
223
255
224
256
// View model item
225
257
const itemContainer = this . doCreateStatusItem ( id , alignment ) ;
226
- const item = this . instantiationService . createInstance ( StatusbarEntryItem , itemContainer , entry , this . hoverDelegate ) ;
258
+ const item = disposables . add ( this . instantiationService . createInstance ( StatusbarEntryItem , itemContainer , this . withEntryOverride ( entry , id ) , this . hoverDelegate ) ) ;
227
259
228
260
// View model entry
229
261
const viewModelEntry : IStatusbarViewModelEntry = new class implements IStatusbarViewModelEntry {
@@ -245,20 +277,32 @@ class StatusbarPart extends Part implements IStatusbarEntryContainer {
245
277
this . appendStatusbarEntry ( viewModelEntry ) ;
246
278
}
247
279
248
- return {
280
+ let lastEntry = entry ;
281
+ const accessor : IStatusbarEntryAccessor = {
249
282
update : entry => {
250
- item . update ( entry ) ;
283
+ lastEntry = entry ;
284
+ item . update ( this . withEntryOverride ( entry , id ) ) ;
251
285
} ,
252
286
dispose : ( ) => {
253
287
const { needsFullRefresh } = this . doAddOrRemoveModelEntry ( viewModelEntry , false ) ;
254
288
if ( needsFullRefresh ) {
255
289
this . appendStatusbarEntries ( ) ;
256
290
} else {
257
291
itemContainer . remove ( ) ;
292
+ this . updateCompactEntries ( ) ;
258
293
}
259
- dispose ( item ) ;
294
+ disposables . dispose ( ) ;
260
295
}
261
296
} ;
297
+
298
+ // React to overrides
299
+ disposables . add ( this . onDidOverrideEntry . event ( overrideEntryId => {
300
+ if ( overrideEntryId === id ) {
301
+ accessor . update ( lastEntry ) ;
302
+ }
303
+ } ) ) ;
304
+
305
+ return accessor ;
262
306
}
263
307
264
308
private doCreateStatusItem ( id : string , alignment : StatusbarAlignment , ...extraClasses : string [ ] ) : HTMLElement {
@@ -790,6 +834,16 @@ export class StatusbarService extends MultiWindowParts<StatusbarPart> implements
790
834
}
791
835
}
792
836
837
+ overrideEntry ( id : string , override : IStatusbarEntryOverride ) : IDisposable {
838
+ const disposables = new DisposableStore ( ) ;
839
+
840
+ for ( const part of this . parts ) {
841
+ disposables . add ( part . overrideEntry ( id , override ) ) ;
842
+ }
843
+
844
+ return disposables ;
845
+ }
846
+
793
847
focus ( preserveEntryFocus ?: boolean ) : void {
794
848
this . activePart . focus ( preserveEntryFocus ) ;
795
849
}
@@ -856,6 +910,10 @@ export class ScopedStatusbarService extends Disposable implements IStatusbarServ
856
910
this . statusbarEntryContainer . updateEntryVisibility ( id , visible ) ;
857
911
}
858
912
913
+ overrideEntry ( id : string , override : IStatusbarEntryOverride ) : IDisposable {
914
+ return this . statusbarEntryContainer . overrideEntry ( id , override ) ;
915
+ }
916
+
859
917
focus ( preserveEntryFocus ?: boolean ) : void {
860
918
this . statusbarEntryContainer . focus ( preserveEntryFocus ) ;
861
919
}
0 commit comments