2024-09-06 18:45:25 +02:00
|
|
|
import * as vscode from 'vscode';
|
|
|
|
import { client, workspace, workspace_list } from './commands';
|
|
|
|
|
|
|
|
export class CodempTreeProvider implements vscode.TreeDataProvider<CodempTreeItem> {
|
|
|
|
|
|
|
|
constructor() {}
|
|
|
|
|
|
|
|
private _emitter: vscode.EventEmitter<CodempTreeItem | undefined | null | void> = new vscode.EventEmitter<CodempTreeItem | undefined | null | void>();
|
|
|
|
readonly onDidChangeTreeData: vscode.Event<CodempTreeItem | undefined | null | void> = this._emitter.event;
|
|
|
|
|
|
|
|
refresh(): void {
|
|
|
|
this._emitter.fire();
|
|
|
|
}
|
|
|
|
|
|
|
|
getTreeItem(element: CodempTreeItem): vscode.TreeItem {
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
async getChildren(element?: CodempTreeItem): Promise<CodempTreeItem[]> {
|
|
|
|
if (element) {
|
|
|
|
switch (element.type) {
|
|
|
|
case Type.Workspace:
|
|
|
|
if (workspace === null) { return [] };
|
|
|
|
if (element.label == workspace.id()) {
|
2024-09-07 00:41:25 +02:00
|
|
|
// return [
|
|
|
|
// new CodempTreeItem("Buffers", Type.BufferContainer, true),
|
|
|
|
// new CodempTreeItem("Users", Type.UserContainer, true)
|
|
|
|
// ];
|
|
|
|
return workspace.filetree().map((x) => new CodempTreeItem(x, Type.Buffer, false));
|
2024-09-06 18:45:25 +02:00
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
case Type.BufferContainer:
|
|
|
|
if (workspace === null) { return [] };
|
2024-09-07 00:41:25 +02:00
|
|
|
return workspace.filetree().map((x) => new CodempTreeItem(x, Type.Buffer, false));
|
2024-09-06 18:45:25 +02:00
|
|
|
case Type.UserContainer:
|
|
|
|
if (workspace === null) { return [] };
|
2024-09-07 00:41:25 +02:00
|
|
|
return [new CodempTreeItem("TODO", Type.User, false)]; // TODO keep track of users
|
2024-09-06 18:45:25 +02:00
|
|
|
case Type.Buffer:
|
|
|
|
return [];
|
|
|
|
case Type.User:
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
} else {
|
2024-09-06 23:15:03 +02:00
|
|
|
if(client === null) return [];
|
2024-09-07 00:41:25 +02:00
|
|
|
return workspace_list.map((x) => new CodempTreeItem(x, Type.Workspace, true));
|
2024-09-06 18:45:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CodempTreeItem extends vscode.TreeItem {
|
|
|
|
type: Type;
|
2024-09-07 00:41:25 +02:00
|
|
|
constructor(label: string | vscode.TreeItemLabel, type: Type, expandable: boolean){
|
|
|
|
let state = expandable ? vscode.TreeItemCollapsibleState.Expanded : vscode.TreeItemCollapsibleState.None;
|
|
|
|
console.log(type.toString());
|
|
|
|
super(label, state);
|
|
|
|
this.type = type;
|
|
|
|
this.contextValue = type;
|
2024-09-06 18:45:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-06 23:15:03 +02:00
|
|
|
enum Type {
|
2024-09-07 00:41:25 +02:00
|
|
|
Workspace = "workspace",
|
|
|
|
BufferContainer = "container_buffer",
|
|
|
|
UserContainer = "container_user",
|
|
|
|
Buffer = "buffer",
|
|
|
|
User = "user",
|
2024-09-06 18:45:25 +02:00
|
|
|
}
|