Repo // Pack InputMode typedefs into Shared package.
This commit is contained in:
parent
a4a37feb16
commit
f80c13331d
|
@ -238,4 +238,21 @@ public enum Shared {
|
||||||
]
|
]
|
||||||
|
|
||||||
public static let arrSupportedLocales: [String] = ["en", "zh-Hant", "zh-Hans", "ja"]
|
public static let arrSupportedLocales: [String] = ["en", "zh-Hant", "zh-Hans", "ja"]
|
||||||
|
|
||||||
|
// The type of input modes.
|
||||||
|
public enum InputMode: String, CaseIterable {
|
||||||
|
case imeModeCHS = "org.atelierInmu.inputmethod.vChewing.IMECHS"
|
||||||
|
case imeModeCHT = "org.atelierInmu.inputmethod.vChewing.IMECHT"
|
||||||
|
case imeModeNULL = ""
|
||||||
|
public var reversed: Shared.InputMode {
|
||||||
|
switch self {
|
||||||
|
case .imeModeCHS:
|
||||||
|
return .imeModeCHT
|
||||||
|
case .imeModeCHT:
|
||||||
|
return .imeModeCHS
|
||||||
|
case .imeModeNULL:
|
||||||
|
return .imeModeNULL
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ public enum ChineseConverter {
|
||||||
if !PrefMgr.shared.currencyNumeralsEnabled { return }
|
if !PrefMgr.shared.currencyNumeralsEnabled { return }
|
||||||
for key in currencyNumeralDictTable.keys {
|
for key in currencyNumeralDictTable.keys {
|
||||||
guard let result = currencyNumeralDictTable[key] else { continue }
|
guard let result = currencyNumeralDictTable[key] else { continue }
|
||||||
if IMEApp.currentInputMode == InputMode.imeModeCHS {
|
if IMEApp.currentInputMode == .imeModeCHS {
|
||||||
target = target.replacingOccurrences(of: key, with: result.3) // Simplified Chinese
|
target = target.replacingOccurrences(of: key, with: result.3) // Simplified Chinese
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -75,9 +75,9 @@ public enum ChineseConverter {
|
||||||
/// - Returns: Text converted to Different Script.
|
/// - Returns: Text converted to Different Script.
|
||||||
public static func crossConvert(_ string: String) -> String? {
|
public static func crossConvert(_ string: String) -> String? {
|
||||||
switch IMEApp.currentInputMode {
|
switch IMEApp.currentInputMode {
|
||||||
case InputMode.imeModeCHS:
|
case .imeModeCHS:
|
||||||
return shared.convert(string, to: .zhHantTW)
|
return shared.convert(string, to: .zhHantTW)
|
||||||
case InputMode.imeModeCHT:
|
case .imeModeCHT:
|
||||||
return shared.convert(string, to: .zhHansCN)
|
return shared.convert(string, to: .zhHansCN)
|
||||||
default:
|
default:
|
||||||
return string
|
return string
|
||||||
|
@ -97,7 +97,7 @@ public enum ChineseConverter {
|
||||||
}
|
}
|
||||||
|
|
||||||
static func kanjiConversionIfRequired(_ text: String) -> String {
|
static func kanjiConversionIfRequired(_ text: String) -> String {
|
||||||
guard IMEApp.currentInputMode == InputMode.imeModeCHT else { return text }
|
guard IMEApp.currentInputMode == .imeModeCHT else { return text }
|
||||||
switch (PrefMgr.shared.chineseConversionEnabled, PrefMgr.shared.shiftJISShinjitaiOutputEnabled) {
|
switch (PrefMgr.shared.chineseConversionEnabled, PrefMgr.shared.shiftJISShinjitaiOutputEnabled) {
|
||||||
case (false, true): return ChineseConverter.cnvTradToJIS(text)
|
case (false, true): return ChineseConverter.cnvTradToJIS(text)
|
||||||
case (true, false): return ChineseConverter.cnvTradToKangXi(text)
|
case (true, false): return ChineseConverter.cnvTradToKangXi(text)
|
||||||
|
|
|
@ -109,7 +109,7 @@ public enum LMMgr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func loadDataModel(_ mode: InputMode) {
|
public static func loadDataModel(_ mode: Shared.InputMode) {
|
||||||
switch mode {
|
switch mode {
|
||||||
case .imeModeCHS:
|
case .imeModeCHS:
|
||||||
if !Self.lmCHS.isMiscDataLoaded {
|
if !Self.lmCHS.isMiscDataLoaded {
|
||||||
|
@ -156,56 +156,56 @@ public enum LMMgr {
|
||||||
|
|
||||||
public static func loadUserPhrasesData() {
|
public static func loadUserPhrasesData() {
|
||||||
Self.lmCHT.loadUserPhrasesData(
|
Self.lmCHT.loadUserPhrasesData(
|
||||||
path: userPhrasesDataURL(InputMode.imeModeCHT).path,
|
path: userPhrasesDataURL(.imeModeCHT).path,
|
||||||
filterPath: userFilteredDataURL(InputMode.imeModeCHT).path
|
filterPath: userFilteredDataURL(.imeModeCHT).path
|
||||||
)
|
)
|
||||||
Self.lmCHS.loadUserPhrasesData(
|
Self.lmCHS.loadUserPhrasesData(
|
||||||
path: userPhrasesDataURL(InputMode.imeModeCHS).path,
|
path: userPhrasesDataURL(.imeModeCHS).path,
|
||||||
filterPath: userFilteredDataURL(InputMode.imeModeCHS).path
|
filterPath: userFilteredDataURL(.imeModeCHS).path
|
||||||
)
|
)
|
||||||
Self.lmCHT.loadUserSymbolData(path: userSymbolDataURL(InputMode.imeModeCHT).path)
|
Self.lmCHT.loadUserSymbolData(path: userSymbolDataURL(.imeModeCHT).path)
|
||||||
Self.lmCHS.loadUserSymbolData(path: userSymbolDataURL(InputMode.imeModeCHS).path)
|
Self.lmCHS.loadUserSymbolData(path: userSymbolDataURL(.imeModeCHS).path)
|
||||||
|
|
||||||
Self.uomCHT.loadData(fromURL: userOverrideModelDataURL(InputMode.imeModeCHT))
|
Self.uomCHT.loadData(fromURL: userOverrideModelDataURL(.imeModeCHT))
|
||||||
Self.uomCHS.loadData(fromURL: userOverrideModelDataURL(InputMode.imeModeCHS))
|
Self.uomCHS.loadData(fromURL: userOverrideModelDataURL(.imeModeCHS))
|
||||||
|
|
||||||
CandidateNode.load(url: Self.userSymbolMenuDataURL())
|
CandidateNode.load(url: Self.userSymbolMenuDataURL())
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func loadUserAssociatesData() {
|
public static func loadUserAssociatesData() {
|
||||||
Self.lmCHT.loadUserAssociatesData(
|
Self.lmCHT.loadUserAssociatesData(
|
||||||
path: Self.userAssociatesDataURL(InputMode.imeModeCHT).path
|
path: Self.userAssociatesDataURL(.imeModeCHT).path
|
||||||
)
|
)
|
||||||
Self.lmCHS.loadUserAssociatesData(
|
Self.lmCHS.loadUserAssociatesData(
|
||||||
path: Self.userAssociatesDataURL(InputMode.imeModeCHS).path
|
path: Self.userAssociatesDataURL(.imeModeCHS).path
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func loadUserPhraseReplacement() {
|
public static func loadUserPhraseReplacement() {
|
||||||
Self.lmCHT.loadReplacementsData(
|
Self.lmCHT.loadReplacementsData(
|
||||||
path: Self.userReplacementsDataURL(InputMode.imeModeCHT).path
|
path: Self.userReplacementsDataURL(.imeModeCHT).path
|
||||||
)
|
)
|
||||||
Self.lmCHS.loadReplacementsData(
|
Self.lmCHS.loadReplacementsData(
|
||||||
path: Self.userReplacementsDataURL(InputMode.imeModeCHS).path
|
path: Self.userReplacementsDataURL(.imeModeCHS).path
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func loadUserSCPCSequencesData() {
|
public static func loadUserSCPCSequencesData() {
|
||||||
Self.lmCHT.loadUserSCPCSequencesData(
|
Self.lmCHT.loadUserSCPCSequencesData(
|
||||||
path: Self.userSCPCSequencesURL(InputMode.imeModeCHT).path
|
path: Self.userSCPCSequencesURL(.imeModeCHT).path
|
||||||
)
|
)
|
||||||
Self.lmCHS.loadUserSCPCSequencesData(
|
Self.lmCHS.loadUserSCPCSequencesData(
|
||||||
path: Self.userSCPCSequencesURL(InputMode.imeModeCHS).path
|
path: Self.userSCPCSequencesURL(.imeModeCHS).path
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func checkIfUserPhraseExist(
|
public static func checkIfUserPhraseExist(
|
||||||
userPhrase: String,
|
userPhrase: String,
|
||||||
mode: InputMode,
|
mode: Shared.InputMode,
|
||||||
key unigramKey: String
|
key unigramKey: String
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
let unigrams: [Megrez.Unigram] =
|
let unigrams: [Megrez.Unigram] =
|
||||||
(mode == InputMode.imeModeCHT)
|
(mode == .imeModeCHT)
|
||||||
? Self.lmCHT.unigramsFor(key: unigramKey) : Self.lmCHS.unigramsFor(key: unigramKey)
|
? Self.lmCHT.unigramsFor(key: unigramKey) : Self.lmCHS.unigramsFor(key: unigramKey)
|
||||||
for unigram in unigrams {
|
for unigram in unigrams {
|
||||||
if unigram.value == userPhrase {
|
if unigram.value == userPhrase {
|
||||||
|
@ -253,48 +253,48 @@ public enum LMMgr {
|
||||||
/// 使用者語彙辭典資料路徑。
|
/// 使用者語彙辭典資料路徑。
|
||||||
/// - Parameter mode: 簡繁體輸入模式。
|
/// - Parameter mode: 簡繁體輸入模式。
|
||||||
/// - Returns: 資料路徑(URL)。
|
/// - Returns: 資料路徑(URL)。
|
||||||
public static func userPhrasesDataURL(_ mode: InputMode) -> URL {
|
public static func userPhrasesDataURL(_ mode: Shared.InputMode) -> URL {
|
||||||
let fileName = (mode == InputMode.imeModeCHT) ? "userdata-cht.txt" : "userdata-chs.txt"
|
let fileName = (mode == .imeModeCHT) ? "userdata-cht.txt" : "userdata-chs.txt"
|
||||||
return URL(fileURLWithPath: dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName)
|
return URL(fileURLWithPath: dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 使用者繪文字符號辭典資料路徑。
|
/// 使用者繪文字符號辭典資料路徑。
|
||||||
/// - Parameter mode: 簡繁體輸入模式。
|
/// - Parameter mode: 簡繁體輸入模式。
|
||||||
/// - Returns: 資料路徑(URL)。
|
/// - Returns: 資料路徑(URL)。
|
||||||
public static func userSymbolDataURL(_ mode: InputMode) -> URL {
|
public static func userSymbolDataURL(_ mode: Shared.InputMode) -> URL {
|
||||||
let fileName = (mode == InputMode.imeModeCHT) ? "usersymbolphrases-cht.txt" : "usersymbolphrases-chs.txt"
|
let fileName = (mode == .imeModeCHT) ? "usersymbolphrases-cht.txt" : "usersymbolphrases-chs.txt"
|
||||||
return URL(fileURLWithPath: dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName)
|
return URL(fileURLWithPath: dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 使用者聯想詞資料路徑。
|
/// 使用者聯想詞資料路徑。
|
||||||
/// - Parameter mode: 簡繁體輸入模式。
|
/// - Parameter mode: 簡繁體輸入模式。
|
||||||
/// - Returns: 資料路徑(URL)。
|
/// - Returns: 資料路徑(URL)。
|
||||||
public static func userAssociatesDataURL(_ mode: InputMode) -> URL {
|
public static func userAssociatesDataURL(_ mode: Shared.InputMode) -> URL {
|
||||||
let fileName = (mode == InputMode.imeModeCHT) ? "associatedPhrases-cht.txt" : "associatedPhrases-chs.txt"
|
let fileName = (mode == .imeModeCHT) ? "associatedPhrases-cht.txt" : "associatedPhrases-chs.txt"
|
||||||
return URL(fileURLWithPath: dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName)
|
return URL(fileURLWithPath: dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 使用者語彙濾除表資料路徑。
|
/// 使用者語彙濾除表資料路徑。
|
||||||
/// - Parameter mode: 簡繁體輸入模式。
|
/// - Parameter mode: 簡繁體輸入模式。
|
||||||
/// - Returns: 資料路徑(URL)。
|
/// - Returns: 資料路徑(URL)。
|
||||||
public static func userFilteredDataURL(_ mode: InputMode) -> URL {
|
public static func userFilteredDataURL(_ mode: Shared.InputMode) -> URL {
|
||||||
let fileName = (mode == InputMode.imeModeCHT) ? "exclude-phrases-cht.txt" : "exclude-phrases-chs.txt"
|
let fileName = (mode == .imeModeCHT) ? "exclude-phrases-cht.txt" : "exclude-phrases-chs.txt"
|
||||||
return URL(fileURLWithPath: dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName)
|
return URL(fileURLWithPath: dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 使用者語彙置換表資料路徑。
|
/// 使用者語彙置換表資料路徑。
|
||||||
/// - Parameter mode: 簡繁體輸入模式。
|
/// - Parameter mode: 簡繁體輸入模式。
|
||||||
/// - Returns: 資料路徑(URL)。
|
/// - Returns: 資料路徑(URL)。
|
||||||
public static func userReplacementsDataURL(_ mode: InputMode) -> URL {
|
public static func userReplacementsDataURL(_ mode: Shared.InputMode) -> URL {
|
||||||
let fileName = (mode == InputMode.imeModeCHT) ? "phrases-replacement-cht.txt" : "phrases-replacement-chs.txt"
|
let fileName = (mode == .imeModeCHT) ? "phrases-replacement-cht.txt" : "phrases-replacement-chs.txt"
|
||||||
return URL(fileURLWithPath: dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName)
|
return URL(fileURLWithPath: dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 使用者逐字選字模式候選字詞順序資料路徑。
|
/// 使用者逐字選字模式候選字詞順序資料路徑。
|
||||||
/// - Parameter mode: 簡繁體輸入模式。
|
/// - Parameter mode: 簡繁體輸入模式。
|
||||||
/// - Returns: 資料路徑(URL)。
|
/// - Returns: 資料路徑(URL)。
|
||||||
public static func userSCPCSequencesURL(_ mode: InputMode) -> URL {
|
public static func userSCPCSequencesURL(_ mode: Shared.InputMode) -> URL {
|
||||||
let fileName = (mode == InputMode.imeModeCHT) ? "data-plain-bpmf-cht.plist" : "data-plain-bpmf-chs.plist"
|
let fileName = (mode == .imeModeCHT) ? "data-plain-bpmf-cht.plist" : "data-plain-bpmf-chs.plist"
|
||||||
return URL(fileURLWithPath: dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName)
|
return URL(fileURLWithPath: dataFolderPath(isDefaultFolder: false)).appendingPathComponent(fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,7 +309,7 @@ public enum LMMgr {
|
||||||
/// 也就是「~/Library/Application Support/vChewing/」目錄下,且不會隨著使用者辭典目錄的改變而改變。
|
/// 也就是「~/Library/Application Support/vChewing/」目錄下,且不會隨著使用者辭典目錄的改變而改變。
|
||||||
/// - Parameter mode: 簡繁體輸入模式。
|
/// - Parameter mode: 簡繁體輸入模式。
|
||||||
/// - Returns: 資料路徑(URL)。
|
/// - Returns: 資料路徑(URL)。
|
||||||
public static func userOverrideModelDataURL(_ mode: InputMode) -> URL {
|
public static func userOverrideModelDataURL(_ mode: Shared.InputMode) -> URL {
|
||||||
let fileName: String = {
|
let fileName: String = {
|
||||||
switch mode {
|
switch mode {
|
||||||
case .imeModeCHS: return "vChewing_override-model-data-chs.dat"
|
case .imeModeCHS: return "vChewing_override-model-data-chs.dat"
|
||||||
|
@ -350,7 +350,7 @@ public enum LMMgr {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@discardableResult public static func chkUserLMFilesExist(_ mode: InputMode) -> Bool {
|
@discardableResult public static func chkUserLMFilesExist(_ mode: Shared.InputMode) -> Bool {
|
||||||
if !userDataFolderExists {
|
if !userDataFolderExists {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -477,11 +477,11 @@ public enum LMMgr {
|
||||||
// MARK: - 寫入使用者檔案
|
// MARK: - 寫入使用者檔案
|
||||||
|
|
||||||
public static func writeUserPhrase(
|
public static func writeUserPhrase(
|
||||||
_ userPhrase: String?, inputMode mode: InputMode, areWeDuplicating: Bool, areWeDeleting: Bool
|
_ userPhrase: String?, inputMode mode: Shared.InputMode, areWeDuplicating: Bool, areWeDeleting: Bool
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
if var currentMarkedPhrase: String = userPhrase {
|
if var currentMarkedPhrase: String = userPhrase {
|
||||||
if !chkUserLMFilesExist(InputMode.imeModeCHS)
|
if !chkUserLMFilesExist(.imeModeCHS)
|
||||||
|| !chkUserLMFilesExist(InputMode.imeModeCHT)
|
|| !chkUserLMFilesExist(.imeModeCHT)
|
||||||
{
|
{
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -526,8 +526,8 @@ public enum LMMgr {
|
||||||
// MARK: - 藉由語彙編輯器開啟使用者檔案
|
// MARK: - 藉由語彙編輯器開啟使用者檔案
|
||||||
|
|
||||||
public static func checkIfUserFilesExistBeforeOpening() -> Bool {
|
public static func checkIfUserFilesExistBeforeOpening() -> Bool {
|
||||||
if !Self.chkUserLMFilesExist(InputMode.imeModeCHS)
|
if !Self.chkUserLMFilesExist(.imeModeCHS)
|
||||||
|| !Self.chkUserLMFilesExist(InputMode.imeModeCHT)
|
|| !Self.chkUserLMFilesExist(.imeModeCHT)
|
||||||
{
|
{
|
||||||
let content = String(
|
let content = String(
|
||||||
format: NSLocalizedString(
|
format: NSLocalizedString(
|
||||||
|
@ -562,19 +562,19 @@ public enum LMMgr {
|
||||||
let group = DispatchGroup()
|
let group = DispatchGroup()
|
||||||
group.enter()
|
group.enter()
|
||||||
globalQuene.async {
|
globalQuene.async {
|
||||||
Self.uomCHT.saveData(toURL: userOverrideModelDataURL(InputMode.imeModeCHT))
|
Self.uomCHT.saveData(toURL: userOverrideModelDataURL(.imeModeCHT))
|
||||||
group.leave()
|
group.leave()
|
||||||
}
|
}
|
||||||
group.enter()
|
group.enter()
|
||||||
globalQuene.async {
|
globalQuene.async {
|
||||||
Self.uomCHS.saveData(toURL: userOverrideModelDataURL(InputMode.imeModeCHS))
|
Self.uomCHS.saveData(toURL: userOverrideModelDataURL(.imeModeCHS))
|
||||||
group.leave()
|
group.leave()
|
||||||
}
|
}
|
||||||
_ = group.wait(timeout: .distantFuture)
|
_ = group.wait(timeout: .distantFuture)
|
||||||
group.notify(queue: DispatchQueue.main) {}
|
group.notify(queue: DispatchQueue.main) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func removeUnigramsFromUserOverrideModel(_ mode: InputMode) {
|
public static func removeUnigramsFromUserOverrideModel(_ mode: Shared.InputMode) {
|
||||||
switch mode {
|
switch mode {
|
||||||
case .imeModeCHS:
|
case .imeModeCHS:
|
||||||
Self.uomCHT.bleachUnigrams(saveCallback: { Self.uomCHT.saveData() })
|
Self.uomCHT.bleachUnigrams(saveCallback: { Self.uomCHT.saveData() })
|
||||||
|
@ -585,12 +585,12 @@ public enum LMMgr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func clearUserOverrideModelData(_ mode: InputMode = .imeModeNULL) {
|
public static func clearUserOverrideModelData(_ mode: Shared.InputMode = .imeModeNULL) {
|
||||||
switch mode {
|
switch mode {
|
||||||
case .imeModeCHS:
|
case .imeModeCHS:
|
||||||
Self.uomCHS.clearData(withURL: userOverrideModelDataURL(InputMode.imeModeCHS))
|
Self.uomCHS.clearData(withURL: userOverrideModelDataURL(.imeModeCHS))
|
||||||
case .imeModeCHT:
|
case .imeModeCHT:
|
||||||
Self.uomCHT.clearData(withURL: userOverrideModelDataURL(InputMode.imeModeCHT))
|
Self.uomCHT.clearData(withURL: userOverrideModelDataURL(.imeModeCHT))
|
||||||
case .imeModeNULL:
|
case .imeModeNULL:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,11 +48,11 @@ public class ctlCandidateIMK: IMKCandidates, ctlCandidateProtocol {
|
||||||
attributes?[NSAttributedString.Key.font] = candidateFont
|
attributes?[NSAttributedString.Key.font] = candidateFont
|
||||||
if PrefMgr.shared.handleDefaultCandidateFontsByLangIdentifier {
|
if PrefMgr.shared.handleDefaultCandidateFontsByLangIdentifier {
|
||||||
switch IMEApp.currentInputMode {
|
switch IMEApp.currentInputMode {
|
||||||
case InputMode.imeModeCHS:
|
case .imeModeCHS:
|
||||||
if #available(macOS 12.0, *) {
|
if #available(macOS 12.0, *) {
|
||||||
attributes?[NSAttributedString.Key.languageIdentifier] = "zh-Hans" as AnyObject
|
attributes?[NSAttributedString.Key.languageIdentifier] = "zh-Hans" as AnyObject
|
||||||
}
|
}
|
||||||
case InputMode.imeModeCHT:
|
case .imeModeCHT:
|
||||||
if #available(macOS 12.0, *) {
|
if #available(macOS 12.0, *) {
|
||||||
attributes?[NSAttributedString.Key.languageIdentifier] =
|
attributes?[NSAttributedString.Key.languageIdentifier] =
|
||||||
(PrefMgr.shared.shiftJISShinjitaiOutputEnabled || PrefMgr.shared.chineseConversionEnabled)
|
(PrefMgr.shared.shiftJISShinjitaiOutputEnabled || PrefMgr.shared.chineseConversionEnabled)
|
||||||
|
|
|
@ -136,11 +136,11 @@ private class vwrCandidateUniversal: NSView {
|
||||||
func ensureLangIdentifier(for attr: inout [NSAttributedString.Key: AnyObject]) {
|
func ensureLangIdentifier(for attr: inout [NSAttributedString.Key: AnyObject]) {
|
||||||
if PrefMgr.shared.handleDefaultCandidateFontsByLangIdentifier {
|
if PrefMgr.shared.handleDefaultCandidateFontsByLangIdentifier {
|
||||||
switch IMEApp.currentInputMode {
|
switch IMEApp.currentInputMode {
|
||||||
case InputMode.imeModeCHS:
|
case .imeModeCHS:
|
||||||
if #available(macOS 12.0, *) {
|
if #available(macOS 12.0, *) {
|
||||||
attr[.languageIdentifier] = "zh-Hans" as AnyObject
|
attr[.languageIdentifier] = "zh-Hans" as AnyObject
|
||||||
}
|
}
|
||||||
case InputMode.imeModeCHT:
|
case .imeModeCHT:
|
||||||
if #available(macOS 12.0, *) {
|
if #available(macOS 12.0, *) {
|
||||||
attr[.languageIdentifier] =
|
attr[.languageIdentifier] =
|
||||||
(PrefMgr.shared.shiftJISShinjitaiOutputEnabled || PrefMgr.shared.chineseConversionEnabled)
|
(PrefMgr.shared.shiftJISShinjitaiOutputEnabled || PrefMgr.shared.chineseConversionEnabled)
|
||||||
|
@ -160,9 +160,9 @@ private class vwrCandidateUniversal: NSView {
|
||||||
}
|
}
|
||||||
// The background color of the highlightened candidate
|
// The background color of the highlightened candidate
|
||||||
switch IMEApp.currentInputMode {
|
switch IMEApp.currentInputMode {
|
||||||
case InputMode.imeModeCHS:
|
case .imeModeCHS:
|
||||||
result = NSColor.systemRed
|
result = NSColor.systemRed
|
||||||
case InputMode.imeModeCHT:
|
case .imeModeCHT:
|
||||||
result = NSColor.systemBlue
|
result = NSColor.systemBlue
|
||||||
default: break
|
default: break
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,14 +168,14 @@ class ctlInputMethod: IMKInputController {
|
||||||
override func setValue(_ value: Any!, forTag tag: Int, client sender: Any!) {
|
override func setValue(_ value: Any!, forTag tag: Int, client sender: Any!) {
|
||||||
_ = tag // 防止格式整理工具毀掉與此對應的參數。
|
_ = tag // 防止格式整理工具毀掉與此對應的參數。
|
||||||
_ = sender // 防止格式整理工具毀掉與此對應的參數。
|
_ = sender // 防止格式整理工具毀掉與此對應的參數。
|
||||||
var newInputMode = InputMode(rawValue: value as? String ?? "") ?? InputMode.imeModeNULL
|
var newInputMode = Shared.InputMode(rawValue: value as? String ?? "") ?? Shared.InputMode.imeModeNULL
|
||||||
switch newInputMode {
|
switch newInputMode {
|
||||||
case InputMode.imeModeCHS:
|
case .imeModeCHS:
|
||||||
newInputMode = InputMode.imeModeCHS
|
newInputMode = .imeModeCHS
|
||||||
case InputMode.imeModeCHT:
|
case .imeModeCHT:
|
||||||
newInputMode = InputMode.imeModeCHT
|
newInputMode = .imeModeCHT
|
||||||
default:
|
default:
|
||||||
newInputMode = InputMode.imeModeNULL
|
newInputMode = .imeModeNULL
|
||||||
}
|
}
|
||||||
LMMgr.loadDataModel(newInputMode)
|
LMMgr.loadDataModel(newInputMode)
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ class ctlInputMethod: IMKInputController {
|
||||||
|
|
||||||
/// InputMode 需要在每次出現內容變更的時候都連帶重設組字器與各項語言模組,
|
/// InputMode 需要在每次出現內容變更的時候都連帶重設組字器與各項語言模組,
|
||||||
/// 順帶更新 IME 模組及 UserPrefs 當中對於當前語言模式的記載。
|
/// 順帶更新 IME 模組及 UserPrefs 當中對於當前語言模式的記載。
|
||||||
var inputMode: InputMode = IMEApp.currentInputMode {
|
var inputMode: Shared.InputMode = IMEApp.currentInputMode {
|
||||||
willSet {
|
willSet {
|
||||||
/// 將新的簡繁輸入模式提報給 Prefs 與 IME 模組。
|
/// 將新的簡繁輸入模式提報給 Prefs 與 IME 模組。
|
||||||
IMEApp.currentInputMode = newValue
|
IMEApp.currentInputMode = newValue
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// marks, or product names of Contributor, except as required to fulfill notice
|
// marks, or product names of Contributor, except as required to fulfill notice
|
||||||
// requirements defined in MIT License.
|
// requirements defined in MIT License.
|
||||||
|
|
||||||
|
import Shared
|
||||||
|
|
||||||
// MARK: - KeyHandler Delegate
|
// MARK: - KeyHandler Delegate
|
||||||
|
|
||||||
extension ctlInputMethod: KeyHandlerDelegate {
|
extension ctlInputMethod: KeyHandlerDelegate {
|
||||||
|
@ -26,9 +28,8 @@ extension ctlInputMethod: KeyHandlerDelegate {
|
||||||
-> Bool
|
-> Bool
|
||||||
{
|
{
|
||||||
guard state.type == .ofMarking else { return false }
|
guard state.type == .ofMarking else { return false }
|
||||||
let refInputModeReversed: InputMode =
|
let refInputModeReversed: Shared.InputMode =
|
||||||
(inputMode == InputMode.imeModeCHT)
|
(inputMode == .imeModeCHT) ? .imeModeCHS : .imeModeCHT
|
||||||
? InputMode.imeModeCHS : InputMode.imeModeCHT
|
|
||||||
if !LMMgr.writeUserPhrase(
|
if !LMMgr.writeUserPhrase(
|
||||||
state.data.userPhraseDumped, inputMode: inputMode,
|
state.data.userPhraseDumped, inputMode: inputMode,
|
||||||
areWeDuplicating: state.data.chkIfUserPhraseExists,
|
areWeDuplicating: state.data.chkIfUserPhraseExists,
|
||||||
|
|
|
@ -192,9 +192,9 @@ extension ctlInputMethod {
|
||||||
let finalReturnFont: NSFont =
|
let finalReturnFont: NSFont =
|
||||||
{
|
{
|
||||||
switch IMEApp.currentInputMode {
|
switch IMEApp.currentInputMode {
|
||||||
case InputMode.imeModeCHS:
|
case .imeModeCHS:
|
||||||
return CTFontCreateUIFontForLanguage(.system, size, "zh-Hans" as CFString)
|
return CTFontCreateUIFontForLanguage(.system, size, "zh-Hans" as CFString)
|
||||||
case InputMode.imeModeCHT:
|
case .imeModeCHT:
|
||||||
return (PrefMgr.shared.shiftJISShinjitaiOutputEnabled || PrefMgr.shared.chineseConversionEnabled)
|
return (PrefMgr.shared.shiftJISShinjitaiOutputEnabled || PrefMgr.shared.chineseConversionEnabled)
|
||||||
? CTFontCreateUIFontForLanguage(.system, size, "ja" as CFString)
|
? CTFontCreateUIFontForLanguage(.system, size, "ja" as CFString)
|
||||||
: CTFontCreateUIFontForLanguage(.system, size, "zh-Hant" as CFString)
|
: CTFontCreateUIFontForLanguage(.system, size, "zh-Hant" as CFString)
|
||||||
|
|
|
@ -48,7 +48,7 @@ extension ctlInputMethod {
|
||||||
useCNS11643SupportItem.keyEquivalentModifierMask = [.command, .control]
|
useCNS11643SupportItem.keyEquivalentModifierMask = [.command, .control]
|
||||||
useCNS11643SupportItem.state = PrefMgr.shared.cns11643Enabled.state
|
useCNS11643SupportItem.state = PrefMgr.shared.cns11643Enabled.state
|
||||||
|
|
||||||
if IMEApp.currentInputMode == InputMode.imeModeCHT {
|
if IMEApp.currentInputMode == .imeModeCHT {
|
||||||
let chineseConversionItem = menu.addItem(
|
let chineseConversionItem = menu.addItem(
|
||||||
withTitle: NSLocalizedString("Force KangXi Writing", comment: ""),
|
withTitle: NSLocalizedString("Force KangXi Writing", comment: ""),
|
||||||
action: #selector(toggleChineseConverter(_:)), keyEquivalent: PrefMgr.shared.usingHotKeyKangXi ? "K" : ""
|
action: #selector(toggleChineseConverter(_:)), keyEquivalent: PrefMgr.shared.usingHotKeyKangXi ? "K" : ""
|
||||||
|
|
|
@ -74,27 +74,11 @@ NSApp.run()
|
||||||
|
|
||||||
// MARK: - Top-level Enums relating to Input Mode and Language Supports.
|
// MARK: - Top-level Enums relating to Input Mode and Language Supports.
|
||||||
|
|
||||||
// The type of input modes.
|
|
||||||
public enum InputMode: String, CaseIterable {
|
|
||||||
case imeModeCHS = "org.atelierInmu.inputmethod.vChewing.IMECHS"
|
|
||||||
case imeModeCHT = "org.atelierInmu.inputmethod.vChewing.IMECHT"
|
|
||||||
case imeModeNULL = ""
|
|
||||||
var reversed: InputMode {
|
|
||||||
switch self {
|
|
||||||
case .imeModeCHS:
|
|
||||||
return .imeModeCHT
|
|
||||||
case .imeModeCHT:
|
|
||||||
return .imeModeCHS
|
|
||||||
case .imeModeNULL:
|
|
||||||
return .imeModeNULL
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum IMEApp {
|
public enum IMEApp {
|
||||||
// MARK: - 輸入法的當前的簡繁體中文模式
|
// MARK: - 輸入法的當前的簡繁體中文模式
|
||||||
|
|
||||||
public static var currentInputMode: InputMode = .init(rawValue: PrefMgr.shared.mostRecentInputMode) ?? .imeModeNULL
|
public static var currentInputMode: Shared.InputMode =
|
||||||
|
.init(rawValue: PrefMgr.shared.mostRecentInputMode) ?? .imeModeNULL
|
||||||
|
|
||||||
/// Fart or Beep?
|
/// Fart or Beep?
|
||||||
static func buzz() {
|
static func buzz() {
|
||||||
|
|
Loading…
Reference in New Issue