From ba57a27a356fef712253d03b496ea23e344627c7 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Tue, 30 Apr 2019 06:38:18 -0500 Subject: [PATCH] Make local account display names changeable --- Frameworks/Account/Account.swift | 1 + Mac/Base.lproj/Preferences.storyboard | 24 +++++++- .../AccountsPreferencesViewController.swift | 56 +++++++++++++++---- .../Accounts/AccountsTableCellView.swift | 14 ----- .../Accounts/Local/LocalAccount.xib | 12 +++- ...ocalAccountPreferencesViewController.swift | 21 ++++++- NetNewsWire.xcodeproj/project.pbxproj | 4 -- 7 files changed, 96 insertions(+), 36 deletions(-) delete mode 100644 Mac/Preferences/Accounts/AccountsTableCellView.swift diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 312d1f763..54c31e32b 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -63,6 +63,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, let currentNameForDisplay = nameForDisplay if newValue != settings.name { settings.name = newValue + settingsDirty = true if currentNameForDisplay != nameForDisplay { postDisplayNameDidChangeNotification() } diff --git a/Mac/Base.lproj/Preferences.storyboard b/Mac/Base.lproj/Preferences.storyboard index 88683e2cd..7afb8b430 100644 --- a/Mac/Base.lproj/Preferences.storyboard +++ b/Mac/Base.lproj/Preferences.storyboard @@ -1,7 +1,7 @@ - + - + @@ -283,9 +283,23 @@ - + + + + + + + + + + + + + + + @@ -360,6 +374,10 @@ + + + + diff --git a/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift b/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift index 68ff8b66b..4c273ae4b 100644 --- a/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift +++ b/Mac/Preferences/Accounts/AccountsPreferencesViewController.swift @@ -11,11 +11,30 @@ import Account final class AccountsPreferencesViewController: NSViewController { + @IBOutlet weak var tableView: NSTableView! + @IBOutlet weak var detailView: NSView! + private var sortedAccounts = [Account]() + override func viewDidLoad() { + super.viewDidLoad() + NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil) + } + override func viewWillAppear() { updateSortedAccounts() + tableView.reloadData() } + + override func viewWillDisappear() { + super.viewWillDisappear() + resetContainerView() + } + + @objc func displayNameDidChange(_ note: Notification) { + tableView.reloadData() + } + } // MARK: - NSTableViewDataSource @@ -38,23 +57,30 @@ extension AccountsPreferencesViewController: NSTableViewDelegate { private static let cellIdentifier = NSUserInterfaceItemIdentifier(rawValue: "AccountCell") func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { - - func configure(_ cell: AccountsTableCellView) { - } - - if let cell = tableView.makeView(withIdentifier: AccountsPreferencesViewController.cellIdentifier, owner: nil) as? AccountsTableCellView { - configure(cell) + if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "Cell"), owner: nil) as? NSTableCellView { + cell.textField?.stringValue = sortedAccounts[row].nameForDisplay return cell } - - let cell = AccountsTableCellView() - cell.identifier = AccountsPreferencesViewController.cellIdentifier - configure(cell) - return cell + return nil } func tableViewSelectionDidChange(_ notification: Notification) { + + let selectedRow = tableView.selectedRow + guard selectedRow != -1 else { + return + } + + let account = sortedAccounts[selectedRow] + + let controller = LocalAccountPreferencesViewController(account: account) + addChild(controller) + controller.view.translatesAutoresizingMaskIntoConstraints = false + detailView.addSubview(controller.view) + detailView.rs_addFullSizeConstraints(forSubview: controller.view) + } + } // MARK: - Private @@ -64,4 +90,12 @@ private extension AccountsPreferencesViewController { func updateSortedAccounts() { sortedAccounts = AccountManager.shared.sortedAccounts } + + func resetContainerView() { + if let controller = children.first { + children.removeAll() + controller.view.removeFromSuperview() + } + } + } diff --git a/Mac/Preferences/Accounts/AccountsTableCellView.swift b/Mac/Preferences/Accounts/AccountsTableCellView.swift deleted file mode 100644 index e2bd57a36..000000000 --- a/Mac/Preferences/Accounts/AccountsTableCellView.swift +++ /dev/null @@ -1,14 +0,0 @@ -// -// AccountsTableCellView.swift -// NetNewsWire -// -// Created by Brent Simmons on 3/23/19. -// Copyright © 2019 Ranchero Software. All rights reserved. -// - -import AppKit - -final class AccountsTableCellView: NSTableCellView { - - -} diff --git a/Mac/Preferences/Accounts/Local/LocalAccount.xib b/Mac/Preferences/Accounts/Local/LocalAccount.xib index f4dea2b98..aaf4e73fb 100644 --- a/Mac/Preferences/Accounts/Local/LocalAccount.xib +++ b/Mac/Preferences/Accounts/Local/LocalAccount.xib @@ -1,11 +1,17 @@ - + - + - + + + + + + + diff --git a/Mac/Preferences/Accounts/Local/LocalAccountPreferencesViewController.swift b/Mac/Preferences/Accounts/Local/LocalAccountPreferencesViewController.swift index 1e9dd955b..ecbcd3820 100644 --- a/Mac/Preferences/Accounts/Local/LocalAccountPreferencesViewController.swift +++ b/Mac/Preferences/Accounts/Local/LocalAccountPreferencesViewController.swift @@ -9,8 +9,11 @@ import AppKit import Account -final class LocalAccountPreferencesViewController: NSViewController { +final class LocalAccountPreferencesViewController: NSViewController, NSTextFieldDelegate { + @IBOutlet weak var typeLabel: NSTextField! + @IBOutlet weak var nameTextField: NSTextField! + private weak var account: Account? init(account: Account) { @@ -21,4 +24,20 @@ final class LocalAccountPreferencesViewController: NSViewController { public required init?(coder: NSCoder) { super.init(coder: coder) } + + override func viewDidLoad() { + super.viewDidLoad() + nameTextField.delegate = self + typeLabel.stringValue = account?.defaultName ?? "" + nameTextField.stringValue = account?.name ?? "" + } + + func controlTextDidEndEditing(_ obj: Notification) { + if !nameTextField.stringValue.isEmpty { + account?.name = nameTextField.stringValue + } else { + account?.name = nil + } + } + } diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index b4eb80d91..4ea09c8c3 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -240,7 +240,6 @@ 84C9FC7C22629E1200D921D6 /* AccountsPreferencesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C9FC7222629E1200D921D6 /* AccountsPreferencesViewController.swift */; }; 84C9FC7D22629E1200D921D6 /* LocalAccount.xib in Resources */ = {isa = PBXBuildFile; fileRef = 84C9FC7422629E1200D921D6 /* LocalAccount.xib */; }; 84C9FC7E22629E1200D921D6 /* LocalAccountPreferencesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C9FC7522629E1200D921D6 /* LocalAccountPreferencesViewController.swift */; }; - 84C9FC7F22629E1200D921D6 /* AccountsTableCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C9FC7622629E1200D921D6 /* AccountsTableCellView.swift */; }; 84C9FC8222629E4800D921D6 /* Preferences.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 84C9FC8022629E4800D921D6 /* Preferences.storyboard */; }; 84C9FC8C22629E8F00D921D6 /* KeyboardShortcuts.html in Resources */ = {isa = PBXBuildFile; fileRef = 84C9FC8722629E8F00D921D6 /* KeyboardShortcuts.html */; }; 84C9FC8D22629E8F00D921D6 /* EvergreenLarge.png in Resources */ = {isa = PBXBuildFile; fileRef = 84C9FC8822629E8F00D921D6 /* EvergreenLarge.png */; }; @@ -808,7 +807,6 @@ 84C9FC7222629E1200D921D6 /* AccountsPreferencesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountsPreferencesViewController.swift; sourceTree = ""; }; 84C9FC7422629E1200D921D6 /* LocalAccount.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = LocalAccount.xib; sourceTree = ""; }; 84C9FC7522629E1200D921D6 /* LocalAccountPreferencesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalAccountPreferencesViewController.swift; sourceTree = ""; }; - 84C9FC7622629E1200D921D6 /* AccountsTableCellView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountsTableCellView.swift; sourceTree = ""; }; 84C9FC8122629E4800D921D6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Mac/Base.lproj/Preferences.storyboard; sourceTree = SOURCE_ROOT; }; 84C9FC8722629E8F00D921D6 /* KeyboardShortcuts.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = KeyboardShortcuts.html; sourceTree = ""; }; 84C9FC8822629E8F00D921D6 /* EvergreenLarge.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = EvergreenLarge.png; sourceTree = ""; }; @@ -1562,7 +1560,6 @@ 84C9FC7122629E1200D921D6 /* AccountsControlsBackgroundView.swift */, 84C9FC7222629E1200D921D6 /* AccountsPreferencesViewController.swift */, 84C9FC7322629E1200D921D6 /* Local */, - 84C9FC7622629E1200D921D6 /* AccountsTableCellView.swift */, ); path = Accounts; sourceTree = ""; @@ -2396,7 +2393,6 @@ 84AD1EAA2031617300BC20B7 /* FolderPasteboardWriter.swift in Sources */, 84AD1EBC2032AF5C00BC20B7 /* SidebarOutlineDataSource.swift in Sources */, 845A29241FC9255E007B49E3 /* SidebarCellAppearance.swift in Sources */, - 84C9FC7F22629E1200D921D6 /* AccountsTableCellView.swift in Sources */, 84F3EE1620DEC97E003FADEB /* FeedFinder.swift in Sources */, 845EE7B11FC2366500854A1F /* StarredFeedDelegate.swift in Sources */, 848F6AE51FC29CFB002D422E /* FaviconDownloader.swift in Sources */,