Skip to content

Commit 3ce0c43

Browse files
committed
💄 给快捷键界面添加分类
1 parent 8c97558 commit 3ce0c43

File tree

4 files changed

+197
-27
lines changed

4 files changed

+197
-27
lines changed

app/src/core/service/controlService/shortcutKeysEngine/KeyBinds.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export namespace KeyBinds {
7272
*/
7373
export async function entries() {
7474
if (!store) {
75-
throw new Error("Store not initialized.");
75+
throw new Error("Keybind Store not initialized.");
7676
}
7777
return await store.entries<{ key: string; modifiers: KeyModifiers }>();
7878
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/**
2+
* 专门给各种快捷键分组
3+
*/
4+
5+
type ShortcutKeysGroup = {
6+
title: string;
7+
keys: string[];
8+
};
9+
10+
export const shortcutKeysGroups: ShortcutKeysGroup[] = [
11+
{
12+
title: "basic",
13+
keys: [
14+
"undo",
15+
"redo",
16+
"selectAll",
17+
"searchText",
18+
"copy",
19+
"paste",
20+
"pasteWithOriginLocation",
21+
"deleteSelectedStageObjects",
22+
],
23+
},
24+
{
25+
title: "camera",
26+
keys: [
27+
"resetView",
28+
"resetCameraScale",
29+
"masterBrakeCheckout",
30+
"masterBrakeControl",
31+
"CameraScaleZoomIn",
32+
"CameraScaleZoomOut",
33+
],
34+
},
35+
{
36+
title: "app",
37+
keys: ["switchDebugShow", "exitSoftware", "checkoutProtectPrivacy", "reload"],
38+
},
39+
{
40+
title: "ui",
41+
keys: [
42+
"checkoutClassroomMode",
43+
"checkoutWindowOpacityMode",
44+
"windowOpacityAlphaIncrease",
45+
"windowOpacityAlphaDecrease",
46+
"openColorPanel",
47+
"clickAppMenuSettingsButton",
48+
"clickTagPanelButton",
49+
"clickAppMenuRecentFileButton",
50+
"clickStartFilePanelButton",
51+
],
52+
},
53+
{
54+
title: "draw",
55+
keys: ["selectEntityByPenStroke", "penStrokeWidthIncrease", "penStrokeWidthDecrease"],
56+
},
57+
{
58+
title: "moveEntity",
59+
keys: [
60+
"moveUpSelectedEntities",
61+
"moveDownSelectedEntities",
62+
"moveLeftSelectedEntities",
63+
"moveRightSelectedEntities",
64+
"jumpMoveUpSelectedEntities",
65+
"jumpMoveDownSelectedEntities",
66+
"jumpMoveLeftSelectedEntities",
67+
"jumpMoveRightSelectedEntities",
68+
],
69+
},
70+
{
71+
title: "generateTextNodeInTree",
72+
keys: ["generateNodeTreeWithDeepMode", "generateNodeTreeWithBroadMode", "generateNodeGraph"],
73+
},
74+
{
75+
title: "generateTextNodeRoundedSelectedNode",
76+
keys: [
77+
"createTextNodeFromSelectedTop",
78+
"createTextNodeFromSelectedDown",
79+
"createTextNodeFromSelectedLeft",
80+
"createTextNodeFromSelectedRight",
81+
],
82+
},
83+
{
84+
title: "createTextNode",
85+
keys: ["createTextNodeFromCameraLocation", "createTextNodeFromMouseLocation"],
86+
},
87+
{
88+
title: "section",
89+
keys: ["folderSection", "packEntityToSection", "unpackEntityFromSection", "textNodeToSection"],
90+
},
91+
{
92+
title: "leftMouseModeCheckout",
93+
keys: [
94+
"checkoutLeftMouseToSelectAndMove",
95+
"checkoutLeftMouseToDrawing",
96+
"checkoutLeftMouseToConnectAndCutting",
97+
"checkoutLeftMouseToConnectAndCuttingOnlyPressed",
98+
],
99+
},
100+
{
101+
title: "edge",
102+
keys: ["reverseEdges", "reverseSelectedNodeEdge"],
103+
},
104+
];

app/src/locales/zh_CN.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,12 +831,12 @@ keyBinds:
831831
title: 全选
832832
description: 按下后,所有节点和连线都会被选中
833833
createTextNodeFromCameraLocation:
834-
title: 创建文本节点
834+
title: 在视野中心位置创建文本节点
835835
description: |
836836
按下后,在当前视野中心的位置创建一个文本节点
837837
等同于鼠标双击创建节点的功能
838838
createTextNodeFromMouseLocation:
839-
title: 创建文本节点
839+
title: 在鼠标位置创建文本节点
840840
description: |
841841
按下后,在鼠标悬浮位置创建一个文本节点
842842
等同于鼠标单击创建节点的功能

app/src/pages/settings/keybinds.tsx

Lines changed: 90 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import React from "react";
33
import { useTranslation } from "react-i18next";
44
import KeyBind from "../../components/KeyBind";
55
import { KeyBinds } from "../../core/service/controlService/shortcutKeysEngine/KeyBinds";
6-
import { Field } from "./_field";
6+
import { Field, FieldGroup } from "./_field";
7+
import { shortcutKeysGroups } from "../../core/service/controlService/shortcutKeysEngine/shortcutKeysGroup";
78

89
export default function KeyBindsPage() {
910
const [keyBinds, setKeyBinds] = React.useState<[id: string, { key: string; modifiers: KeyBinds.KeyModifiers }][]>([]);
@@ -14,29 +15,94 @@ export default function KeyBindsPage() {
1415
});
1516
}, []);
1617

