import * as vscode from 'vscode'; export class Node { constructor(public label: string, public darkIcon: vscode.Uri | undefined = undefined, public lightIcon: vscode.Uri | undefined = undefined, public children: Node[] | undefined = undefined, public contextValue: string | undefined = undefined, public value: any | undefined = undefined) {} public serialize() : any { return { label: this.label, iconPath: (this.lightIcon&&this.darkIcon) ? { light: this.lightIcon?.fsPath, dark: this.darkIcon?.fsPath } : undefined, collapsibleState: this.children? vscode.TreeItemCollapsibleState.Collapsed : vscode.TreeItemCollapsibleState.None, contextValue: this.contextValue } } } export class Panel implements vscode.TreeDataProvider { private placeholder : Node[] = []; private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); public readonly onDidChangeTreeData : vscode.Event | undefined; public set placeholderMessage(value: string) { this.placeholder = [new Node(value)]; } constructor(public readonly name: string, public rootItems: Node[], placeholderMessage : string){ this.placeholderMessage = placeholderMessage; this.onDidChangeTreeData = this._onDidChangeTreeData.event; vscode.window.createTreeView(name, { treeDataProvider: this }); this.UpdatePanel(); } public UpdatePanel() : void { this._onDidChangeTreeData.fire(); } getTreeItem(node: Node ): vscode.TreeItem | Thenable { return node.serialize(); } getChildren(node?: Node): Node[] { if(!node) if(this.rootItems.length>0) return this.rootItems; else return this.placeholder; else return node.children || []; } }