Move accounts menu setup in a separate function

This commit is contained in:
Ivan Grachyov 2021-07-17 18:16:56 +03:00
parent 70d9090abb
commit f734e658a7

View File

@ -34,13 +34,7 @@ class AccountsListViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
let menu = NSMenu()
menu.delegate = self
menu.addItem(NSMenuItem(title: "Copy address", action: #selector(didClickCopyAddress(_:)), keyEquivalent: ""))
menu.addItem(.separator())
menu.addItem(NSMenuItem(title: "Show private key", action: #selector(didClickExportAccount(_:)), keyEquivalent: "")) // TODO: show different texts for secret words export
menu.addItem(NSMenuItem(title: "Remove account", action: #selector(didClickRemoveAccount(_:)), keyEquivalent: ""))
tableView.menu = menu
setupAccountsMenu()
if accounts.isEmpty {
reloadAccounts()
@ -50,6 +44,16 @@ class AccountsListViewController: NSViewController {
NotificationCenter.default.addObserver(self, selector: #selector(didBecomeActive), name: NSApplication.didBecomeActiveNotification, object: nil)
}
private func setupAccountsMenu() {
let menu = NSMenu()
menu.delegate = self
menu.addItem(NSMenuItem(title: "Copy address", action: #selector(didClickCopyAddress(_:)), keyEquivalent: ""))
menu.addItem(.separator())
menu.addItem(NSMenuItem(title: "Show private key", action: #selector(didClickExportAccount(_:)), keyEquivalent: "")) // TODO: show different texts for secret words export
menu.addItem(NSMenuItem(title: "Remove account", action: #selector(didClickRemoveAccount(_:)), keyEquivalent: ""))
tableView.menu = menu
}
private func reloadAccounts() {
accounts = AccountsService.getAccounts()
}