NetNewsWire/Mac/Preferences/Accounts/AccountsDetailViewControlle...

109 lines
3.4 KiB
Swift
Raw Normal View History

//
// AccountsDetailViewController.swift
// NetNewsWire
//
// Created by Brent Simmons on 3/20/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import AppKit
import Account
final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate {
@IBOutlet weak var typeLabel: NSTextField!
@IBOutlet weak var nameTextField: NSTextField!
2019-05-02 12:41:44 +02:00
@IBOutlet weak var activeButton: NSButtonCell!
@IBOutlet weak var limitationsAndSolutionsRow: NSGridRow!
@IBOutlet weak var limitationsAndSolutionsTextField: NSTextField!
2019-05-04 23:10:58 +02:00
@IBOutlet weak var credentialsButton: NSButton!
2019-05-04 23:10:58 +02:00
private var accountsWindowController: NSWindowController?
private var account: Account?
init(account: Account) {
super.init(nibName: "AccountsDetail", bundle: nil)
self.account = account
}
public required init?(coder: NSCoder) {
super.init(coder: coder)
}
private var hidesCredentialsButton: Bool {
guard let account = account else {
return true
}
switch account.type {
case .onMyMac, .cloudKit, .feedly:
return true
default:
return false
}
}
override func viewDidLoad() {
super.viewDidLoad()
2019-05-04 23:10:58 +02:00
nameTextField.delegate = self
typeLabel.stringValue = account?.defaultName ?? ""
nameTextField.stringValue = account?.name ?? ""
2019-05-02 12:41:44 +02:00
activeButton.state = account?.isActive ?? false ? .on : .off
if account?.type == .cloudKit {
let attrString = NSAttributedString(linkText: CloudKitWebDocumentation.limitationsAndSolutionsText, linkURL: CloudKitWebDocumentation.limitationsAndSolutionsURL)
limitationsAndSolutionsTextField.attributedStringValue = attrString
} else {
limitationsAndSolutionsRow.isHidden = true
}
credentialsButton.isHidden = hidesCredentialsButton
}
func controlTextDidEndEditing(_ obj: Notification) {
if !nameTextField.stringValue.isEmpty {
account?.name = nameTextField.stringValue
} else {
account?.name = nil
}
}
2019-05-02 12:41:44 +02:00
@IBAction func active(_ sender: NSButtonCell) {
account?.isActive = sender.state == .on ? true : false
}
2019-05-04 23:10:58 +02:00
@IBAction func credentials(_ sender: Any) {
guard let account = account else { return }
switch account.type {
case .feedbin:
let accountsFeedbinWindowController = AccountsFeedbinWindowController()
accountsFeedbinWindowController.account = account
accountsFeedbinWindowController.runSheetOnWindow(self.view.window!)
accountsWindowController = accountsFeedbinWindowController
case .inoreader, .bazQux, .theOldReader, .freshRSS:
let accountsReaderAPIWindowController = AccountsReaderAPIWindowController()
accountsReaderAPIWindowController.accountType = account.type
accountsReaderAPIWindowController.account = account
accountsReaderAPIWindowController.runSheetOnWindow(self.view.window!)
accountsWindowController = accountsReaderAPIWindowController
break
case .feedWrangler:
let accountsFeedWranglerWindowController = AccountsFeedWranglerWindowController()
accountsFeedWranglerWindowController.account = account
accountsFeedWranglerWindowController.runSheetOnWindow(self.view.window!)
accountsWindowController = accountsFeedWranglerWindowController
case .newsBlur:
let accountsNewsBlurWindowController = AccountsNewsBlurWindowController()
accountsNewsBlurWindowController.account = account
accountsNewsBlurWindowController.runSheetOnWindow(self.view.window!)
accountsWindowController = accountsNewsBlurWindowController
2019-05-04 23:10:58 +02:00
default:
break
}
}
}