Don't use block-based notification observing

This commit is contained in:
Nate Weaver 2019-10-21 16:31:33 -05:00
parent 7e98869080
commit a762052264
1 changed files with 13 additions and 5 deletions

View File

@ -9,7 +9,9 @@
import AppKit
import Account
struct ExportOPMLController {
class ExportOPMLController {
weak var savePanel: NSSavePanel?
func runSheetOnWindow(_ hostWindow: NSWindow) {
@ -24,11 +26,11 @@ struct ExportOPMLController {
panel.isExtensionHidden = false
panel.accessoryView = accessoryViewController.view
let observer = NotificationCenter.default.addObserver(forName: .ExportOPMLSelectedAccountDidChange, object: nil, queue: OperationQueue.main) { notification in
self.updateNameFieldStringValueIfAppropriate(savePanel: panel, from: accessoryViewController)
}
NotificationCenter.default.addObserver(self, selector: #selector(selectedAccountDidChange(_:)), name: .ExportOPMLSelectedAccountDidChange, object: accessoryViewController)
updateNameFieldStringValueIfAppropriate(savePanel: panel, from: accessoryViewController, force: true)
savePanel = panel
panel.beginSheetModal(for: hostWindow) { result in
if result == NSApplication.ModalResponse.OK, let url = panel.url {
@ -45,7 +47,7 @@ struct ExportOPMLController {
}
}
NotificationCenter.default.removeObserver(observer)
NotificationCenter.default.removeObserver(self)
}
}
@ -59,4 +61,10 @@ struct ExportOPMLController {
panel.nameFieldStringValue = "Subscriptions-\(accountName).opml"
}
@objc private func selectedAccountDidChange(_ notification: Notification) {
if let savePanel = savePanel, let accessoryViewController = notification.object as? ExportOPMLAccessoryViewController {
self.updateNameFieldStringValueIfAppropriate(savePanel: savePanel, from: accessoryViewController)
}
}
}