Skip to content

Commit

Permalink
节点点击响应
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Jun 4, 2024
1 parent d030c68 commit 9302aa1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"name": "Y3开发助手"
},
{
"id": "y3-helper.client",
"name": "客户端"
"id": "y3-helper.custom",
"name": "自定义"
}
]
},
Expand Down
4 changes: 2 additions & 2 deletions src/console/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class Client extends vscode.Disposable {
if (data.trim() === '') {
return;
}
await this.request('command', { data: data });
this.notify('command', { data: data });
});

this.button = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left);
Expand Down Expand Up @@ -165,6 +165,6 @@ vscode.commands.registerCommand('y3-helper.testTerminal', async () => {

vscode.commands.registerCommand('y3-helper.reloadLua', async () => {
for (let client of clients) {
client.request('command', { data: '.rd' });
client.notify('command', { data: '.rd' });
}
});
34 changes: 30 additions & 4 deletions src/console/treeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ class TreeDataProvider implements vscode.TreeDataProvider<number> {
item.collapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
}
}
if (data.canClick) {
item.command = {
command: 'y3-helper.custom.treeViewClick',
title: '',
arguments: [this.manager.id, item.uid],
};
}
}

createItem(id: number, data: getTreeNodeResponse) {
Expand Down Expand Up @@ -110,7 +117,7 @@ export class TreeView {
readonly name: string,
readonly root: number,
) {
vscode.commands.executeCommand('y3-helper.client.focus');
vscode.commands.executeCommand('y3-helper.custom.focus');
}
}

Expand All @@ -120,17 +127,24 @@ interface getTreeNodeResponse {
tip?: string;
icon?: string;
hasChilds?: boolean;
canClick?: boolean;
}

export class TreeViewManager extends vscode.Disposable {
static nextID = 0;
static allManagers = new Map<number, TreeViewManager>();

readonly id = TreeViewManager.nextID++;
constructor(private client: Client) {
super(() => {
this.view.dispose();
TreeViewManager.allManagers.delete(this.id);
});

TreeViewManager.allManagers.set(this.id, this);
this.treeDataProvider = new TreeDataProvider(this);

this.view = vscode.window.createTreeView('y3-helper.client', {
this.view = vscode.window.createTreeView('y3-helper.custom', {
treeDataProvider: this.treeDataProvider,
showCollapseAll: true,
});
Expand All @@ -149,7 +163,7 @@ export class TreeViewManager extends vscode.Disposable {
}

private view: vscode.TreeView<number>;
private treeDataProvider: TreeDataProvider;
readonly treeDataProvider: TreeDataProvider;

readonly treeViews = new Array<TreeView>();

Expand Down Expand Up @@ -185,6 +199,18 @@ export class TreeViewManager extends vscode.Disposable {
}

notifyChangeTreeNodeVisible(ids: number[], visible: boolean) {
this.client.request('changeTreeNodeVisible', { ids, visible });
this.client.notify('changeTreeNodeVisible', { ids, visible });
}

notifyClickTreeNode(id: number) {
this.client.notify('clickTreeNode', { id });
}
}

vscode.commands.registerCommand('y3-helper.custom.treeViewClick', async (managerID, itemUID) => {
let manager = TreeViewManager.allManagers.get(managerID);
if (!manager) {
return;
}
manager.notifyClickTreeNode(itemUID);
});

0 comments on commit 9302aa1

Please sign in to comment.