Skip to content

Commit

Permalink
界面的右键菜单
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed May 21, 2024
1 parent 976127e commit 199c768
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@
"command": "y3-helper.copyEventName",
"when": "viewItem == 自定义事件",
"group": "copy"
},
{
"command": "y3-helper.copyUIName",
"when": "viewItem == 画板 || viewItem == 场景UI || viewItem == 元件",
"group": "copy"
},
{
"command": "y3-helper.copyUIPath",
"when": "viewItem == 画板",
"group": "copy"
},
{
"command": "y3-helper.copyUIUID",
"when": "viewItem == 画板 || viewItem == 场景UI || viewItem == 元件",
"group": "copy"
}
]
},
Expand Down Expand Up @@ -273,6 +288,24 @@
"enablement": "viewItem == 自定义事件",
"category": "Y3开发助手"
},
{
"command": "y3-helper.copyUIName",
"title": "复制名称",
"enablement": "viewItem == 画板 || viewItem == 场景UI || viewItem == 元件",
"category": "Y3开发助手"
},
{
"command": "y3-helper.copyUIPath",
"title": "复制路径",
"enablement": "viewItem == 画板",
"category": "Y3开发助手"
},
{
"command": "y3-helper.copyUIUID",
"title": "复制ID",
"enablement": "viewItem == 画板 || viewItem == 场景UI || viewItem == 元件",
"category": "Y3开发助手"
},
{
"command": "y3-helper.networkServer",
"title": "启动网络服务器(用于测试`network`库)",
Expand Down
41 changes: 35 additions & 6 deletions src/mainMenu/pages/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ icons.set(27, new vscode.ThemeIcon('settings-gear')); // Chat_Box
icons.set(38, new vscode.ThemeIcon('sparkle')); // Sequence_Animation

class UINode extends TreeNode {
constructor(ui: Node) {
constructor(ui: Node, type: string) {
super(ui.name, {
iconPath: icons.get(ui.type),
contextValue: type,
update: async (node) => {
node.iconPath = icons.get(ui.type);
node.tooltip = ui.uid;
node.childs = ui.childs.length > 0
? ui.childs.map(ui => new UINode(ui))
? ui.childs.map(ui => new UINode(ui, type))
: undefined;
}
});
Expand Down Expand Up @@ -60,7 +61,7 @@ export class 界面 extends TreeNode {

node.childs = (await define.界面.getUIPackage())
.画板
.map(ui => new UINode(ui));
.map(ui => new UINode(ui, '画板'));
}
}),
new TreeNode('场景UI', {
Expand All @@ -77,7 +78,7 @@ export class 界面 extends TreeNode {

node.childs = (await define.界面.getUIPackage())
.场景UI
.map(ui => new UINode(ui));
.map(ui => new UINode(ui, '场景UI'));
}
}),
new TreeNode('元件', {
Expand All @@ -94,10 +95,38 @@ export class 界面 extends TreeNode {

node.childs = (await define.界面.getUIPackage())
.元件
.map(ui => new UINode(ui));
.map(ui => new UINode(ui, '元件'));
}
}),
],
});
}
};

vscode.commands.registerCommand('y3-helper.copyUIName', (node: TreeNode) => {
if (typeof node.label !== 'string') {
return;
}
vscode.env.clipboard.writeText(node.label);
});

vscode.commands.registerCommand('y3-helper.copyUIPath', (node: TreeNode) => {
let paths: string[] = [];
// 递归父节点将所有的label拼接起来
let curNode = node;
while (curNode.contextValue === '画板') {
paths.unshift(curNode.label as string);
if (curNode.parent === undefined) {
break;
}
curNode = curNode.parent;
}
vscode.env.clipboard.writeText(paths.join('.'));
});

vscode.commands.registerCommand('y3-helper.copyUIUID', (node: TreeNode) => {
if (typeof node.tooltip !== 'string') {
return;
}
vscode.env.clipboard.writeText(node.tooltip);
});

0 comments on commit 199c768

Please sign in to comment.