mgrPrefs // Let IME remember its most recent input mode.

This commit is contained in:
ShikiSuen 2022-04-14 18:39:45 +08:00
parent 77a4b47ba3
commit f2ca6ed5c9
3 changed files with 8 additions and 2 deletions

View File

@ -112,11 +112,11 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
// 緊接著將新的簡繁輸入模式提報給 ctlInputMethod: // 緊接著將新的簡繁輸入模式提報給 ctlInputMethod:
ctlInputMethod.currentInputMode = isCHS ? imeModeCHS : imeModeCHT; ctlInputMethod.currentInputMode = isCHS ? imeModeCHS : imeModeCHT;
mgrPrefs.mostRecentInputMode = ctlInputMethod.currentInputMode;
// 拿當前的 _inputMode 與 ctlInputMethod 的提報結果對比,不同的話則套用新設定: // 拿當前的 _inputMode 與 ctlInputMethod 的提報結果對比,不同的話則套用新設定:
if (![_inputMode isEqualToString:ctlInputMethod.currentInputMode]) if (![_inputMode isEqualToString:ctlInputMethod.currentInputMode])
{ {
// Reinitiate language models if necessary // Reinitiate language models if necessary
[self setInputModesToLM:isCHS]; [self setInputModesToLM:isCHS];

View File

@ -60,7 +60,7 @@ class ctlInputMethod: IMKInputController {
// currentKeyHandler keyHandler // currentKeyHandler keyHandler
// currentKeyHandler // currentKeyHandler
static var currentKeyHandler: KeyHandler = KeyHandler() static var currentKeyHandler: KeyHandler = KeyHandler()
@objc static var currentInputMode = "" @objc static var currentInputMode = mgrPrefs.mostRecentInputMode
// MARK: - Keyboard Layout Specifier // MARK: - Keyboard Layout Specifier

View File

@ -28,6 +28,7 @@ import Cocoa
struct UserDef { struct UserDef {
static let kIsDebugModeEnabled = "_DebugMode" static let kIsDebugModeEnabled = "_DebugMode"
static let kMostRecentInputMode = "MostRecentInputMode"
static let kUserDataFolderSpecified = "UserDataFolderSpecified" static let kUserDataFolderSpecified = "UserDataFolderSpecified"
static let kCheckUpdateAutomatically = "CheckUpdateAutomatically" static let kCheckUpdateAutomatically = "CheckUpdateAutomatically"
static let kMandarinParser = "MandarinParser" static let kMandarinParser = "MandarinParser"
@ -204,6 +205,7 @@ public class mgrPrefs: NSObject {
static var allKeys: [String] { static var allKeys: [String] {
[ [
UserDef.kIsDebugModeEnabled, UserDef.kIsDebugModeEnabled,
UserDef.kMostRecentInputMode,
UserDef.kUserDataFolderSpecified, UserDef.kUserDataFolderSpecified,
UserDef.kMandarinParser, UserDef.kMandarinParser,
UserDef.kBasicKeyboardLayout, UserDef.kBasicKeyboardLayout,
@ -238,6 +240,7 @@ public class mgrPrefs: NSObject {
// MARK: - Preferences Module plist // MARK: - Preferences Module plist
@objc public static func setMissingDefaults() { @objc public static func setMissingDefaults() {
UserDefaults.standard.setDefault(mgrPrefs.isDebugModeEnabled, forKey: UserDef.kIsDebugModeEnabled) 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.checkUpdateAutomatically, forKey: UserDef.kCheckUpdateAutomatically)
UserDefaults.standard.setDefault( UserDefaults.standard.setDefault(
mgrPrefs.showPageButtonsInCandidateWindow, forKey: UserDef.kShowPageButtonsInCandidateWindow) mgrPrefs.showPageButtonsInCandidateWindow, forKey: UserDef.kShowPageButtonsInCandidateWindow)
@ -271,6 +274,9 @@ public class mgrPrefs: NSObject {
@UserDefault(key: UserDef.kIsDebugModeEnabled, defaultValue: false) @UserDefault(key: UserDef.kIsDebugModeEnabled, defaultValue: false)
@objc static var isDebugModeEnabled: Bool @objc static var isDebugModeEnabled: Bool
@UserDefault(key: UserDef.kMostRecentInputMode, defaultValue: "")
@objc static var mostRecentInputMode: String
@UserDefault(key: UserDef.kCheckUpdateAutomatically, defaultValue: false) @UserDefault(key: UserDef.kCheckUpdateAutomatically, defaultValue: false)
@objc static var checkUpdateAutomatically: Bool @objc static var checkUpdateAutomatically: Bool