Repo // Introducing Broadcaster for KVO operations.
This commit is contained in:
parent
a56b55125a
commit
cd33a21587
|
@ -0,0 +1,17 @@
|
||||||
|
// (c) 2011 and onwards The OpenVanilla Project (MIT License).
|
||||||
|
// All possible vChewing-specific modifications are of:
|
||||||
|
// (c) 2021 and onwards The vChewing Project (MIT-NTL License).
|
||||||
|
// ====================
|
||||||
|
// This code is released under the MIT license (SPDX-License-Identifier: MIT)
|
||||||
|
// ... with NTL restriction stating that:
|
||||||
|
// No trademark license is granted to use the trade names, trademarks, service
|
||||||
|
// marks, or product names of Contributor, except as required to fulfill notice
|
||||||
|
// requirements defined in MIT License.
|
||||||
|
|
||||||
|
import AppKit
|
||||||
|
|
||||||
|
@objcMembers public class Broadcaster: NSObject {
|
||||||
|
public static var shared = Broadcaster()
|
||||||
|
public dynamic var eventForReloadingPhraseEditor = UUID()
|
||||||
|
public dynamic var eventForReloadingRevLookupData = UUID()
|
||||||
|
}
|
|
@ -47,7 +47,7 @@ extension AppDelegate {
|
||||||
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) {
|
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) {
|
||||||
if #available(macOS 10.15, *) { FileObserveProject.shared.touch() }
|
if #available(macOS 10.15, *) { FileObserveProject.shared.touch() }
|
||||||
if PrefMgr.shared.phraseEditorAutoReloadExternalModifications {
|
if PrefMgr.shared.phraseEditorAutoReloadExternalModifications {
|
||||||
CtlPrefWindow.shared?.updatePhraseEditor()
|
Broadcaster.shared.eventForReloadingPhraseEditor = .init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -280,7 +280,7 @@ public extension LMMgr {
|
||||||
// by the current application itself, requiring additional manual loading process here.
|
// by the current application itself, requiring additional manual loading process here.
|
||||||
if #available(macOS 10.15, *) { FileObserveProject.shared.touch() }
|
if #available(macOS 10.15, *) { FileObserveProject.shared.touch() }
|
||||||
if PrefMgr.shared.phraseEditorAutoReloadExternalModifications {
|
if PrefMgr.shared.phraseEditorAutoReloadExternalModifications {
|
||||||
CtlPrefWindow.shared?.updatePhraseEditor()
|
Broadcaster.shared.eventForReloadingPhraseEditor = .init()
|
||||||
}
|
}
|
||||||
loadUserPhrasesData(type: .thePhrases)
|
loadUserPhrasesData(type: .thePhrases)
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,8 @@ class CtlPrefWindow: NSWindowController, NSWindowDelegate {
|
||||||
|
|
||||||
public static var shared: CtlPrefWindow?
|
public static var shared: CtlPrefWindow?
|
||||||
|
|
||||||
|
@objc var observation: NSKeyValueObservation?
|
||||||
|
|
||||||
static func show() {
|
static func show() {
|
||||||
let resetPhraseEditor: Bool = shared?.window == nil || !(shared?.window?.isVisible ?? false) || shared == nil
|
let resetPhraseEditor: Bool = shared?.window == nil || !(shared?.window?.isVisible ?? false) || shared == nil
|
||||||
if shared == nil { shared = CtlPrefWindow(windowNibName: "frmPrefWindow") }
|
if shared == nil { shared = CtlPrefWindow(windowNibName: "frmPrefWindow") }
|
||||||
|
@ -83,6 +85,10 @@ class CtlPrefWindow: NSWindowController, NSWindowDelegate {
|
||||||
super.windowDidLoad()
|
super.windowDidLoad()
|
||||||
window?.setPosition(vertical: .top, horizontal: .right, padding: 20)
|
window?.setPosition(vertical: .top, horizontal: .right, padding: 20)
|
||||||
|
|
||||||
|
observation = Broadcaster.shared.observe(\.eventForReloadingPhraseEditor, options: [.new]) { _, _ in
|
||||||
|
self.updatePhraseEditor()
|
||||||
|
}
|
||||||
|
|
||||||
chkFartSuppressor.isHidden = !Date.isTodayTheDate(from: 0401)
|
chkFartSuppressor.isHidden = !Date.isTodayTheDate(from: 0401)
|
||||||
chkFartSuppressor.isEnabled = !chkFartSuppressor.isHidden
|
chkFartSuppressor.isEnabled = !chkFartSuppressor.isHidden
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import LangModelAssembly
|
||||||
|
|
||||||
class CtlRevLookupWindow: NSWindowController, NSWindowDelegate {
|
class CtlRevLookupWindow: NSWindowController, NSWindowDelegate {
|
||||||
static var shared: CtlRevLookupWindow?
|
static var shared: CtlRevLookupWindow?
|
||||||
|
@objc var observation: NSKeyValueObservation?
|
||||||
|
|
||||||
static func show() {
|
static func show() {
|
||||||
if shared == nil { Self.shared = .init(window: FrmRevLookupWindow()) }
|
if shared == nil { Self.shared = .init(window: FrmRevLookupWindow()) }
|
||||||
|
@ -20,10 +21,16 @@ class CtlRevLookupWindow: NSWindowController, NSWindowDelegate {
|
||||||
window.setPosition(vertical: .bottom, horizontal: .right, padding: 20)
|
window.setPosition(vertical: .bottom, horizontal: .right, padding: 20)
|
||||||
window.orderFrontRegardless() // 逼著視窗往最前方顯示
|
window.orderFrontRegardless() // 逼著視窗往最前方顯示
|
||||||
window.level = .statusBar
|
window.level = .statusBar
|
||||||
window.titlebarAppearsTransparent = true
|
|
||||||
shared.showWindow(shared)
|
shared.showWindow(shared)
|
||||||
NSApp.popup()
|
NSApp.popup()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func windowDidLoad() {
|
||||||
|
super.windowDidLoad()
|
||||||
|
observation = Broadcaster.shared.observe(\.eventForReloadingRevLookupData, options: [.new]) { _, _ in
|
||||||
|
FrmRevLookupWindow.reloadData()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FrmRevLookupWindow: NSWindow {
|
class FrmRevLookupWindow: NSWindow {
|
||||||
|
|
Loading…
Reference in New Issue