Repo // Xcode 14.2 comaptibility.
This commit is contained in:
parent
e6e27ee937
commit
90c35db4d1
|
@ -39,14 +39,14 @@ public class FolderMonitor {
|
||||||
// Define the block to call when a file change is detected.
|
// Define the block to call when a file change is detected.
|
||||||
folderMonitorSource?.setEventHandler { [weak self] in
|
folderMonitorSource?.setEventHandler { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
folderDidChange?()
|
self.folderDidChange?()
|
||||||
}
|
}
|
||||||
// Define a cancel handler to ensure the directory is closed when the source is cancelled.
|
// Define a cancel handler to ensure the directory is closed when the source is cancelled.
|
||||||
folderMonitorSource?.setCancelHandler { [weak self] in
|
folderMonitorSource?.setCancelHandler { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
close(monitoredFolderFileDescriptor)
|
close(self.monitoredFolderFileDescriptor)
|
||||||
monitoredFolderFileDescriptor = -1
|
self.monitoredFolderFileDescriptor = -1
|
||||||
folderMonitorSource = nil
|
self.folderMonitorSource = nil
|
||||||
}
|
}
|
||||||
// Start monitoring the directory via the source.
|
// Start monitoring the directory via the source.
|
||||||
folderMonitorSource?.resume()
|
folderMonitorSource?.resume()
|
||||||
|
|
|
@ -65,7 +65,7 @@ open class CtlCandidate: NSWindowController, CtlCandidateProtocol {
|
||||||
NSObject.cancelPreviousPerformRequests(withTarget: self)
|
NSObject.cancelPreviousPerformRequests(withTarget: self)
|
||||||
DispatchQueue.main.async { [weak self] in
|
DispatchQueue.main.async { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
_ = visible ? window?.orderFront(self) : window?.orderOut(self)
|
_ = self.visible ? self.window?.orderFront(self) : self.window?.orderOut(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ public extension AppDelegate {
|
||||||
LMMgr.initUserLangModels()
|
LMMgr.initUserLangModels()
|
||||||
folderMonitor.folderDidChange = { [weak self] in
|
folderMonitor.folderDidChange = { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
reloadOnFolderChangeHappens()
|
self.reloadOnFolderChangeHappens()
|
||||||
}
|
}
|
||||||
if LMMgr.userDataFolderExists { folderMonitor.startMonitoring() }
|
if LMMgr.userDataFolderExists { folderMonitor.startMonitoring() }
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ public extension AppDelegate {
|
||||||
)
|
)
|
||||||
folderMonitor.folderDidChange = { [weak self] in
|
folderMonitor.folderDidChange = { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
reloadOnFolderChangeHappens()
|
self.reloadOnFolderChangeHappens()
|
||||||
}
|
}
|
||||||
if LMMgr.userDataFolderExists { // 沒有資料夾的話,FolderMonitor 會崩潰。
|
if LMMgr.userDataFolderExists { // 沒有資料夾的話,FolderMonitor 會崩潰。
|
||||||
folderMonitor.startMonitoring()
|
folderMonitor.startMonitoring()
|
||||||
|
|
|
@ -40,9 +40,9 @@ extension CtlPrefWindow: NSTextViewDelegate, NSTextFieldDelegate {
|
||||||
tfdPETextEditor.string = NSLocalizedString("Loading…", comment: "")
|
tfdPETextEditor.string = NSLocalizedString("Loading…", comment: "")
|
||||||
DispatchQueue.main.async { [weak self] in
|
DispatchQueue.main.async { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
tfdPETextEditor.string = LMMgr.retrieveData(mode: selInputMode, type: selUserDataType)
|
self.tfdPETextEditor.string = LMMgr.retrieveData(mode: self.selInputMode, type: self.selUserDataType)
|
||||||
tfdPETextEditor.toolTip = PETerms.TooltipTexts.sampleDictionaryContent(for: selUserDataType)
|
self.tfdPETextEditor.toolTip = PETerms.TooltipTexts.sampleDictionaryContent(for: self.selUserDataType)
|
||||||
isLoading = false
|
self.isLoading = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,12 +176,12 @@ extension CtlPrefWindow: NSTextViewDelegate, NSTextFieldDelegate {
|
||||||
@IBAction func consolidatePEButtonClicked(_: NSButton) {
|
@IBAction func consolidatePEButtonClicked(_: NSButton) {
|
||||||
DispatchQueue.main.async { [weak self] in
|
DispatchQueue.main.async { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
isLoading = true
|
self.isLoading = true
|
||||||
vChewingLM.LMConsolidator.consolidate(text: &tfdPETextEditor.string, pragma: false)
|
vChewingLM.LMConsolidator.consolidate(text: &self.tfdPETextEditor.string, pragma: false)
|
||||||
if selUserDataType == .thePhrases {
|
if self.selUserDataType == .thePhrases {
|
||||||
LMMgr.shared.tagOverrides(in: &tfdPETextEditor.string, mode: selInputMode)
|
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
|
DispatchQueue.main.async { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
let app: String = NSEvent.keyModifierFlags.contains(.option) ? "TextEdit" : "Finder"
|
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) {
|
@IBAction func addPEButtonClicked(_: NSButton) {
|
||||||
DispatchQueue.main.async { [weak self] in
|
DispatchQueue.main.async { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
txtPEField1.stringValue.removeAll { " \t\n\r".contains($0) }
|
self.txtPEField1.stringValue.removeAll { " \t\n\r".contains($0) }
|
||||||
if selUserDataType != .theAssociates {
|
if self.selUserDataType != .theAssociates {
|
||||||
txtPEField2.stringValue.regReplace(pattern: #"( +| +| +|\t+)+"#, replaceWith: "-")
|
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)
|
self.selUserDataType == .theAssociates ? "\n\r".contains($0) : " \t\n\r".contains($0)
|
||||||
}
|
}
|
||||||
txtPEField3.stringValue.removeAll { !"0123456789.-".contains($0) }
|
self.txtPEField3.stringValue.removeAll { !"0123456789.-".contains($0) }
|
||||||
txtPECommentField.stringValue.removeAll { "\n\r".contains($0) }
|
self.txtPECommentField.stringValue.removeAll { "\n\r".contains($0) }
|
||||||
guard !txtPEField1.stringValue.isEmpty, !txtPEField2.stringValue.isEmpty else { return }
|
guard !self.txtPEField1.stringValue.isEmpty, !self.txtPEField2.stringValue.isEmpty else { return }
|
||||||
var arrResult: [String] = [txtPEField1.stringValue, txtPEField2.stringValue]
|
var arrResult: [String] = [self.txtPEField1.stringValue, self.txtPEField2.stringValue]
|
||||||
if let weightVal = Double(txtPEField3.stringValue), weightVal < 0 {
|
if let weightVal = Double(self.txtPEField3.stringValue), weightVal < 0 {
|
||||||
arrResult.append(weightVal.description)
|
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(
|
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(" #𝙾𝚟𝚎𝚛𝚛𝚒𝚍𝚎")
|
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)
|
arrResult.insert("\n", at: 0)
|
||||||
}
|
}
|
||||||
tfdPETextEditor.string.append(arrResult.joined(separator: " ") + "\n")
|
self.tfdPETextEditor.string.append(arrResult.joined(separator: " ") + "\n")
|
||||||
clearAllFields()
|
self.clearAllFields()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,7 +158,7 @@ class FrmRevLookupWindow: NSWindow {
|
||||||
resultView.string = "\n" + "Loading…".localized
|
resultView.string = "\n" + "Loading…".localized
|
||||||
DispatchQueue.main.async { [weak self] in
|
DispatchQueue.main.async { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
updateResult(with: self.inputField.stringValue)
|
self.updateResult(with: self.inputField.stringValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue