From 7811767f01f7124bb3263ad8f140f85249f0f50e Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Tue, 15 Feb 2022 20:13:23 +0800 Subject: [PATCH] kanjiConv // Bind JIS Conversion to Functions. --- .../IMEModules/PreferencesModule.swift | 22 ++++++- .../Modules/IMEModules/ctlInputMethod.swift | 40 ++++++++++--- .../Resources/Base.lproj/Localizable.strings | 1 + Source/Resources/en.lproj/Localizable.strings | 1 + Source/Resources/ja.lproj/Localizable.strings | 1 + .../zh-Hans.lproj/Localizable.strings | 1 + .../zh-Hant.lproj/Localizable.strings | 1 + Source/WindowControllers/ctlPrefWindow.swift | 17 ++++++ .../WindowNIBs/Base.lproj/frmPrefWindow.xib | 57 ++++++++++++------- .../WindowNIBs/en.lproj/frmPrefWindow.strings | 3 + .../WindowNIBs/ja.lproj/frmPrefWindow.strings | 3 + .../zh-Hans.lproj/frmPrefWindow.strings | 3 + .../zh-Hant.lproj/frmPrefWindow.strings | 3 + 13 files changed, 123 insertions(+), 30 deletions(-) diff --git a/Source/Modules/IMEModules/PreferencesModule.swift b/Source/Modules/IMEModules/PreferencesModule.swift index 6cc51025..aed90dd5 100644 --- a/Source/Modules/IMEModules/PreferencesModule.swift +++ b/Source/Modules/IMEModules/PreferencesModule.swift @@ -36,6 +36,7 @@ private let kComposingBufferSizePreference = "ComposingBufferSize" private let kChooseCandidateUsingSpace = "ChooseCandidateUsingSpace" private let kCNS11643Enabled = "CNS11643Enabled" private let kChineseConversionEnabled = "ChineseConversionEnabled" +private let kShiftJISShinjitaiOutputEnabled = "ShiftJISShinjitaiOutputEnabled" private let kHalfWidthPunctuationEnabled = "HalfWidthPunctuationEnable" private let kMoveCursorAfterSelectingCandidate = "MoveCursorAfterSelectingCandidate" private let kEscToCleanInputBuffer = "EscToCleanInputBuffer" @@ -228,6 +229,7 @@ struct ComposingBufferSize { kChooseCandidateUsingSpace, kCNS11643Enabled, kChineseConversionEnabled, + kShiftJISShinjitaiOutputEnabled, kHalfWidthPunctuationEnabled, kEscToCleanInputBuffer, kCandidateTextFontName, @@ -316,6 +318,11 @@ struct ComposingBufferSize { UserDefaults.standard.set(Preferences.chineseConversionEnabled, forKey: kChineseConversionEnabled) } + // 預設停用繁體轉 JIS 當用新字體模組 + if UserDefaults.standard.object(forKey: kShiftJISShinjitaiOutputEnabled) == nil { + UserDefaults.standard.set(Preferences.shiftJISShinjitaiOutputEnabled, forKey: kShiftJISShinjitaiOutputEnabled) + } + // 預設停用自訂語彙置換 if UserDefaults.standard.object(forKey: kPhraseReplacementEnabled) == nil { UserDefaults.standard.set(Preferences.phraseReplacementEnabled, forKey: kPhraseReplacementEnabled) @@ -411,12 +418,25 @@ struct ComposingBufferSize { @UserDefault(key: kChineseConversionEnabled, defaultValue: false) @objc static var chineseConversionEnabled: Bool - @objc static func toggleChineseConversionEnabled() -> Bool { + @objc @discardableResult static func toggleChineseConversionEnabled() -> Bool { chineseConversionEnabled = !chineseConversionEnabled + // 康熙轉換與 JIS 轉換不能同時開啟,否則會出現某些奇奇怪怪的情況 + if chineseConversionEnabled && shiftJISShinjitaiOutputEnabled {self.toggleShiftJISShinjitaiOutputEnabled()} UserDefaults.standard.set(chineseConversionEnabled, forKey: kChineseConversionEnabled) return chineseConversionEnabled } + @UserDefault(key: kShiftJISShinjitaiOutputEnabled, defaultValue: false) + @objc static var shiftJISShinjitaiOutputEnabled: Bool + + @objc @discardableResult static func toggleShiftJISShinjitaiOutputEnabled() -> Bool { + shiftJISShinjitaiOutputEnabled = !shiftJISShinjitaiOutputEnabled + // 康熙轉換與 JIS 轉換不能同時開啟,否則會出現某些奇奇怪怪的情況 + if shiftJISShinjitaiOutputEnabled && chineseConversionEnabled {self.toggleChineseConversionEnabled()} + UserDefaults.standard.set(shiftJISShinjitaiOutputEnabled, forKey: kShiftJISShinjitaiOutputEnabled) + return shiftJISShinjitaiOutputEnabled + } + @UserDefault(key: kHalfWidthPunctuationEnabled, defaultValue: false) @objc static var halfWidthPunctuationEnabled: Bool diff --git a/Source/Modules/IMEModules/ctlInputMethod.swift b/Source/Modules/IMEModules/ctlInputMethod.swift index 4c7b7543..4335b49f 100644 --- a/Source/Modules/IMEModules/ctlInputMethod.swift +++ b/Source/Modules/IMEModules/ctlInputMethod.swift @@ -67,10 +67,16 @@ class ctlInputMethod: IMKInputController { useCNS11643SupportItem.keyEquivalentModifierMask = [.command, .control] useCNS11643SupportItem.state = Preferences.cns11643Enabled.state - let chineseConversionItem = menu.addItem(withTitle: NSLocalizedString("Force KangXi Writing", comment: ""), action: #selector(toggleChineseConverter(_:)), keyEquivalent: "K") - chineseConversionItem.keyEquivalentModifierMask = [.command, .control] - chineseConversionItem.state = Preferences.chineseConversionEnabled.state + if keyHandler.inputMode == InputMode.imeModeCHT { + let chineseConversionItem = menu.addItem(withTitle: NSLocalizedString("Force KangXi Writing", comment: ""), action: #selector(toggleChineseConverter(_:)), keyEquivalent: "K") + chineseConversionItem.keyEquivalentModifierMask = [.command, .control] + chineseConversionItem.state = Preferences.chineseConversionEnabled.state + let shiftJISConversionItem = menu.addItem(withTitle: NSLocalizedString("JIS Shinjitai Output", comment: ""), action: #selector(toggleShiftJISShinjitaiOutput(_:)), keyEquivalent: "J") + shiftJISConversionItem.keyEquivalentModifierMask = [.command, .control] + shiftJISConversionItem.state = Preferences.shiftJISShinjitaiOutputEnabled.state + } + let halfWidthPunctuationItem = menu.addItem(withTitle: NSLocalizedString("Half-Width Punctuation Mode", comment: ""), action: #selector(toggleHalfWidthPunctuation(_:)), keyEquivalent: "H") halfWidthPunctuationItem.keyEquivalentModifierMask = [.command, .control] halfWidthPunctuationItem.state = Preferences.halfWidthPunctuationEnabled.state @@ -215,6 +221,10 @@ class ctlInputMethod: IMKInputController { NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("Force KangXi Writing", comment: ""), "\n", Preferences.toggleChineseConversionEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: ""))) } + @objc func toggleShiftJISShinjitaiOutput(_ sender: Any?) { + NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("JIS Shinjitai Output", comment: ""), "\n", Preferences.toggleShiftJISShinjitaiOutputEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: ""))) + } + @objc func toggleHalfWidthPunctuation(_ sender: Any?) { NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("Half-Width Punctuation Mode", comment: ""), "\n", Preferences.toggleHalfWidthPunctuationEnabled() ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: ""))) } @@ -320,15 +330,27 @@ extension ctlInputMethod { private func commit(text: String, client: Any!) { - func convertToKangXiChineseIfRequired(_ text: String) -> String { - if !Preferences.chineseConversionEnabled { - return text + func kanjiConversionIfRequired(_ text: String) -> String { + var result : String = "" + if keyHandler.inputMode == InputMode.imeModeCHT { + if !Preferences.chineseConversionEnabled && Preferences.shiftJISShinjitaiOutputEnabled { + result = vChewingKanjiConverter.cnvTradToJIS(text) + } + if Preferences.chineseConversionEnabled && !Preferences.shiftJISShinjitaiOutputEnabled { + result = vChewingKanjiConverter.cnvTradToKangXi(text) + } + // 本來這兩個開關不該同時開啟的,但萬一被開啟了的話就這樣處理: + if Preferences.chineseConversionEnabled && Preferences.shiftJISShinjitaiOutputEnabled { + result = vChewingKanjiConverter.cnvTradToJIS(text) + } } - // return OpenCCBridge.convertToKangXi(text) ?? "" - return vChewingKanjiConverter.cnvTradToKangXi(text) + // if (!Preferences.chineseConversionEnabled && !Preferences.shiftJISShinjitaiOutputEnabled) || (keyHandler.inputMode != InputMode.imeModeCHT); + result = text + + return result } - let buffer = convertToKangXiChineseIfRequired(text) + let buffer = kanjiConversionIfRequired(text) if buffer.isEmpty { return } diff --git a/Source/Resources/Base.lproj/Localizable.strings b/Source/Resources/Base.lproj/Localizable.strings index be8b7293..9f854dac 100644 --- a/Source/Resources/Base.lproj/Localizable.strings +++ b/Source/Resources/Base.lproj/Localizable.strings @@ -37,6 +37,7 @@ "⚠︎ Unhandlable char selected for user phrases." = "⚠︎ Unhandlable char selected for user phrases."; "Per-Char Select Mode" = "Per-Char Select Mode"; "CNS11643 Mode" = "CNS11643 Mode"; +"JIS Shinjitai Output" = "JIS Shinjitai Output"; "Per-Char Associated Phrases" = "Per-Char Associated Phrases"; "Open User Data Folder" = "Open User Data Folder"; "Edit Associated Phrases…" = "Edit Associated Phrases…"; diff --git a/Source/Resources/en.lproj/Localizable.strings b/Source/Resources/en.lproj/Localizable.strings index be8b7293..9f854dac 100644 --- a/Source/Resources/en.lproj/Localizable.strings +++ b/Source/Resources/en.lproj/Localizable.strings @@ -37,6 +37,7 @@ "⚠︎ Unhandlable char selected for user phrases." = "⚠︎ Unhandlable char selected for user phrases."; "Per-Char Select Mode" = "Per-Char Select Mode"; "CNS11643 Mode" = "CNS11643 Mode"; +"JIS Shinjitai Output" = "JIS Shinjitai Output"; "Per-Char Associated Phrases" = "Per-Char Associated Phrases"; "Open User Data Folder" = "Open User Data Folder"; "Edit Associated Phrases…" = "Edit Associated Phrases…"; diff --git a/Source/Resources/ja.lproj/Localizable.strings b/Source/Resources/ja.lproj/Localizable.strings index c0917b8a..df40d67c 100644 --- a/Source/Resources/ja.lproj/Localizable.strings +++ b/Source/Resources/ja.lproj/Localizable.strings @@ -37,6 +37,7 @@ "⚠︎ Unhandlable char selected for user phrases." = "⚠︎ ユーザー辞書の対処できない文字は選択されています。"; "Per-Char Select Mode" = "全候補入力モード"; "CNS11643 Mode" = "全字庫モード"; +"JIS Shinjitai Output" = "JIS 新字体モード"; "Per-Char Associated Phrases" = "全候補入力で連想語彙"; "Open User Data Folder" = "ユーザー資料フォルダを開く"; "Edit Associated Phrases…" = "連想語彙を編集…"; diff --git a/Source/Resources/zh-Hans.lproj/Localizable.strings b/Source/Resources/zh-Hans.lproj/Localizable.strings index 75577658..12bb250c 100644 --- a/Source/Resources/zh-Hans.lproj/Localizable.strings +++ b/Source/Resources/zh-Hans.lproj/Localizable.strings @@ -37,6 +37,7 @@ "⚠︎ Unhandlable char selected for user phrases." = "⚠︎ 已选中无法处理的字符,无法加入自订语汇。"; "Per-Char Select Mode" = "仿真逐字选字输入"; "CNS11643 Mode" = "全字库模式"; +"JIS Shinjitai Output" = "JIS 新字体模式"; "Per-Char Associated Phrases" = "逐字选字联想模式"; "Open User Data Folder" = "开启使用者资料夹"; "Edit Associated Phrases…" = "编辑联想词…"; diff --git a/Source/Resources/zh-Hant.lproj/Localizable.strings b/Source/Resources/zh-Hant.lproj/Localizable.strings index bbb98b51..783fa8dd 100644 --- a/Source/Resources/zh-Hant.lproj/Localizable.strings +++ b/Source/Resources/zh-Hant.lproj/Localizable.strings @@ -37,6 +37,7 @@ "⚠︎ Unhandlable char selected for user phrases." = "⚠︎ 已選中無法處理的字元,無法加入自訂語彙。"; "Per-Char Select Mode" = "模擬逐字選字輸入"; "CNS11643 Mode" = "全字庫模式"; +"JIS Shinjitai Output" = "JIS 新字體模式"; "Per-Char Associated Phrases" = "逐字選字聯想模式"; "Open User Data Folder" = "開啟使用者資料夾"; "Edit Associated Phrases…" = "編輯聯想詞…"; diff --git a/Source/WindowControllers/ctlPrefWindow.swift b/Source/WindowControllers/ctlPrefWindow.swift index 8670a263..12e02c80 100644 --- a/Source/WindowControllers/ctlPrefWindow.swift +++ b/Source/WindowControllers/ctlPrefWindow.swift @@ -36,6 +36,8 @@ extension RangeReplaceableCollection where Element: Hashable { @IBOutlet weak var uiLanguageButton: NSPopUpButton! @IBOutlet weak var basisKeyboardLayoutButton: NSPopUpButton! @IBOutlet weak var selectionKeyComboBox: NSComboBox! + @IBOutlet weak var chkTrad2KangXi: NSButton! + @IBOutlet weak var chkTrad2JISShinjitai: NSButton! var currentLanguageSelectItem: NSMenuItem? = nil @@ -160,6 +162,21 @@ extension RangeReplaceableCollection where Element: Hashable { } selectionKeyComboBox.stringValue = candidateSelectionKeys + + // MARK: - 設定漢字轉換選項是否禁用 + + } + + @IBAction func toggleTrad2KangXiAction(_ sender: Any) { + if chkTrad2KangXi.state == .on && chkTrad2JISShinjitai.state == .on { + Preferences.toggleShiftJISShinjitaiOutputEnabled() + } + } + + @IBAction func toggleTrad2JISShinjitaiAction(_ sender: Any) { + if chkTrad2KangXi.state == .on && chkTrad2JISShinjitai.state == .on { + Preferences.toggleChineseConversionEnabled() + } } @IBAction func updateBasisKeyboardLayoutAction(_ sender: Any) { diff --git a/Source/WindowNIBs/Source/WindowNIBs/Base.lproj/frmPrefWindow.xib b/Source/WindowNIBs/Source/WindowNIBs/Base.lproj/frmPrefWindow.xib index ebc63d2b..50f61204 100644 --- a/Source/WindowNIBs/Source/WindowNIBs/Base.lproj/frmPrefWindow.xib +++ b/Source/WindowNIBs/Source/WindowNIBs/Base.lproj/frmPrefWindow.xib @@ -9,6 +9,8 @@ + + @@ -223,9 +225,9 @@ - + - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -634,11 +651,11 @@ - Regarding On-Screen Keyboard Viewer Support: + Regarding On-Screen Keyboard Viewer Support: Since v1.3.2, vChewing supports on-screen keyboard by supporting "Apple Zhuyin Bopomofo" and "Apple Zhuyin Eten" alphanumeric layout. Theoreotically, these two dynamic layouts work with all types of Apple physical keyboards, and you can report failure cases through macOS Feedback Assistant app if macOS built-in Zhuyin / Eten-Zhuyin Input Method fails from working with your non-US keyboard. - HOWEVER, choosing such dynamic alphanumeric layouts REQUIRING THAT you have to choose the Bopomofo layout above to Standard (Microsoft / Dachen) since the Bopomofo / Eten layout support in this case is already finished by the macOS system. + HOWEVER, choosing such dynamic alphanumeric layouts REQUIRING THAT you have to choose the Bopomofo layout above to Standard (Microsoft / Dachen) since the Bopomofo / Eten layout support in this case is already finished by the macOS system. diff --git a/Source/WindowNIBs/Source/WindowNIBs/en.lproj/frmPrefWindow.strings b/Source/WindowNIBs/Source/WindowNIBs/en.lproj/frmPrefWindow.strings index 18444261..8d36bb1c 100644 --- a/Source/WindowNIBs/Source/WindowNIBs/en.lproj/frmPrefWindow.strings +++ b/Source/WindowNIBs/Source/WindowNIBs/en.lproj/frmPrefWindow.strings @@ -116,6 +116,9 @@ /* Class = "NSButtonCell"; title = "Auto-convert traditional Chinese glyphs to KangXi characters"; ObjectID = "BSK-bH-Gct"; */ "BSK-bH-Gct.title" = "Auto-convert traditional Chinese glyphs to KangXi characters"; +/* Class = "NSButtonCell"; title = "Auto-convert traditional Chinese glyphs to KangXi characters"; ObjectID = "eia-1F-Do0"; */ +"eia-1F-Do0.title" = "Auto-convert traditional Chinese glyphs to JIS Shinjitai characters"; + /* Class = "NSBox"; title = "Advanced Settings"; ObjectID = "E1l-m8-xgb"; */ "E1l-m8-xgb.title" = "Advanced Settings"; diff --git a/Source/WindowNIBs/Source/WindowNIBs/ja.lproj/frmPrefWindow.strings b/Source/WindowNIBs/Source/WindowNIBs/ja.lproj/frmPrefWindow.strings index a7aca5dd..f7c41959 100644 --- a/Source/WindowNIBs/Source/WindowNIBs/ja.lproj/frmPrefWindow.strings +++ b/Source/WindowNIBs/Source/WindowNIBs/ja.lproj/frmPrefWindow.strings @@ -116,6 +116,9 @@ /* Class = "NSButtonCell"; title = "Auto-convert traditional Chinese glyphs to KangXi characters"; ObjectID = "BSK-bH-Gct"; */ "BSK-bH-Gct.title" = "自動的に繁体漢字を康熙文字と変換する"; +/* Class = "NSButtonCell"; title = "Auto-convert traditional Chinese glyphs to KangXi characters"; ObjectID = "eia-1F-Do0"; */ +"eia-1F-Do0.title" = "自動的に繁体漢字をJIS 新字体と変換する"; + /* Class = "NSBox"; title = "Advanced Settings"; ObjectID = "E1l-m8-xgb"; */ "E1l-m8-xgb.title" = "詳細設定"; diff --git a/Source/WindowNIBs/Source/WindowNIBs/zh-Hans.lproj/frmPrefWindow.strings b/Source/WindowNIBs/Source/WindowNIBs/zh-Hans.lproj/frmPrefWindow.strings index 95542870..55278482 100644 --- a/Source/WindowNIBs/Source/WindowNIBs/zh-Hans.lproj/frmPrefWindow.strings +++ b/Source/WindowNIBs/Source/WindowNIBs/zh-Hans.lproj/frmPrefWindow.strings @@ -116,6 +116,9 @@ /* Class = "NSButtonCell"; title = "Auto-convert traditional Chinese glyphs to KangXi characters"; ObjectID = "BSK-bH-Gct"; */ "BSK-bH-Gct.title" = "自动将繁体中文字转换为康熙字"; +/* Class = "NSButtonCell"; title = "Auto-convert traditional Chinese glyphs to KangXi characters"; ObjectID = "eia-1F-Do0"; */ +"eia-1F-Do0.title" = "自动将繁体中文字转换为日本简化字(JIS 新字体)"; + /* Class = "NSBox"; title = "Advanced Settings"; ObjectID = "E1l-m8-xgb"; */ "E1l-m8-xgb.title" = "进阶设定"; diff --git a/Source/WindowNIBs/Source/WindowNIBs/zh-Hant.lproj/frmPrefWindow.strings b/Source/WindowNIBs/Source/WindowNIBs/zh-Hant.lproj/frmPrefWindow.strings index 7ed57551..29a8b8c4 100644 --- a/Source/WindowNIBs/Source/WindowNIBs/zh-Hant.lproj/frmPrefWindow.strings +++ b/Source/WindowNIBs/Source/WindowNIBs/zh-Hant.lproj/frmPrefWindow.strings @@ -116,6 +116,9 @@ /* Class = "NSButtonCell"; title = "Auto-convert traditional Chinese glyphs to KangXi characters"; ObjectID = "BSK-bH-Gct"; */ "BSK-bH-Gct.title" = "自動將繁體中文字轉換為康熙字"; +/* Class = "NSButtonCell"; title = "Auto-convert traditional Chinese glyphs to KangXi characters"; ObjectID = "eia-1F-Do0"; */ +"eia-1F-Do0.title" = "自動將繁體中文字轉換為日本簡化字(JIS 新字體)"; + /* Class = "NSBox"; title = "Advanced Settings"; ObjectID = "E1l-m8-xgb"; */ "E1l-m8-xgb.title" = "進階設定";