@@ -9,7 +9,7 @@ import { Event, Emitter } from 'vs/base/common/event';
99import { ColorIdentifier } from 'vs/platform/theme/common/colorRegistry' ;
1010import { attachStyler , IColorMapping } from 'vs/platform/theme/common/styler' ;
1111import { SIDE_BAR_DRAG_AND_DROP_BACKGROUND , SIDE_BAR_SECTION_HEADER_FOREGROUND , SIDE_BAR_SECTION_HEADER_BACKGROUND , SIDE_BAR_SECTION_HEADER_BORDER } from 'vs/workbench/common/theme' ;
12- import { append , $ , trackFocus , toggleClass , EventType , isAncestor , Dimension , addDisposableListener } from 'vs/base/browser/dom' ;
12+ import { append , $ , trackFocus , toggleClass , EventType , isAncestor , Dimension , addDisposableListener , addClass , removeClass } from 'vs/base/browser/dom' ;
1313import { IDisposable , combinedDisposable , dispose , toDisposable , Disposable , MutableDisposable } from 'vs/base/common/lifecycle' ;
1414import { firstIndex } from 'vs/base/common/arrays' ;
1515import { IAction , IActionRunner , ActionRunner } from 'vs/base/common/actions' ;
@@ -25,7 +25,7 @@ import { PaneView, IPaneViewOptions, IPaneOptions, Pane, DefaultPaneDndControlle
2525import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
2626import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService' ;
2727import { StandardMouseEvent } from 'vs/base/browser/mouseEvent' ;
28- import { Extensions as ViewContainerExtensions , IView , FocusedViewContext , IViewContainersRegistry , IViewDescriptor , ViewContainer } from 'vs/workbench/common/views' ;
28+ import { Extensions as ViewContainerExtensions , IView , FocusedViewContext , IViewContainersRegistry , IViewDescriptor , ViewContainer , IViewsRegistry } from 'vs/workbench/common/views' ;
2929import { IStorageService , StorageScope } from 'vs/platform/storage/common/storage' ;
3030import { IContextKey , IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
3131import { assertIsDefined } from 'vs/base/common/types' ;
@@ -54,6 +54,8 @@ export interface IViewPaneOptions extends IPaneOptions {
5454 titleMenuId ?: MenuId ;
5555}
5656
57+ const viewsRegistry = Registry . as < IViewsRegistry > ( ViewContainerExtensions . ViewsRegistry ) ;
58+
5759export abstract class ViewPane extends Pane implements IView {
5860
5961 private static readonly AlwaysShowActionsConfig = 'workbench.view.alwaysShowHeaderActions' ;
@@ -87,7 +89,9 @@ export abstract class ViewPane extends Pane implements IView {
8789 private headerContainer ?: HTMLElement ;
8890 private titleContainer ?: HTMLElement ;
8991 protected twistiesContainer ?: HTMLElement ;
90- private emptyViewContainer ?: HTMLElement ;
92+
93+ private bodyContainer ! : HTMLElement ;
94+ private emptyViewContainer ! : HTMLElement ;
9195
9296 constructor (
9397 options : IViewPaneOptions ,
@@ -195,8 +199,19 @@ export abstract class ViewPane extends Pane implements IView {
195199 }
196200
197201 protected renderBody ( container : HTMLElement ) : void {
202+ this . bodyContainer = container ;
198203 this . emptyViewContainer = append ( container , $ ( '.empty-view' , { tabIndex : 0 } ) ) ;
199- this . emptyViewContainer . textContent = 'this view is empty' ;
204+
205+ // we should update our empty state whenever
206+ const onEmptyViewContentChange = Event . any (
207+ // the registry changes
208+ Event . map ( Event . filter ( viewsRegistry . onDidChangeEmptyViewContent , id => id === this . id ) , ( ) => this . isEmpty ( ) ) ,
209+ // or the view's empty state changes
210+ Event . latch ( Event . map ( this . onDidChangeEmptyState , ( ) => this . isEmpty ( ) ) )
211+ ) ;
212+
213+ this . _register ( onEmptyViewContentChange ( this . updateEmptyState , this ) ) ;
214+ this . updateEmptyState ( this . isEmpty ( ) ) ;
200215 }
201216
202217 focus ( ) : void {
@@ -253,6 +268,25 @@ export abstract class ViewPane extends Pane implements IView {
253268 // Subclasses to implement for saving state
254269 }
255270
271+ private updateEmptyState ( isEmpty : boolean ) : void {
272+ if ( ! isEmpty ) {
273+ removeClass ( this . bodyContainer , 'empty' ) ;
274+ this . emptyViewContainer . innerHTML = '' ;
275+ return ;
276+ }
277+
278+ const contents = viewsRegistry . getEmptyViewContent ( this . id ) ;
279+
280+ if ( contents . length === 0 ) {
281+ removeClass ( this . bodyContainer , 'empty' ) ;
282+ this . emptyViewContainer . innerHTML = '' ;
283+ return ;
284+ }
285+
286+ addClass ( this . bodyContainer , 'empty' ) ;
287+ this . emptyViewContainer . textContent = contents . map ( c => c . content ) . join ( '' ) ;
288+ }
289+
256290 isEmpty ( ) : boolean {
257291 return false ;
258292 }
0 commit comments