From f2ca6ed5c9df9ca2b26d360526a22edf7d2617a3 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Thu, 14 Apr 2022 18:39:45 +0800 Subject: [PATCH] mgrPrefs // Let IME remember its most recent input mode. --- Source/Modules/ControllerModules/KeyHandler.mm | 2 +- Source/Modules/IMEModules/ctlInputMethod.swift | 2 +- Source/Modules/IMEModules/mgrPrefs.swift | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Source/Modules/ControllerModules/KeyHandler.mm b/Source/Modules/ControllerModules/KeyHandler.mm index 46d5458b..36202c28 100644 --- a/Source/Modules/ControllerModules/KeyHandler.mm +++ b/Source/Modules/ControllerModules/KeyHandler.mm @@ -112,11 +112,11 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; // 緊接著將新的簡繁輸入模式提報給 ctlInputMethod: ctlInputMethod.currentInputMode = isCHS ? imeModeCHS : imeModeCHT; + mgrPrefs.mostRecentInputMode = ctlInputMethod.currentInputMode; // 拿當前的 _inputMode 與 ctlInputMethod 的提報結果對比,不同的話則套用新設定: if (![_inputMode isEqualToString:ctlInputMethod.currentInputMode]) { - // Reinitiate language models if necessary [self setInputModesToLM:isCHS]; diff --git a/Source/Modules/IMEModules/ctlInputMethod.swift b/Source/Modules/IMEModules/ctlInputMethod.swift index 1f946a24..f906ad00 100644 --- a/Source/Modules/IMEModules/ctlInputMethod.swift +++ b/Source/Modules/IMEModules/ctlInputMethod.swift @@ -60,7 +60,7 @@ class ctlInputMethod: IMKInputController { // 所以才需要「currentKeyHandler」這個假 keyHandler。 // 這個「currentKeyHandler」僅用來讓其他模組知道當前的輸入模式是什麼模式,除此之外別無屌用。 static var currentKeyHandler: KeyHandler = KeyHandler() - @objc static var currentInputMode = "" + @objc static var currentInputMode = mgrPrefs.mostRecentInputMode // MARK: - Keyboard Layout Specifier diff --git a/Source/Modules/IMEModules/mgrPrefs.swift b/Source/Modules/IMEModules/mgrPrefs.swift index 9f42bb35..9651963a 100644 --- a/Source/Modules/IMEModules/mgrPrefs.swift +++ b/Source/Modules/IMEModules/mgrPrefs.swift @@ -28,6 +28,7 @@ import Cocoa struct UserDef { static let kIsDebugModeEnabled = "_DebugMode" + static let kMostRecentInputMode = "MostRecentInputMode" static let kUserDataFolderSpecified = "UserDataFolderSpecified" static let kCheckUpdateAutomatically = "CheckUpdateAutomatically" static let kMandarinParser = "MandarinParser" @@ -204,6 +205,7 @@ public class mgrPrefs: NSObject { static var allKeys: [String] { [ UserDef.kIsDebugModeEnabled, + UserDef.kMostRecentInputMode, UserDef.kUserDataFolderSpecified, UserDef.kMandarinParser, UserDef.kBasicKeyboardLayout, @@ -238,6 +240,7 @@ public class mgrPrefs: NSObject { // MARK: - 既然 Preferences Module 的預設屬性不自動寫入 plist,那這邊就先寫入了。 @objc public static func setMissingDefaults() { UserDefaults.standard.setDefault(mgrPrefs.isDebugModeEnabled, forKey: UserDef.kIsDebugModeEnabled) + UserDefaults.standard.setDefault(mgrPrefs.mostRecentInputMode, forKey: UserDef.kMostRecentInputMode) UserDefaults.standard.setDefault(mgrPrefs.checkUpdateAutomatically, forKey: UserDef.kCheckUpdateAutomatically) UserDefaults.standard.setDefault( mgrPrefs.showPageButtonsInCandidateWindow, forKey: UserDef.kShowPageButtonsInCandidateWindow) @@ -271,6 +274,9 @@ public class mgrPrefs: NSObject { @UserDefault(key: UserDef.kIsDebugModeEnabled, defaultValue: false) @objc static var isDebugModeEnabled: Bool + @UserDefault(key: UserDef.kMostRecentInputMode, defaultValue: "") + @objc static var mostRecentInputMode: String + @UserDefault(key: UserDef.kCheckUpdateAutomatically, defaultValue: false) @objc static var checkUpdateAutomatically: Bool