NetNewsWire/Mac/MainWindow/OPML/ExportOPMLAccessoryViewController.swift
Brent Simmons 06b0e35739 Move Protocol declaration to top of ExportOPMLAccessoryViewController.swift. As critical API, it needs to be easy to spot.
Create separation extensions — one for protocol conformance, one for private methods — ExportOPMLController.

Make minor code formatting change: instead of { return } — which is hard to set a breakpoint on — move the return to its own line.

Remove an internal access qualifier, since internal is default and implied.
2019-10-23 22:00:14 -07:00

63 lines
1.6 KiB
Swift

//
// ExportOPMLAccessoryViewController.swift
// NetNewsWire
//
// Created by Nate Weaver on 2019-10-20.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import AppKit
import Account
protocol ExportOPMLAccessoryViewControllerDelegate: class {
func selectedAccountDidChange(_ accessoryViewController: ExportOPMLAccessoryViewController)
}
class ExportOPMLAccessoryViewController: NSViewController {
@IBOutlet weak var accountPopUpButton: NSPopUpButton!
weak var delegate: ExportOPMLAccessoryViewControllerDelegate?
var selectedAccount: Account? {
accountPopUpButton.selectedItem?.representedObject as? Account
}
init(delegate: ExportOPMLAccessoryViewControllerDelegate) {
super.init(nibName: "ExportOPMLAccessoryView", bundle: nil)
self.delegate = delegate
}
init() {
preconditionFailure("init() without delegate not implemented by design.")
}
required init?(coder: NSCoder) {
preconditionFailure("ExportOPMLAccessoryView.init(coder) not implemented by design.")
}
override func viewDidLoad() {
accountPopUpButton.removeAllItems()
let menu = NSMenu()
accountPopUpButton.menu = menu
for oneAccount in AccountManager.shared.sortedAccounts {
let oneMenuItem = NSMenuItem()
oneMenuItem.title = oneAccount.nameForDisplay
oneMenuItem.representedObject = oneAccount
menu.addItem(oneMenuItem)
if oneAccount.accountID == AppDefaults.exportOPMLAccountID {
accountPopUpButton.select(oneMenuItem)
}
}
}
@IBAction func accountSelected(_ popUpButton: NSPopUpButton) {
delegate!.selectedAccountDidChange(self)
}
}