From f37cc0c3ea48e72b3e73becb9da8edcbaaee4c49 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Thu, 10 Mar 2022 15:16:52 +0800 Subject: [PATCH] ctlIME & KeyHandler // Add ObjC way to know current inputMode. - This is not recommended to use unless in rare cases that the ctlInputMethod.currentKeyHandler approach doesn't work. --- Source/Modules/ControllerModules/KeyHandler.mm | 9 ++++++--- Source/Modules/IMEModules/ctlInputMethod.swift | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Source/Modules/ControllerModules/KeyHandler.mm b/Source/Modules/ControllerModules/KeyHandler.mm index e7dc6a61..5760db1b 100644 --- a/Source/Modules/ControllerModules/KeyHandler.mm +++ b/Source/Modules/ControllerModules/KeyHandler.mm @@ -27,9 +27,9 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #import "vChewing-Swift.h" #import -InputMode imeModeCHT = @"org.atelierInmu.inputmethod.vChewing.IMECHT"; -InputMode imeModeCHS = @"org.atelierInmu.inputmethod.vChewing.IMECHS"; -InputMode imeModeNULL = @"org.atelierInmu.inputmethod.vChewing.IMENULL"; +InputMode imeModeCHS = ctlInputMethod.kIMEModeCHS; +InputMode imeModeCHT = ctlInputMethod.kIMEModeCHT; +InputMode imeModeNULL = ctlInputMethod.kIMEModeNULL; static const double kEpsilon = 0.000001; @@ -111,6 +111,9 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; newUserOverrideModel = [mgrLangModel userOverrideModelCHT]; } + // Report the current Input Mode to ctlInputMethod: + ctlInputMethod.currentInputMode = newInputMode; + // Synchronize the Preference Setting "setPhraseReplacementEnabled" to the new LM. newLanguageModel->setPhraseReplacementEnabled(Preferences.phraseReplacementEnabled); diff --git a/Source/Modules/IMEModules/ctlInputMethod.swift b/Source/Modules/IMEModules/ctlInputMethod.swift index ae1f6a90..13604d5d 100644 --- a/Source/Modules/IMEModules/ctlInputMethod.swift +++ b/Source/Modules/IMEModules/ctlInputMethod.swift @@ -38,6 +38,10 @@ private extension CandidateController { @objc(ctlInputMethod) class ctlInputMethod: IMKInputController { + @objc static let kIMEModeCHS = "org.atelierInmu.inputmethod.vChewing.IMECHS"; + @objc static let kIMEModeCHT = "org.atelierInmu.inputmethod.vChewing.IMECHT"; + @objc static let kIMEModeNULL = "org.atelierInmu.inputmethod.vChewing.IMENULL"; + private static let tooltipController = TooltipController() // MARK: - @@ -53,6 +57,7 @@ class ctlInputMethod: IMKInputController { // 所以才需要「currentKeyHandler」這個假 keyHandler。 // 這個「currentKeyHandler」僅用來讓其他模組知道當前的輸入模式是什麼模式,除此之外別無屌用。 static var currentKeyHandler: KeyHandler = KeyHandler() + @objc static var currentInputMode = "" // MARK: - IMKInputController methods