18+
const getKeybindObjectById = (id: string) => {
19+
return keyBinds.find((item) => item[0] === id)?.[1];
20+
};
21+
22+
/**
23+
* 获取未加入分组的快捷键
24+
* @returns
25+
*/
26+
const getUnGroupedKeys = () => {
27+
return keyBinds.filter((item) => !shortcutKeysGroups.some((group) => group.keys.includes(item[0])));
28+
};
29+
1730
const { t } = useTranslation("keyBinds");
1831

19-
return keyBinds
20-
.map(([id, bind]) => (
21-
<Field
22-
key={id}
23-
icon={<Keyboard />}
24-
title={t(`${id}.title`, { defaultValue: id })}
25-
description={t(`${id}.description`, { defaultValue: "" })}
26-
>
27-
<KeyBind
28-
value={bind}
29-
onChange={(value) => {
30-
KeyBinds.set(id, value.key, value.modifiers);
31-
setKeyBinds((prev) => prev.map((item) => (item[0] === id ? [item[0], value] : item)));
32-
}}
33-
/>
34-
</Field>
35-
))
36-
.sort((a, b) => {
37-
if (a.key === null && b.key === null) return 0; // 两者均为 null,相等
38-
if (a.key === null) return 1; // a.key 为 null,把它排到后面
39-
if (b.key === null) return -1; // b.key 为 null,把它排到后面
40-
return a.key.localeCompare(b.key); // 正常比较
41-
});
32+
return (
33+
<>
34+
{shortcutKeysGroups.map((group, i) => {
35+
console.log(group);
36+
return (
37+
<FieldGroup title={t(group.title)} key={i}>
38+
{group.keys.map((id) => (
39+
<Field
40+
key={id}
41+
icon={<Keyboard />}
42+
title={t(`${id}.title`, { defaultValue: id })}
43+
description={t(`${id}.description`, { defaultValue: "" })}
44+
>
45+
<KeyBind
46+
value={getKeybindObjectById(id)}
47+
onChange={(value) => {
48+
KeyBinds.set(id, value.key, value.modifiers);
49+
setKeyBinds((prev) => prev.map((item) => (item[0] === id ? [item[0], value] : item)));
50+
}}
51+
/>
52+
</Field>
53+
))}
54+
</FieldGroup>
55+
);
56+
})}
57+
<FieldGroup title={t("otherKeys")} description={"未分组的快捷键"}>
58+
{getUnGroupedKeys()
59+
.map(([id, bind]) => (
60+
<Field
61+
key={id}
62+
icon={<Keyboard />}
63+
title={t(`${id}.title`, { defaultValue: id })}
64+
description={t(`${id}.description`, { defaultValue: "" })}
65+
>
66+
<KeyBind
67+
value={bind}
68+
onChange={(value) => {
69+
KeyBinds.set(id, value.key, value.modifiers);
70+
setKeyBinds((prev) => prev.map((item) => (item[0] === id ? [item[0], value] : item)));
71+
}}
72+
/>
73+
</Field>
74+
))
75+
.sort((a, b) => {
76+
if (a.key === null && b.key === null) return 0; // 两者均为 null,相等
77+
if (a.key === null) return 1; // a.key 为 null,把它排到后面
78+
if (b.key === null) return -1; // b.key 为 null,把它排到后面
79+
return a.key.localeCompare(b.key); // 正常比较
80+
})}
81+
</FieldGroup>
82+
{/* <h1>{t("title")}</h1>
83+
{keyBinds
84+
.map(([id, bind]) => (
85+
<Field
86+
key={id}
87+
icon={<Keyboard />}
88+
title={t(`${id}.title`, { defaultValue: id })}
89+
description={t(`${id}.description`, { defaultValue: "" })}
90+
>
91+
<KeyBind
92+
value={bind}
93+
onChange={(value) => {
94+
KeyBinds.set(id, value.key, value.modifiers);
95+
setKeyBinds((prev) => prev.map((item) => (item[0] === id ? [item[0], value] : item)));
96+
}}
97+
/>
98+
</Field>
99+
))
100+
.sort((a, b) => {
101+
if (a.key === null && b.key === null) return 0; // 两者均为 null,相等
102+
if (a.key === null) return 1; // a.key 为 null,把它排到后面
103+
if (b.key === null) return -1; // b.key 为 null,把它排到后面
104+
return a.key.localeCompare(b.key); // 正常比较
105+
})} */}
106+
</>
107+
);
42108
}

0 commit comments

Comments
 (0)