From 9088c1462a83842dca25d14712284ac4b8195d02 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Tue, 1 Mar 2022 17:35:32 +0800 Subject: [PATCH] Pref // Adding preferences for handling alphanumerical input mode. --- .../Modules/IMEModules/PreferencesModule.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Source/Modules/IMEModules/PreferencesModule.swift b/Source/Modules/IMEModules/PreferencesModule.swift index 802982d5..9ee67a12 100644 --- a/Source/Modules/IMEModules/PreferencesModule.swift +++ b/Source/Modules/IMEModules/PreferencesModule.swift @@ -20,6 +20,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH import Cocoa private let kIsDebugModeEnabled = "_DebugMode" +private let kIsAlphanumericalModeEnabled = "IsAlphanumericalModeEnabled" private let kCheckUpdateAutomatically = "CheckUpdateAutomatically" private let kKeyboardLayoutPreference = "KeyboardLayout" private let kBasisKeyboardLayoutPreference = "BasisKeyboardLayout" @@ -214,6 +215,7 @@ struct ComposingBufferSize { @objc public class Preferences: NSObject { static var allKeys:[String] { [kIsDebugModeEnabled, + kIsAlphanumericalModeEnabled, kKeyboardLayoutPreference, kBasisKeyboardLayoutPreference, kFunctionKeyKeyboardLayoutPreference, @@ -253,6 +255,11 @@ struct ComposingBufferSize { UserDefaults.standard.set(Preferences.isDebugModeEnabled, forKey: kIsDebugModeEnabled) } + // 首次啟用輸入法時不要啟用英數模式。 + if UserDefaults.standard.object(forKey: kIsAlphanumericalModeEnabled) == nil { + UserDefaults.standard.set(Preferences.isAlphanumericalModeEnabled, forKey: kIsAlphanumericalModeEnabled) + } + // 首次啟用輸入法時設定不要自動更新,免得在某些要隔絕外部網路連線的保密機構內觸犯資安規則。 if UserDefaults.standard.object(forKey: kCheckUpdateAutomatically) == nil { UserDefaults.standard.set(false, forKey: kCheckUpdateAutomatically) @@ -339,6 +346,16 @@ struct ComposingBufferSize { @UserDefault(key: kIsDebugModeEnabled, defaultValue: false) @objc static var isDebugModeEnabled: Bool + @UserDefault(key: kIsAlphanumericalModeEnabled, defaultValue: false) + @objc static var isAlphanumericalModeEnabled: Bool + + @objc @discardableResult static func toggleAlphanumericalModeEnabled() -> Bool { + isAlphanumericalModeEnabled = !isAlphanumericalModeEnabled + UserDefaults.standard.set(isAlphanumericalModeEnabled, forKey: kIsAlphanumericalModeEnabled) + NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("Alphanumerical Input Mode", comment: ""), "\n", isAlphanumericalModeEnabled ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: ""))) + return isAlphanumericalModeEnabled + } + @UserDefault(key: kAppleLanguagesPreferences, defaultValue: []) @objc static var appleLanguages: Array