Skip to content

Commit ff4b55d

Browse files
committed
views: link up empty view registry to panes
1 parent 7c30a1b commit ff4b55d

3 files changed

Lines changed: 56 additions & 6 deletions

File tree

‎src/vs/workbench/browser/parts/views/media/views.css‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
height: 100%;
7777
}
7878

79-
.monaco-workbench .pane > .pane-body > .empty-view,
79+
.monaco-workbench .pane > .pane-body:not(.empty) > .empty-view,
8080
.monaco-workbench .pane > .pane-body.empty > :not(.empty-view) {
8181
display: none;
8282
}

‎src/vs/workbench/browser/parts/views/viewPaneContainer.ts‎

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Event, Emitter } from 'vs/base/common/event';
99
import { ColorIdentifier } from 'vs/platform/theme/common/colorRegistry';
1010
import { attachStyler, IColorMapping } from 'vs/platform/theme/common/styler';
1111
import { 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';
1313
import { IDisposable, combinedDisposable, dispose, toDisposable, Disposable, MutableDisposable } from 'vs/base/common/lifecycle';
1414
import { firstIndex } from 'vs/base/common/arrays';
1515
import { IAction, IActionRunner, ActionRunner } from 'vs/base/common/actions';
@@ -25,7 +25,7 @@ import { PaneView, IPaneViewOptions, IPaneOptions, Pane, DefaultPaneDndControlle
2525
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2626
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
2727
import { 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';
2929
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
3030
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
3131
import { 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+
5759
export 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
}

‎src/vs/workbench/common/views.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ export interface IViewsRegistry {
233233

234234
getViewContainer(id: string): ViewContainer | null;
235235

236+
readonly onDidChangeEmptyViewContent: Event<string>;
236237
registerEmptyViewContent(id: string, viewContent: IViewContentDescriptor): IDisposable;
238+
getEmptyViewContent(id: string): IViewContentDescriptor[];
237239
}
238240

239241
class ViewsRegistry extends Disposable implements IViewsRegistry {
@@ -247,6 +249,9 @@ class ViewsRegistry extends Disposable implements IViewsRegistry {
247249
private readonly _onDidChangeContainer: Emitter<{ views: IViewDescriptor[], from: ViewContainer, to: ViewContainer }> = this._register(new Emitter<{ views: IViewDescriptor[], from: ViewContainer, to: ViewContainer }>());
248250
readonly onDidChangeContainer: Event<{ views: IViewDescriptor[], from: ViewContainer, to: ViewContainer }> = this._onDidChangeContainer.event;
249251

252+
private readonly _onDidChangeEmptyViewContent: Emitter<string> = this._register(new Emitter<string>());
253+
readonly onDidChangeEmptyViewContent: Event<string> = this._onDidChangeEmptyViewContent.event;
254+
250255
private _viewContainers: ViewContainer[] = [];
251256
private _views: Map<ViewContainer, IViewDescriptor[]> = new Map<ViewContainer, IViewDescriptor[]>();
252257
private _emptyViewContents = new SetMap<string, IViewContentDescriptor>();
@@ -301,7 +306,18 @@ class ViewsRegistry extends Disposable implements IViewsRegistry {
301306

302307
registerEmptyViewContent(id: string, viewContent: IViewContentDescriptor): IDisposable {
303308
this._emptyViewContents.add(id, viewContent);
304-
return toDisposable(() => this._emptyViewContents.delete(id, viewContent));
309+
this._onDidChangeEmptyViewContent.fire(id);
310+
311+
return toDisposable(() => {
312+
this._emptyViewContents.delete(id, viewContent);
313+
this._onDidChangeEmptyViewContent.fire(id);
314+
});
315+
}
316+
317+
getEmptyViewContent(id: string): IViewContentDescriptor[] {
318+
const result: IViewContentDescriptor[] = [];
319+
this._emptyViewContents.forEach(id, descriptor => result.push(descriptor));
320+
return result;
305321
}
306322

307323
private addViews(viewDescriptors: IViewDescriptor[], viewContainer: ViewContainer): void {

0 commit comments

Comments
 (0)