Skip to content

Commit a3f0520

Browse files
committed
feat: 增加一键重置所有快捷键功能
1 parent ad39233 commit a3f0520

File tree

4 files changed

+49
-210
lines changed

4 files changed

+49
-210
lines changed

app/src/core/service/GlobalMenu.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,32 @@ export function GlobalMenu() {
604604
<Palette />
605605
{t("settings.appearance")}
606606
</Item>
607+
<Item
608+
className="*:text-destructive! text-destructive!"
609+
onClick={async () => {
610+
if (
611+
await Dialog.confirm(
612+
"确认重置全部快捷键",
613+
"此操作会将所有快捷键恢复为默认值,无法撤销。\n\n是否继续?",
614+
{ destructive: true },
615+
)
616+
) {
617+
try {
618+
const activeProject = store.get(activeProjectAtom);
619+
if (activeProject) {
620+
await activeProject.keyBinds.resetAllKeyBinds();
621+
toast.success("所有快捷键已重置为默认值");
622+
}
623+
} catch (error) {
624+
toast.error("重置快捷键失败");
625+
console.error("重置快捷键失败:", error);
626+
}
627+
}
628+
}}
629+
>
630+
<Radiation />
631+
重置全部快捷键
632+
</Item>
607633
</Content>
608634
</Menu>
609635

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ export class KeyBinds {
111111
userSetKey = defaultKey;
112112
}
113113
const obj = new _Bind(this.project, id, userSetKey, onPress);
114+
// 将绑定对象添加到集合中,以便后续清理
115+
this.binds.add(obj);
114116
// 监听快捷键变化
115117
this.watch(id, (value) => {
116118
obj.key = value;
@@ -124,6 +126,21 @@ export class KeyBinds {
124126
this.registeredIdSet.clear();
125127
this.callbacks = {};
126128
}
129+
130+
/**
131+
* 重置所有快捷键为默认值
132+
*/
133+
async resetAllKeyBinds() {
134+
if (!this.store) {
135+
throw new Error("Store not initialized.");
136+
}
137+
// 清除已注册ID集合和资源
138+
this.dispose();
139+
// 清空存储
140+
await this.store.clear();
141+
// 重新注册所有快捷键
142+
await this.project.keyBindsRegistrar.registerKeyBinds();
143+
}
127144
}
128145

129146
/**

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

Lines changed: 0 additions & 209 deletions
This file was deleted.

app/src/sub/SettingsWindow/keybinds.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,13 @@ export default function KeyBindsPage() {
212212
<Field color="warning" title="需要先打开一个工程文件才能编辑快捷键设置" />
213213
);
214214
}
215+
type ShortcutKeysGroup = {
216+
title: string;
217+
icon: React.ReactNode;
218+
keys: string[];
219+
};
215220

216-
const shortcutKeysGroups = [
221+
const shortcutKeysGroups: ShortcutKeysGroup[] = [
217222
{
218223
title: "basic",
219224
icon: <Keyboard />,

0 commit comments

Comments
 (0)