From 78635348d5ebec26ae3e2a59030b2c8d28fa9795 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Mon, 19 Dec 2022 14:41:45 +0800 Subject: [PATCH] Repo // Add hotkey for calling reverse-lookup window. --- .../Shared/Protocols/PrefMgrProtocol.swift | 1 + .../Sources/Shared/Shared.swift | 1 + Source/Modules/PrefMgr_Core.swift | 3 ++ Source/Modules/SessionCtl_Menu.swift | 6 ++- .../PrefUI/VwrPrefPaneKeyboard.swift | 8 ++++ .../WindowNIBs/Base.lproj/frmPrefWindow.xib | 42 ++++++++++++------- .../WindowNIBs/en.lproj/frmPrefWindow.strings | 1 + .../WindowNIBs/ja.lproj/frmPrefWindow.strings | 1 + .../zh-Hans.lproj/frmPrefWindow.strings | 1 + .../zh-Hant.lproj/frmPrefWindow.strings | 1 + 10 files changed, 48 insertions(+), 17 deletions(-) diff --git a/Packages/vChewing_Shared/Sources/Shared/Protocols/PrefMgrProtocol.swift b/Packages/vChewing_Shared/Sources/Shared/Protocols/PrefMgrProtocol.swift index 2d3be9d3..5299c4b0 100644 --- a/Packages/vChewing_Shared/Sources/Shared/Protocols/PrefMgrProtocol.swift +++ b/Packages/vChewing_Shared/Sources/Shared/Protocols/PrefMgrProtocol.swift @@ -80,4 +80,5 @@ public protocol PrefMgrProtocol { var usingHotKeyHalfWidthASCII: Bool { get set } var usingHotKeyCurrencyNumerals: Bool { get set } var usingHotKeyCassette: Bool { get set } + var usingHotKeyRevLookup: Bool { get set } } diff --git a/Packages/vChewing_Shared/Sources/Shared/Shared.swift b/Packages/vChewing_Shared/Sources/Shared/Shared.swift index 6f49b29a..8bddd0bb 100644 --- a/Packages/vChewing_Shared/Sources/Shared/Shared.swift +++ b/Packages/vChewing_Shared/Sources/Shared/Shared.swift @@ -87,6 +87,7 @@ public enum UserDef: String, CaseIterable { case kUsingHotKeyHalfWidthASCII = "UsingHotKeyHalfWidthASCII" case kUsingHotKeyCurrencyNumerals = "UsingHotKeyCurrencyNumerals" case kUsingHotKeyCassette = "UsingHotKeyCassette" + case kUsingHotKeyRevLookup = "UsingHotKeyRevLookup" public static func resetAll() { UserDef.allCases.forEach { diff --git a/Source/Modules/PrefMgr_Core.swift b/Source/Modules/PrefMgr_Core.swift index 45a4fa19..bc7c36da 100644 --- a/Source/Modules/PrefMgr_Core.swift +++ b/Source/Modules/PrefMgr_Core.swift @@ -327,4 +327,7 @@ public class PrefMgr: PrefMgrProtocol { @AppProperty(key: UserDef.kUsingHotKeyCassette.rawValue, defaultValue: true) public var usingHotKeyCassette: Bool + + @AppProperty(key: UserDef.kUsingHotKeyRevLookup.rawValue, defaultValue: true) + public var usingHotKeyRevLookup: Bool } diff --git a/Source/Modules/SessionCtl_Menu.swift b/Source/Modules/SessionCtl_Menu.swift index 0e7396e0..54c706ce 100644 --- a/Source/Modules/SessionCtl_Menu.swift +++ b/Source/Modules/SessionCtl_Menu.swift @@ -144,10 +144,12 @@ extension SessionCtl { ) } - menu.addItem( + let revLookupMenuItem = menu.addItem( withTitle: "Reverse Lookup (Phonabets)".localized.withEllipsis, - action: #selector(callReverseLookupWindow(_:)) + action: #selector(callReverseLookupWindow(_:)), + keyEquivalent: PrefMgr.shared.usingHotKeyRevLookup ? "/" : "" ) + revLookupMenuItem.keyEquivalentModifierMask = [.command, .control] menu.addItem(NSMenuItem.separator()) // --------------------- diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneKeyboard.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneKeyboard.swift index 7fbb2491..d686799d 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneKeyboard.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneKeyboard.swift @@ -224,6 +224,8 @@ private struct VwrPrefPaneKeyboard_KeyboardShortcuts: View { forKey: UserDef.kUsingHotKeyCurrencyNumerals.rawValue) @State private var selUsingHotKeyCassette = UserDefaults.standard.bool( forKey: UserDef.kUsingHotKeyCassette.rawValue) + @State private var selUsingHotKeyRevLookup = UserDefaults.standard.bool( + forKey: UserDef.kUsingHotKeyRevLookup.rawValue) var body: some View { HStack(alignment: .top, spacing: NSFont.systemFontSize) { @@ -252,6 +254,12 @@ private struct VwrPrefPaneKeyboard_KeyboardShortcuts: View { PrefMgr.shared.usingHotKeyKangXi = selUsingHotKeyKangXi } ) + Toggle( + LocalizedStringKey("Reverse Lookup (Phonabets)"), + isOn: $selUsingHotKeyRevLookup.onChange { + PrefMgr.shared.usingHotKeyRevLookup = selUsingHotKeyRevLookup + } + ) } VStack(alignment: .leading) { Toggle( diff --git a/Source/WindowNIBs/Base.lproj/frmPrefWindow.xib b/Source/WindowNIBs/Base.lproj/frmPrefWindow.xib index bc449a6b..0f083af5 100644 --- a/Source/WindowNIBs/Base.lproj/frmPrefWindow.xib +++ b/Source/WindowNIBs/Base.lproj/frmPrefWindow.xib @@ -1295,14 +1295,14 @@ - + - + - + @@ -1496,11 +1496,11 @@ - - + + - + @@ -1508,7 +1508,7 @@ + @@ -1598,6 +1608,7 @@ + @@ -1609,6 +1620,7 @@ + @@ -1626,7 +1638,7 @@ - + diff --git a/Source/WindowNIBs/en.lproj/frmPrefWindow.strings b/Source/WindowNIBs/en.lproj/frmPrefWindow.strings index a13e3f1c..06b37894 100644 --- a/Source/WindowNIBs/en.lproj/frmPrefWindow.strings +++ b/Source/WindowNIBs/en.lproj/frmPrefWindow.strings @@ -13,6 +13,7 @@ "18.title" = "Radio"; "1AW-xf-c2f.label" = "Keyboard"; "1ll-Jn-OD5.title" = "CIN Cassette Mode"; +"1Pn-EV-mui.title" = "Reverse Lookup (Phonabets)"; "20.title" = "Radio"; "21.title" = "Horizontal"; "22.title" = "Vertical"; diff --git a/Source/WindowNIBs/ja.lproj/frmPrefWindow.strings b/Source/WindowNIBs/ja.lproj/frmPrefWindow.strings index 7d2d2410..c22b46df 100644 --- a/Source/WindowNIBs/ja.lproj/frmPrefWindow.strings +++ b/Source/WindowNIBs/ja.lproj/frmPrefWindow.strings @@ -13,6 +13,7 @@ "18.title" = "Radio"; "1AW-xf-c2f.label" = "キーボード"; "1ll-Jn-OD5.title" = "CIN カセットモード"; +"1Pn-EV-mui.title" = "注音音読逆引参照"; "20.title" = "Radio"; "21.title" = "横型陳列"; "22.title" = "縦型陳列"; diff --git a/Source/WindowNIBs/zh-Hans.lproj/frmPrefWindow.strings b/Source/WindowNIBs/zh-Hans.lproj/frmPrefWindow.strings index 49e5dadc..22615bda 100644 --- a/Source/WindowNIBs/zh-Hans.lproj/frmPrefWindow.strings +++ b/Source/WindowNIBs/zh-Hans.lproj/frmPrefWindow.strings @@ -13,6 +13,7 @@ "18.title" = "Radio"; "1AW-xf-c2f.label" = "键盘"; "1ll-Jn-OD5.title" = "CIN 磁带模式"; +"1Pn-EV-mui.title" = "注音反查"; "20.title" = "Radio"; "21.title" = "横向布局"; "22.title" = "纵向布局"; diff --git a/Source/WindowNIBs/zh-Hant.lproj/frmPrefWindow.strings b/Source/WindowNIBs/zh-Hant.lproj/frmPrefWindow.strings index cbd4e567..4e42c1c3 100644 --- a/Source/WindowNIBs/zh-Hant.lproj/frmPrefWindow.strings +++ b/Source/WindowNIBs/zh-Hant.lproj/frmPrefWindow.strings @@ -13,6 +13,7 @@ "18.title" = "Radio"; "1AW-xf-c2f.label" = "鍵盤"; "1ll-Jn-OD5.title" = "CIN 磁帶模式"; +"1Pn-EV-mui.title" = "注音反查"; "20.title" = "Radio"; "21.title" = "橫向佈局"; "22.title" = "縱向佈局";