diff --git a/src/components/Menu/MenuBar/MenuBar.vue b/src/components/Menu/MenuBar/MenuBar.vue index cd1bf1d60e..2b21b507e2 100644 --- a/src/components/Menu/MenuBar/MenuBar.vue +++ b/src/components/Menu/MenuBar/MenuBar.vue @@ -32,9 +32,10 @@ import { MenuItemData, MenuItemRoot } from "../type"; import MenuButton from "../MenuButton.vue"; import TitleBarButtons from "./TitleBarButtons.vue"; import TitleBarEditorSwitcher from "./TitleBarEditorSwitcher.vue"; +import { EditorType } from "@/type/preload"; import { useStore } from "@/store"; import { base64ImageToUri } from "@/helpers/imageHelper"; -import { HotkeyAction, useHotkeyManager } from "@/plugins/hotkeyPlugin"; +import { useHotkeyManager } from "@/plugins/hotkeyPlugin"; const props = defineProps<{ /** 「ファイル」メニューのサブメニュー */ @@ -42,7 +43,7 @@ const props = defineProps<{ /** 「編集」メニューのサブメニュー */ editSubMenuData: MenuItemData[]; /** エディタの種類 */ - editor: "talk" | "song"; + editor: EditorType; }>(); const store = useStore(); @@ -491,34 +492,23 @@ watch(uiLocked, () => { } }); -/** - * 全エディタに対してホットキーを登録する - * FIXME: hotkeyPlugin側で全エディタに対して登録できるようにする - */ -function registerHotkeyForAllEditors(action: Omit) { - registerHotkeyWithCleanup({ - editor: "talk", - ...action, - }); - registerHotkeyWithCleanup({ - editor: "song", - ...action, - }); -} - -registerHotkeyForAllEditors({ +registerHotkeyWithCleanup({ + editor: "talk&song", callback: createNewProject, name: "新規プロジェクト", }); -registerHotkeyForAllEditors({ +registerHotkeyWithCleanup({ + editor: "talk&song", callback: saveProject, name: "プロジェクトを上書き保存", }); -registerHotkeyForAllEditors({ +registerHotkeyWithCleanup({ + editor: "talk&song", callback: saveProjectAs, name: "プロジェクトを名前を付けて保存", }); -registerHotkeyForAllEditors({ +registerHotkeyWithCleanup({ + editor: "talk&song", callback: importProject, name: "プロジェクトを読み込む", }); diff --git a/src/plugins/hotkeyPlugin.ts b/src/plugins/hotkeyPlugin.ts index 2ec221e88f..e6363d57f8 100644 --- a/src/plugins/hotkeyPlugin.ts +++ b/src/plugins/hotkeyPlugin.ts @@ -12,6 +12,7 @@ import { HotkeyActionNameType, HotkeyCombination, HotkeySettingType, + EditorType, } from "@/type/preload"; import { createLogger } from "@/domain/frontend/log"; @@ -32,7 +33,8 @@ export const useHotkeyManager = () => { return { hotkeyManager, registerHotkeyWithCleanup }; }; -type Editor = "talk" | "song"; +// FIXME: EditorType型内の要素数が増えてきたら型定義をより一般な形に変更 +type Editor = "talk" | "song" | "talk&song"; type BindingKey = string & { __brand: "BindingKey" }; // BindingKey専用のブランド型 @@ -76,7 +78,7 @@ export class HotkeyManager { /** 登録されたHotkeyAction */ private actions: HotkeyAction[] = []; /** スコープ */ - private scope: Editor = "talk"; + private scope: EditorType = "talk"; /** ユーザーのショートカットキー設定 */ private settings: HotkeySettingType[] | undefined; // ユーザーのショートカットキー設定 /** 登録されたショートカットキーの組み合わせ */ @@ -217,7 +219,7 @@ export class HotkeyManager { /** * エディタが変更されたときに呼び出される。 */ - onEditorChange(editor: "talk" | "song"): void { + onEditorChange(editor: EditorType): void { // this.hotkeys.setScope(editor); this.scope = editor; this.log("Editor changed to", editor); @@ -249,7 +251,7 @@ export class HotkeyManager { combinationToBindingKey(this.getSetting(item).combination) == combination, ) - .find((item) => item.editor == this.scope); + .find((item) => item.editor.split("&").includes(this.scope)); if (action == null) { return; }