From ffd7db4bca60a6b48265b242afbf24d9cc05629a Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Sat, 10 Jun 2023 17:37:30 +0800 Subject: [PATCH] Repo // Allow hot-toggling IMKCandidates. --- Source/Modules/SessionCtl_Core.swift | 19 ++++++++++++++++++- .../PrefUI/VwrPrefPaneCandidates.swift | 9 +-------- .../WindowControllers/CtlPrefWindow.swift | 4 ++-- .../WindowNIBs/en.lproj/frmPrefWindow.strings | 2 +- .../WindowNIBs/ja.lproj/frmPrefWindow.strings | 2 +- .../zh-Hans.lproj/frmPrefWindow.strings | 2 +- .../zh-Hant.lproj/frmPrefWindow.strings | 2 +- 7 files changed, 25 insertions(+), 15 deletions(-) diff --git a/Source/Modules/SessionCtl_Core.swift b/Source/Modules/SessionCtl_Core.swift index d850dad1..ff852c38 100644 --- a/Source/Modules/SessionCtl_Core.swift +++ b/Source/Modules/SessionCtl_Core.swift @@ -29,8 +29,25 @@ public class SessionCtl: IMKInputController { /// 標記狀態來聲明目前新增的詞彙是否需要賦以非常低的權重。 public static var areWeNerfing = false + // IMK 選字窗專用記憶體位址 + private var candidateIMK: CtlCandidateProtocol? + + // 田所選字窗專用記憶體位址 + private var candidateTDK: CtlCandidateProtocol? + /// 目前在用的的選字窗副本。 - public var candidateUI: CtlCandidateProtocol? + public var candidateUI: CtlCandidateProtocol? { + get { + PrefMgr.shared.useIMKCandidateWindow ? candidateIMK : candidateTDK + } + set { + if PrefMgr.shared.useIMKCandidateWindow { + candidateIMK = newValue + } else { + candidateTDK = newValue + } + } + } /// 工具提示視窗的副本。 public var tooltipInstance = TooltipUI() diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneCandidates.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneCandidates.swift index fdf95401..4e3865f0 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneCandidates.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneCandidates.swift @@ -166,15 +166,8 @@ struct VwrPrefPaneCandidates: View { SSPreferences.Settings.Section(title: "Experimental:".localized) { Toggle( LocalizedStringKey("Use IMK Candidate Window instead of Tadokoro"), - isOn: $useIMKCandidateWindow.onChange { - NSLog("vChewing App self-terminated due to enabling / disabling IMK candidate window.") - NSApp.terminate(nil) - } + isOn: $useIMKCandidateWindow ) - Text( - LocalizedStringKey("⚠︎ This will reboot the vChewing IME.") - ) - .preferenceDescription(maxWidth: CtlPrefUIShared.maxDescriptionWidth) Text( "IMK candidate window relies on certain Apple private APIs which are force-exposed by using bridging headers. Its usability, at this moment, is only guaranteed from macOS 10.14 Mojave to macOS 13 Ventura. Further tests are required in the future in order to tell whether it is usable in newer macOS releases.".localized ) diff --git a/Source/Modules/WindowControllers/CtlPrefWindow.swift b/Source/Modules/WindowControllers/CtlPrefWindow.swift index 014c6944..5aa8125d 100644 --- a/Source/Modules/WindowControllers/CtlPrefWindow.swift +++ b/Source/Modules/WindowControllers/CtlPrefWindow.swift @@ -260,8 +260,8 @@ class CtlPrefWindow: NSWindowController, NSWindowDelegate { } @IBAction func updateIMKCandidateEnableStatusAction(_: Any) { - NSLog("vChewing App self-terminated due to enabling / disabling IMK candidate window.") - NSApp.terminate(nil) + // NSLog("vChewing App self-terminated due to enabling / disabling IMK candidate window.") + // NSApp.terminate(nil) } @IBAction func clickedWhetherIMEShouldNotFartToggleAction(_: Any) { diff --git a/Source/WindowNIBs/en.lproj/frmPrefWindow.strings b/Source/WindowNIBs/en.lproj/frmPrefWindow.strings index 1e343062..91279eed 100644 --- a/Source/WindowNIBs/en.lproj/frmPrefWindow.strings +++ b/Source/WindowNIBs/en.lproj/frmPrefWindow.strings @@ -113,7 +113,7 @@ "s7u-Fm-dVg.title" = "Revolving Pages"; "shc-Nu-UsM.title" = "Show notifications when toggling Caps Lock"; "SzF-FL-sVO.title" = "Show translated strokes in composition buffer"; -"tglDevZoneIMKCandidate.title" = "Use IMK Candidate Window instead of Tadokoro (will reboot the IME)"; +"tglDevZoneIMKCandidate.title" = "Use IMK Candidate Window instead of Tadokoro"; "tglTrimUnfinishedReadingsOnCommit.title" = "Trim unfinished readings / strokes on commit"; "TKl-TY-lvN.title" = "General Settings"; "TXr-FF-ehw.title" = "Traditional Chinese"; diff --git a/Source/WindowNIBs/ja.lproj/frmPrefWindow.strings b/Source/WindowNIBs/ja.lproj/frmPrefWindow.strings index 0d41b3dc..68a7af7e 100644 --- a/Source/WindowNIBs/ja.lproj/frmPrefWindow.strings +++ b/Source/WindowNIBs/ja.lproj/frmPrefWindow.strings @@ -113,7 +113,7 @@ "s7u-Fm-dVg.title" = "ページ"; "shc-Nu-UsM.title" = "Caps Lock で切り替えの時に吹出通知メッセージを"; "SzF-FL-sVO.title" = "原始キーネームでなく、筆画を入力緩衝列で表示する"; -"tglDevZoneIMKCandidate.title" = "IMK 候補陳列ウィンドウを起用(入力アプリは自動的に再起動)"; +"tglDevZoneIMKCandidate.title" = "IMK 候補陳列ウィンドウを起用"; "tglTrimUnfinishedReadingsOnCommit.title" = "送り出す緩衝列内容から未完成な音読み/筆組みを除く"; "TKl-TY-lvN.title" = "一般設定"; "TXr-FF-ehw.title" = "繁体中国語"; diff --git a/Source/WindowNIBs/zh-Hans.lproj/frmPrefWindow.strings b/Source/WindowNIBs/zh-Hans.lproj/frmPrefWindow.strings index 1d9c3a28..81bd1dfb 100644 --- a/Source/WindowNIBs/zh-Hans.lproj/frmPrefWindow.strings +++ b/Source/WindowNIBs/zh-Hans.lproj/frmPrefWindow.strings @@ -113,7 +113,7 @@ "s7u-Fm-dVg.title" = "轮替页面"; "shc-Nu-UsM.title" = "以 Caps Lock 切换输入法/中英模式时显示通知"; "SzF-FL-sVO.title" = "在组字区内显示字根、而非原始键盘码"; -"tglDevZoneIMKCandidate.title" = "启用与 macOS 内建输入法相同的 IMK 选字窗(会自动重启输入法)"; +"tglDevZoneIMKCandidate.title" = "启用与 macOS 内建输入法相同的 IMK 选字窗"; "tglTrimUnfinishedReadingsOnCommit.title" = "在递交时清理未完成拼写的读音或字根"; "TKl-TY-lvN.title" = "一般设定"; "TXr-FF-ehw.title" = "繁体中文"; diff --git a/Source/WindowNIBs/zh-Hant.lproj/frmPrefWindow.strings b/Source/WindowNIBs/zh-Hant.lproj/frmPrefWindow.strings index 13dc5a37..1ce70643 100644 --- a/Source/WindowNIBs/zh-Hant.lproj/frmPrefWindow.strings +++ b/Source/WindowNIBs/zh-Hant.lproj/frmPrefWindow.strings @@ -113,7 +113,7 @@ "s7u-Fm-dVg.title" = "輪替頁面"; "shc-Nu-UsM.title" = "以 Caps Lock 切換輸入法/中英模式時顯示通知"; "SzF-FL-sVO.title" = "在組字區內顯示字根、而非原始鍵盤碼"; -"tglDevZoneIMKCandidate.title" = "啟用與 macOS 內建輸入法相同的 IMK 選字窗(會自動重啟輸入法)"; +"tglDevZoneIMKCandidate.title" = "啟用與 macOS 內建輸入法相同的 IMK 選字窗"; "tglTrimUnfinishedReadingsOnCommit.title" = "在遞交時清理未完成拼寫的讀音或字根"; "TKl-TY-lvN.title" = "一般設定"; "TXr-FF-ehw.title" = "繁體中文";