Forgo notifications entirely, and use a delegate instead
This commit is contained in:
parent
a762052264
commit
e7278017d9
|
@ -12,13 +12,15 @@ import Account
|
|||
class ExportOPMLAccessoryViewController: NSViewController {
|
||||
|
||||
@IBOutlet weak var accountPopUpButton: NSPopUpButton!
|
||||
weak var delegate: ExportOPMLAccessoryViewControllerDelegate?
|
||||
|
||||
var selectedAccount: Account? {
|
||||
accountPopUpButton.selectedItem?.representedObject as? Account
|
||||
}
|
||||
|
||||
init() {
|
||||
init(delegate: ExportOPMLAccessoryViewControllerDelegate) {
|
||||
super.init(nibName: "ExportOPMLAccessoryView", bundle: nil)
|
||||
self.delegate = delegate
|
||||
}
|
||||
|
||||
// MARK: - NSViewController
|
||||
|
@ -48,11 +50,10 @@ class ExportOPMLAccessoryViewController: NSViewController {
|
|||
}
|
||||
|
||||
@IBAction func accountSelected(_ popUpButton: NSPopUpButton) {
|
||||
NotificationCenter.default.post(name: .ExportOPMLSelectedAccountDidChange, object: self)
|
||||
delegate!.selectedAccountDidChange(self)
|
||||
}
|
||||
}
|
||||
|
||||
extension Notification.Name {
|
||||
static let ExportOPMLSelectedAccountDidChange = Notification.Name(rawValue: "SelectedAccountDidChange")
|
||||
|
||||
protocol ExportOPMLAccessoryViewControllerDelegate: class {
|
||||
func selectedAccountDidChange(_ accessoryViewController: ExportOPMLAccessoryViewController)
|
||||
}
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
import AppKit
|
||||
import Account
|
||||
|
||||
class ExportOPMLController {
|
||||
class ExportOPMLController: ExportOPMLAccessoryViewControllerDelegate {
|
||||
|
||||
weak var savePanel: NSSavePanel?
|
||||
|
||||
func runSheetOnWindow(_ hostWindow: NSWindow) {
|
||||
|
||||
let accessoryViewController = ExportOPMLAccessoryViewController()
|
||||
let accessoryViewController = ExportOPMLAccessoryViewController(delegate: self)
|
||||
let panel = NSSavePanel()
|
||||
panel.allowedFileTypes = ["opml"]
|
||||
panel.allowsOtherFileTypes = false
|
||||
|
@ -26,8 +26,6 @@ class ExportOPMLController {
|
|||
panel.isExtensionHidden = false
|
||||
panel.accessoryView = accessoryViewController.view
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(selectedAccountDidChange(_:)), name: .ExportOPMLSelectedAccountDidChange, object: accessoryViewController)
|
||||
|
||||
updateNameFieldStringValueIfAppropriate(savePanel: panel, from: accessoryViewController, force: true)
|
||||
|
||||
savePanel = panel
|
||||
|
@ -46,8 +44,6 @@ class ExportOPMLController {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -62,8 +58,8 @@ class ExportOPMLController {
|
|||
|
||||
}
|
||||
|
||||
@objc private func selectedAccountDidChange(_ notification: Notification) {
|
||||
if let savePanel = savePanel, let accessoryViewController = notification.object as? ExportOPMLAccessoryViewController {
|
||||
internal func selectedAccountDidChange(_ accessoryViewController: ExportOPMLAccessoryViewController) {
|
||||
if let savePanel = savePanel {
|
||||
self.updateNameFieldStringValueIfAppropriate(savePanel: savePanel, from: accessoryViewController)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue