fix: expandability, context value in tree

This commit is contained in:
əlemi 2024-09-07 00:41:25 +02:00
parent 4d2a7407e2
commit 045c0bddc8
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -22,19 +22,20 @@ export class CodempTreeProvider implements vscode.TreeDataProvider<CodempTreeIte
case Type.Workspace: case Type.Workspace:
if (workspace === null) { return [] }; if (workspace === null) { return [] };
if (element.label == workspace.id()) { if (element.label == workspace.id()) {
return [ // return [
new CodempTreeItem("Buffers", Type.BufferContainer), // new CodempTreeItem("Buffers", Type.BufferContainer, true),
new CodempTreeItem("Users", Type.UserContainer) // new CodempTreeItem("Users", Type.UserContainer, true)
]; // ];
return workspace.filetree().map((x) => new CodempTreeItem(x, Type.Buffer, false));
} else { } else {
return []; return [];
} }
case Type.BufferContainer: case Type.BufferContainer:
if (workspace === null) { return [] }; if (workspace === null) { return [] };
return workspace.filetree().map((x) => new CodempTreeItem(x, Type.Buffer)); return workspace.filetree().map((x) => new CodempTreeItem(x, Type.Buffer, false));
case Type.UserContainer: case Type.UserContainer:
if (workspace === null) { return [] }; if (workspace === null) { return [] };
return [new CodempTreeItem("TODO", Type.User)]; // TODO keep track of users return [new CodempTreeItem("TODO", Type.User, false)]; // TODO keep track of users
case Type.Buffer: case Type.Buffer:
return []; return [];
case Type.User: case Type.User:
@ -42,7 +43,7 @@ export class CodempTreeProvider implements vscode.TreeDataProvider<CodempTreeIte
} }
} else { } else {
if(client === null) return []; if(client === null) return [];
return workspace_list.map((x) => new CodempTreeItem(x, Type.Workspace)); return workspace_list.map((x) => new CodempTreeItem(x, Type.Workspace, true));
} }
} }
@ -50,16 +51,19 @@ export class CodempTreeProvider implements vscode.TreeDataProvider<CodempTreeIte
class CodempTreeItem extends vscode.TreeItem { class CodempTreeItem extends vscode.TreeItem {
type: Type; type: Type;
constructor(label: string | vscode.TreeItemLabel, type: Type){ constructor(label: string | vscode.TreeItemLabel, type: Type, expandable: boolean){
super(label, vscode.TreeItemCollapsibleState.Expanded); let state = expandable ? vscode.TreeItemCollapsibleState.Expanded : vscode.TreeItemCollapsibleState.None;
console.log(type.toString());
super(label, state);
this.type = type; this.type = type;
this.contextValue = type;
} }
} }
enum Type { enum Type {
Workspace, Workspace = "workspace",
BufferContainer, BufferContainer = "container_buffer",
UserContainer, UserContainer = "container_user",
Buffer, Buffer = "buffer",
User, User = "user",
} }