MainAssembly // Reload filter when necessary.
This commit is contained in:
parent
60b9f28fa3
commit
9cbf087d95
|
@ -141,7 +141,7 @@ public extension vChewingLM {
|
||||||
|
|
||||||
// 上述幾個函式不要加 Async,因為這些內容都被 LMMgr 負責用別的方法 Async 了、用 GCD 的多任務並行共結來完成。
|
// 上述幾個函式不要加 Async,因為這些內容都被 LMMgr 負責用別的方法 Async 了、用 GCD 的多任務並行共結來完成。
|
||||||
|
|
||||||
public func loadUserPhrasesData(path: String, filterPath: String) {
|
public func loadUserPhrasesData(path: String, filterPath: String?) {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
if FileManager.default.isReadableFile(atPath: path) {
|
if FileManager.default.isReadableFile(atPath: path) {
|
||||||
self.lmUserPhrases.clear()
|
self.lmUserPhrases.clear()
|
||||||
|
@ -151,6 +151,7 @@ public extension vChewingLM {
|
||||||
vCLog("lmUserPhrases: File access failure: \(path)")
|
vCLog("lmUserPhrases: File access failure: \(path)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
guard let filterPath = filterPath else { return }
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
if FileManager.default.isReadableFile(atPath: filterPath) {
|
if FileManager.default.isReadableFile(atPath: filterPath) {
|
||||||
self.lmFiltered.clear()
|
self.lmFiltered.clear()
|
||||||
|
@ -162,6 +163,17 @@ public extension vChewingLM {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 這個函式不用 GCD。
|
||||||
|
public func reloadUserFilterDirectly(path: String) {
|
||||||
|
if FileManager.default.isReadableFile(atPath: path) {
|
||||||
|
lmFiltered.clear()
|
||||||
|
lmFiltered.open(path)
|
||||||
|
vCLog("lmFiltered: \(lmFiltered.count) entries of data loaded from: \(path)")
|
||||||
|
} else {
|
||||||
|
vCLog("lmFiltered: File access failure: \(path)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func loadUserSymbolData(path: String) {
|
public func loadUserSymbolData(path: String) {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
if FileManager.default.isReadableFile(atPath: path) {
|
if FileManager.default.isReadableFile(atPath: path) {
|
||||||
|
|
|
@ -220,15 +220,22 @@ public class LMMgr {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch type {
|
switch type {
|
||||||
case .thePhrases, .theFilter:
|
case .thePhrases:
|
||||||
Self.lmCHT.loadUserPhrasesData(
|
Self.lmCHT.loadUserPhrasesData(
|
||||||
path: userDictDataURL(mode: .imeModeCHT, type: .thePhrases).path,
|
path: userDictDataURL(mode: .imeModeCHT, type: .thePhrases).path,
|
||||||
filterPath: userDictDataURL(mode: .imeModeCHT, type: .theFilter).path
|
filterPath: nil
|
||||||
)
|
)
|
||||||
Self.lmCHS.loadUserPhrasesData(
|
Self.lmCHS.loadUserPhrasesData(
|
||||||
path: userDictDataURL(mode: .imeModeCHS, type: .thePhrases).path,
|
path: userDictDataURL(mode: .imeModeCHS, type: .thePhrases).path,
|
||||||
filterPath: userDictDataURL(mode: .imeModeCHS, type: .theFilter).path
|
filterPath: nil
|
||||||
)
|
)
|
||||||
|
case .theFilter:
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
Self.reloadUserFilterDirectly(mode: IMEApp.currentInputMode)
|
||||||
|
}
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
Self.reloadUserFilterDirectly(mode: IMEApp.currentInputMode.reversed)
|
||||||
|
}
|
||||||
case .theReplacements:
|
case .theReplacements:
|
||||||
if PrefMgr.shared.phraseReplacementEnabled { Self.loadUserPhraseReplacement() }
|
if PrefMgr.shared.phraseReplacementEnabled { Self.loadUserPhraseReplacement() }
|
||||||
case .theAssociates:
|
case .theAssociates:
|
||||||
|
@ -270,6 +277,10 @@ public class LMMgr {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static func reloadUserFilterDirectly(mode: Shared.InputMode) {
|
||||||
|
Self.getLM(mode: mode).reloadUserFilterDirectly(path: userDictDataURL(mode: mode, type: .theFilter).path)
|
||||||
|
}
|
||||||
|
|
||||||
public static func checkIfPhrasePairExists(
|
public static func checkIfPhrasePairExists(
|
||||||
userPhrase: String,
|
userPhrase: String,
|
||||||
mode: Shared.InputMode,
|
mode: Shared.InputMode,
|
||||||
|
|
|
@ -185,6 +185,7 @@ public extension LMMgr {
|
||||||
fileHandle.seek(toFileOffset: currentWorkingOffset)
|
fileHandle.seek(toFileOffset: currentWorkingOffset)
|
||||||
fileHandle.write(blankData)
|
fileHandle.write(blankData)
|
||||||
}
|
}
|
||||||
|
LMMgr.reloadUserFilterDirectly(mode: inputMode)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -282,7 +282,7 @@ public extension LMMgr {
|
||||||
if PrefMgr.shared.phraseEditorAutoReloadExternalModifications {
|
if PrefMgr.shared.phraseEditorAutoReloadExternalModifications {
|
||||||
Broadcaster.shared.eventForReloadingPhraseEditor = .init()
|
Broadcaster.shared.eventForReloadingPhraseEditor = .init()
|
||||||
}
|
}
|
||||||
loadUserPhrasesData(type: .thePhrases)
|
loadUserPhrasesData(type: areWeFiltering ? .theFilter : .thePhrases)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - 藉由語彙編輯器開啟使用者檔案
|
// MARK: - 藉由語彙編輯器開啟使用者檔案
|
||||||
|
|
Loading…
Reference in New Issue