diff --git a/Mac/MainWindow/OPML/ExportOPMLAccessoryViewController.swift b/Mac/MainWindow/OPML/ExportOPMLAccessoryViewController.swift index 639d88ec6..6e94a5206 100644 --- a/Mac/MainWindow/OPML/ExportOPMLAccessoryViewController.swift +++ b/Mac/MainWindow/OPML/ExportOPMLAccessoryViewController.swift @@ -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) } diff --git a/Mac/MainWindow/OPML/ExportOPMLController.swift b/Mac/MainWindow/OPML/ExportOPMLController.swift index 2888ff986..87530df3a 100644 --- a/Mac/MainWindow/OPML/ExportOPMLController.swift +++ b/Mac/MainWindow/OPML/ExportOPMLController.swift @@ -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) } }