diff --git a/Mac/Preferences/Accounts/AccountsAdd.xib b/Mac/Preferences/Accounts/AccountsAdd.xib index 6ed60e9fd..d95f1f842 100644 --- a/Mac/Preferences/Accounts/AccountsAdd.xib +++ b/Mac/Preferences/Accounts/AccountsAdd.xib @@ -1,7 +1,7 @@ - + - + @@ -13,19 +13,19 @@ - - + + - + - + - - + + @@ -33,7 +33,6 @@ - @@ -49,7 +48,7 @@ - + @@ -60,7 +59,7 @@ - + @@ -77,10 +76,24 @@ + + + + + @@ -109,6 +122,7 @@ + diff --git a/Mac/Preferences/Accounts/AccountsAddTableCellView.swift b/Mac/Preferences/Accounts/AccountsAddTableCellView.swift index cf8af80ec..fca762320 100644 --- a/Mac/Preferences/Accounts/AccountsAddTableCellView.swift +++ b/Mac/Preferences/Accounts/AccountsAddTableCellView.swift @@ -7,10 +7,23 @@ // import AppKit +import Account + +protocol AccountsAddTableCellViewDelegate: class { + func addAccount(_ accountType: AccountType) +} class AccountsAddTableCellView: NSTableCellView { + weak var delegate: AccountsAddTableCellViewDelegate? + var accountType: AccountType? + @IBOutlet weak var accountImageView: NSImageView? @IBOutlet weak var accountNameLabel: NSTextField? + @IBAction func pressed(_ sender: Any) { + guard let accountType = accountType else { return } + delegate?.addAccount(accountType) + } + } diff --git a/Mac/Preferences/Accounts/AccountsAddViewController.swift b/Mac/Preferences/Accounts/AccountsAddViewController.swift index 6d8f59f90..98f2e093a 100644 --- a/Mac/Preferences/Accounts/AccountsAddViewController.swift +++ b/Mac/Preferences/Accounts/AccountsAddViewController.swift @@ -61,6 +61,10 @@ extension AccountsAddViewController: NSTableViewDelegate { func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "Cell"), owner: nil) as? AccountsAddTableCellView { + + cell.accountType = addableAccountTypes[row] + cell.delegate = self + switch addableAccountTypes[row] { case .onMyMac: cell.accountNameLabel?.stringValue = Account.defaultLocalAccountName @@ -88,15 +92,16 @@ extension AccountsAddViewController: NSTableViewDelegate { } return nil } - - func tableViewSelectionDidChange(_ notification: Notification) { - let selectedRow = tableView.selectedRow - guard selectedRow != -1 else { - return - } +} - switch addableAccountTypes[selectedRow] { +// MARK: AccountsAddTableCellViewDelegate + +extension AccountsAddViewController: AccountsAddTableCellViewDelegate { + + func addAccount(_ accountType: AccountType) { + + switch accountType { case .onMyMac: let accountsAddLocalWindowController = AccountsAddLocalWindowController() accountsAddLocalWindowController.runSheetOnWindow(self.view.window!) @@ -134,8 +139,6 @@ extension AccountsAddViewController: NSTableViewDelegate { accountsAddWindowController = accountsNewsBlurWindowController } - tableView.selectRowIndexes([], byExtendingSelection: false) - } }