diff --git a/Packages/DanielGalasko_FolderMonitor/Sources/FolderMonitor/FolderMonitor.swift b/Packages/DanielGalasko_FolderMonitor/Sources/FolderMonitor/FolderMonitor.swift index e9cdda44..827e684b 100644 --- a/Packages/DanielGalasko_FolderMonitor/Sources/FolderMonitor/FolderMonitor.swift +++ b/Packages/DanielGalasko_FolderMonitor/Sources/FolderMonitor/FolderMonitor.swift @@ -39,14 +39,14 @@ public class FolderMonitor { // Define the block to call when a file change is detected. folderMonitorSource?.setEventHandler { [weak self] in guard let self = self else { return } - folderDidChange?() + self.folderDidChange?() } // Define a cancel handler to ensure the directory is closed when the source is cancelled. folderMonitorSource?.setCancelHandler { [weak self] in guard let self = self else { return } - close(monitoredFolderFileDescriptor) - monitoredFolderFileDescriptor = -1 - folderMonitorSource = nil + close(self.monitoredFolderFileDescriptor) + self.monitoredFolderFileDescriptor = -1 + self.folderMonitorSource = nil } // Start monitoring the directory via the source. folderMonitorSource?.resume() diff --git a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CtlCandidate.swift b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CtlCandidate.swift index a057fbff..076ff3c7 100644 --- a/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CtlCandidate.swift +++ b/Packages/vChewing_CandidateWindow/Sources/CandidateWindow/CtlCandidate.swift @@ -65,7 +65,7 @@ open class CtlCandidate: NSWindowController, CtlCandidateProtocol { NSObject.cancelPreviousPerformRequests(withTarget: self) DispatchQueue.main.async { [weak self] in guard let self = self else { return } - _ = visible ? window?.orderFront(self) : window?.orderOut(self) + _ = self.visible ? self.window?.orderFront(self) : self.window?.orderOut(self) } } } diff --git a/Packages/vChewing_MainAssembly/Sources/MainAssembly/AppDelegate.swift b/Packages/vChewing_MainAssembly/Sources/MainAssembly/AppDelegate.swift index d6766028..d38579bf 100644 --- a/Packages/vChewing_MainAssembly/Sources/MainAssembly/AppDelegate.swift +++ b/Packages/vChewing_MainAssembly/Sources/MainAssembly/AppDelegate.swift @@ -86,7 +86,7 @@ public extension AppDelegate { LMMgr.initUserLangModels() folderMonitor.folderDidChange = { [weak self] in guard let self = self else { return } - reloadOnFolderChangeHappens() + self.reloadOnFolderChangeHappens() } if LMMgr.userDataFolderExists { folderMonitor.startMonitoring() } @@ -103,7 +103,7 @@ public extension AppDelegate { ) folderMonitor.folderDidChange = { [weak self] in guard let self = self else { return } - reloadOnFolderChangeHappens() + self.reloadOnFolderChangeHappens() } if LMMgr.userDataFolderExists { // 沒有資料夾的話,FolderMonitor 會崩潰。 folderMonitor.startMonitoring() diff --git a/Source/Modules/WindowControllers/CtlPrefWindow_PhraseEditor.swift b/Source/Modules/WindowControllers/CtlPrefWindow_PhraseEditor.swift index 3be64709..7abdcb4f 100644 --- a/Source/Modules/WindowControllers/CtlPrefWindow_PhraseEditor.swift +++ b/Source/Modules/WindowControllers/CtlPrefWindow_PhraseEditor.swift @@ -40,9 +40,9 @@ extension CtlPrefWindow: NSTextViewDelegate, NSTextFieldDelegate { tfdPETextEditor.string = NSLocalizedString("Loading…", comment: "") DispatchQueue.main.async { [weak self] in guard let self = self else { return } - tfdPETextEditor.string = LMMgr.retrieveData(mode: selInputMode, type: selUserDataType) - tfdPETextEditor.toolTip = PETerms.TooltipTexts.sampleDictionaryContent(for: selUserDataType) - isLoading = false + self.tfdPETextEditor.string = LMMgr.retrieveData(mode: self.selInputMode, type: self.selUserDataType) + self.tfdPETextEditor.toolTip = PETerms.TooltipTexts.sampleDictionaryContent(for: self.selUserDataType) + self.isLoading = false } } @@ -176,12 +176,12 @@ extension CtlPrefWindow: NSTextViewDelegate, NSTextFieldDelegate { @IBAction func consolidatePEButtonClicked(_: NSButton) { DispatchQueue.main.async { [weak self] in guard let self = self else { return } - isLoading = true - vChewingLM.LMConsolidator.consolidate(text: &tfdPETextEditor.string, pragma: false) - if selUserDataType == .thePhrases { - LMMgr.shared.tagOverrides(in: &tfdPETextEditor.string, mode: selInputMode) + self.isLoading = true + vChewingLM.LMConsolidator.consolidate(text: &self.tfdPETextEditor.string, pragma: false) + if self.selUserDataType == .thePhrases { + LMMgr.shared.tagOverrides(in: &self.tfdPETextEditor.string, mode: self.selInputMode) } - isLoading = false + self.isLoading = false } } @@ -198,38 +198,38 @@ extension CtlPrefWindow: NSTextViewDelegate, NSTextFieldDelegate { DispatchQueue.main.async { [weak self] in guard let self = self else { return } let app: String = NSEvent.keyModifierFlags.contains(.option) ? "TextEdit" : "Finder" - LMMgr.shared.openPhraseFile(mode: selInputMode, type: selUserDataType, app: app) + LMMgr.shared.openPhraseFile(mode: self.selInputMode, type: self.selUserDataType, app: app) } } @IBAction func addPEButtonClicked(_: NSButton) { DispatchQueue.main.async { [weak self] in guard let self = self else { return } - txtPEField1.stringValue.removeAll { "  \t\n\r".contains($0) } - if selUserDataType != .theAssociates { - txtPEField2.stringValue.regReplace(pattern: #"( +| +| +|\t+)+"#, replaceWith: "-") + self.txtPEField1.stringValue.removeAll { "  \t\n\r".contains($0) } + if self.selUserDataType != .theAssociates { + self.txtPEField2.stringValue.regReplace(pattern: #"( +| +| +|\t+)+"#, replaceWith: "-") } - txtPEField2.stringValue.removeAll { + self.txtPEField2.stringValue.removeAll { self.selUserDataType == .theAssociates ? "\n\r".contains($0) : "  \t\n\r".contains($0) } - txtPEField3.stringValue.removeAll { !"0123456789.-".contains($0) } - txtPECommentField.stringValue.removeAll { "\n\r".contains($0) } - guard !txtPEField1.stringValue.isEmpty, !txtPEField2.stringValue.isEmpty else { return } - var arrResult: [String] = [txtPEField1.stringValue, txtPEField2.stringValue] - if let weightVal = Double(txtPEField3.stringValue), weightVal < 0 { + self.txtPEField3.stringValue.removeAll { !"0123456789.-".contains($0) } + self.txtPECommentField.stringValue.removeAll { "\n\r".contains($0) } + guard !self.txtPEField1.stringValue.isEmpty, !self.txtPEField2.stringValue.isEmpty else { return } + var arrResult: [String] = [self.txtPEField1.stringValue, self.txtPEField2.stringValue] + if let weightVal = Double(self.txtPEField3.stringValue), weightVal < 0 { arrResult.append(weightVal.description) } - if !txtPECommentField.stringValue.isEmpty { arrResult.append("#" + txtPECommentField.stringValue) } + if !self.txtPECommentField.stringValue.isEmpty { arrResult.append("#" + self.txtPECommentField.stringValue) } if LMMgr.shared.checkIfPhrasePairExists( - userPhrase: txtPEField1.stringValue, mode: selInputMode, key: txtPEField2.stringValue + userPhrase: self.txtPEField1.stringValue, mode: self.selInputMode, key: self.txtPEField2.stringValue ) { arrResult.append(" #𝙾𝚟𝚎𝚛𝚛𝚒𝚍𝚎") } - if let lastChar = tfdPETextEditor.string.last, !"\n".contains(lastChar) { + if let lastChar = self.tfdPETextEditor.string.last, !"\n".contains(lastChar) { arrResult.insert("\n", at: 0) } - tfdPETextEditor.string.append(arrResult.joined(separator: " ") + "\n") - clearAllFields() + self.tfdPETextEditor.string.append(arrResult.joined(separator: " ") + "\n") + self.clearAllFields() } } } diff --git a/Source/Modules/WindowControllers/CtlRevLookupWindow.swift b/Source/Modules/WindowControllers/CtlRevLookupWindow.swift index 294f0ab1..11d69e11 100644 --- a/Source/Modules/WindowControllers/CtlRevLookupWindow.swift +++ b/Source/Modules/WindowControllers/CtlRevLookupWindow.swift @@ -158,7 +158,7 @@ class FrmRevLookupWindow: NSWindow { resultView.string = "\n" + "Loading…".localized DispatchQueue.main.async { [weak self] in guard let self = self else { return } - updateResult(with: self.inputField.stringValue) + self.updateResult(with: self.inputField.stringValue) } }