Add multiple local accounts

This commit is contained in:
Maurice Parker 2019-05-01 12:37:13 -05:00
parent 7cc4475596
commit f4180424e1
11 changed files with 233 additions and 23 deletions

View File

@ -104,8 +104,10 @@ public final class AccountManager: UnreadCountProvider {
let account = Account(dataFolder: accountFolder, type: type, accountID: accountID)!
accountsDictionary[accountID] = account
return account
NotificationCenter.default.post(name: .AccountsDidChangeNotification, object: self)
return account
}
public func existingAccount(with accountID: String) -> Account? {

View File

@ -27,15 +27,11 @@ struct AppImages {
}()
static var accountLocal: RSImage! = {
let image = RSImage(named: "accountLocal")
image?.isTemplate = true
return image
return RSImage(named: "accountLocal")
}()
static var accountFeedbin: RSImage! = {
let image = RSImage(named: "accountFeedbin")
image?.isTemplate = true
return image
return RSImage(named: "accountFeedbin")
}()
}

View File

@ -53,6 +53,7 @@ protocol SidebarDelegate: class {
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(containerChildrenDidChange(_:)), name: .ChildrenDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(accountsDidChangeNotification(_:)), name: .AccountsDidChangeNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(userDidAddFeed(_:)), name: .UserDidAddFeed, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidPerform(_:)), name: .BatchUpdateDidPerform, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil)
@ -110,6 +111,10 @@ protocol SidebarDelegate: class {
rebuildTreeAndRestoreSelection()
}
@objc func accountsDidChangeNotification(_ notification: Notification) {
rebuildTreeAndRestoreSelection()
}
@objc func batchUpdateDidPerform(_ notification: Notification) {
rebuildTreeAndRestoreSelection()
}

View File

@ -0,0 +1,135 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="AccountsAddLocalWindowController" customModule="NetNewsWire" customModuleProvider="target">
<connections>
<outlet property="nameTextField" destination="f9b-FM-i8Q" id="TJl-Uc-PNg"/>
<outlet property="window" destination="QvC-M9-y7g" id="ENN-6Q-J5m"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="QvC-M9-y7g">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="358" height="183"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
<view key="contentView" wantsLayer="YES" id="EiT-Mj-1SZ">
<rect key="frame" x="0.0" y="0.0" width="358" height="183"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView distribution="fill" orientation="horizontal" alignment="bottom" spacing="19" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uDK-ji-zlT">
<rect key="frame" x="73" y="128" width="213" height="39"/>
<subviews>
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="ySx-qg-WbT">
<rect key="frame" x="0.0" y="0.0" width="36" height="36"/>
<constraints>
<constraint firstAttribute="width" constant="36" id="BKI-n8-fbR"/>
<constraint firstAttribute="height" constant="36" id="NLk-V3-hn9"/>
</constraints>
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="accountLocal" id="9RZ-J3-ioX"/>
</imageView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="80D-3X-rL2">
<rect key="frame" x="53" y="0.0" width="162" height="39"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="On My Mac" id="1d2-Mx-TKe">
<font key="font" metaFont="system" size="32"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<visibilityPriorities>
<integer value="1000"/>
<integer value="1000"/>
</visibilityPriorities>
<customSpacing>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
<stackView distribution="fill" orientation="horizontal" alignment="firstBaseline" spacing="18" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" translatesAutoresizingMaskIntoConstraints="NO" id="6Q7-nI-h5u">
<rect key="frame" x="80" y="57" width="198" height="40"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="MWg-UL-xtj">
<rect key="frame" x="-2" y="21" width="44" height="17"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Name:" id="AVh-ns-LEN">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="f9b-FM-i8Q">
<rect key="frame" x="58" y="18" width="140" height="22"/>
<constraints>
<constraint firstAttribute="width" constant="140" id="cdf-tS-vno"/>
</constraints>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" id="Y12-ua-Bj8">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<visibilityPriorities>
<integer value="1000"/>
<integer value="1000"/>
</visibilityPriorities>
<customSpacing>
<real value="3.4028234663852886e+38"/>
<real value="3.4028234663852886e+38"/>
</customSpacing>
</stackView>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="xqo-gP-MPl">
<rect key="frame" x="263" y="13" width="81" height="32"/>
<buttonCell key="cell" type="push" title="Create" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="oih-6c-KbS">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent" base64-UTF8="YES">
DQ
</string>
</buttonCell>
<connections>
<action selector="create:" target="-2" id="jgg-n6-VVy"/>
</connections>
</button>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9eG-vV-s8c">
<rect key="frame" x="182" y="13" width="82" height="32"/>
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="iVd-bO-4LN">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent" base64-UTF8="YES">
Gw
</string>
</buttonCell>
<connections>
<action selector="cancel:" target="-2" id="uDi-hX-dXu"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="6Q7-nI-h5u" firstAttribute="top" secondItem="80D-3X-rL2" secondAttribute="bottom" constant="31" id="3Sa-lr-BqF"/>
<constraint firstItem="9eG-vV-s8c" firstAttribute="centerY" secondItem="xqo-gP-MPl" secondAttribute="centerY" id="DLC-C8-enC"/>
<constraint firstAttribute="bottom" secondItem="xqo-gP-MPl" secondAttribute="bottom" constant="20" id="HgX-ud-184"/>
<constraint firstItem="6Q7-nI-h5u" firstAttribute="centerX" secondItem="EiT-Mj-1SZ" secondAttribute="centerX" id="KYO-G6-21s"/>
<constraint firstItem="xqo-gP-MPl" firstAttribute="top" secondItem="6Q7-nI-h5u" secondAttribute="bottom" constant="16" id="avP-tb-lGq"/>
<constraint firstItem="80D-3X-rL2" firstAttribute="top" secondItem="EiT-Mj-1SZ" secondAttribute="top" constant="16" id="h30-eN-6VF"/>
<constraint firstItem="9eG-vV-s8c" firstAttribute="top" secondItem="f9b-FM-i8Q" secondAttribute="bottom" constant="34" id="ikz-I1-O2L"/>
<constraint firstItem="xqo-gP-MPl" firstAttribute="leading" secondItem="9eG-vV-s8c" secondAttribute="trailing" constant="11" id="p6M-6b-ybu"/>
<constraint firstItem="uDK-ji-zlT" firstAttribute="centerX" secondItem="EiT-Mj-1SZ" secondAttribute="centerX" id="uXu-yF-PBG"/>
<constraint firstAttribute="trailing" secondItem="xqo-gP-MPl" secondAttribute="trailing" constant="20" id="z4O-vd-ear"/>
</constraints>
</view>
<connections>
<outlet property="delegate" destination="-2" id="hpu-h7-p4Z"/>
</connections>
<point key="canvasLocation" x="79" y="103.5"/>
</window>
</objects>
<resources>
<image name="accountLocal" width="78" height="98"/>
</resources>
</document>

View File

@ -0,0 +1,43 @@
//
// AccountsAddLocalWindowController.swift
// NetNewsWire
//
// Created by Maurice Parker on 5/1/19.
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import AppKit
import Account
class AccountsAddLocalWindowController: NSWindowController {
@IBOutlet weak var nameTextField: NSTextField!
private weak var hostWindow: NSWindow?
convenience init() {
self.init(windowNibName: NSNib.Name("AccountsAddLocal"))
}
// MARK: API
func runSheetOnWindow(_ hostWindow: NSWindow) {
self.hostWindow = hostWindow
hostWindow.beginSheet(window!)
}
// MARK: Actions
@IBAction func cancel(_ sender: Any) {
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.cancel)
}
@IBAction func create(_ sender: Any) {
let account = AccountManager.shared.createAccount(type: .onMyMac)
if !nameTextField.stringValue.isEmpty {
account.name = nameTextField.stringValue
}
hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK)
}
}

View File

@ -6,7 +6,7 @@
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import Cocoa
import AppKit
class AccountsAddTableCellView: NSTableCellView {

View File

@ -6,12 +6,14 @@
// Copyright © 2019 Ranchero Software. All rights reserved.
//
import Cocoa
import AppKit
class AccountsAddViewController: NSViewController {
@IBOutlet weak var tableView: NSTableView!
private var accountsAddWindowController: NSWindowController?
init() {
super.init(nibName: "AccountsAdd", bundle: nil)
}
@ -21,11 +23,14 @@ class AccountsAddViewController: NSViewController {
}
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
}
}
}
// MARK: - NSTableViewDataSource
@ -52,7 +57,7 @@ extension AccountsAddViewController: NSTableViewDelegate {
if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "Cell"), owner: nil) as? AccountsAddTableCellView {
switch row {
case 0:
cell.accountNameLabel?.stringValue = NSLocalizedString("Local", comment: "Local")
cell.accountNameLabel?.stringValue = NSLocalizedString("On My Mac", comment: "Local")
cell.accountImageView?.image = AppImages.accountLocal
case 1:
cell.accountNameLabel?.stringValue = NSLocalizedString("Feedbin", comment: "Feedbin")
@ -67,18 +72,21 @@ extension AccountsAddViewController: NSTableViewDelegate {
func tableViewSelectionDidChange(_ notification: Notification) {
// let selectedRow = tableView.selectedRow
// guard selectedRow != -1 else {
// return
// }
//
// let account = sortedAccounts[selectedRow]
//
// let controller = AccountDetailViewController(account: account)
// addChild(controller)
// controller.view.translatesAutoresizingMaskIntoConstraints = false
// detailView.addSubview(controller.view)
// detailView.rs_addFullSizeConstraints(forSubview: controller.view)
let selectedRow = tableView.selectedRow
guard selectedRow != -1 else {
return
}
switch selectedRow {
case 0:
let accountsAddLocalWindowController = AccountsAddLocalWindowController()
accountsAddLocalWindowController.runSheetOnWindow(self.view.window!)
accountsAddWindowController = accountsAddLocalWindowController
default:
break
}
tableView.selectRowIndexes([], byExtendingSelection: false)
}

View File

@ -24,6 +24,8 @@ final class AccountsPreferencesViewController: NSViewController {
tableView.dataSource = self
NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(accountsDidChangeNotification(_:)), name: .AccountsDidChangeNotification, object: nil)
showController(AccountsAddViewController())
}
@ -41,6 +43,11 @@ final class AccountsPreferencesViewController: NSViewController {
tableView.reloadData()
}
@objc func accountsDidChangeNotification(_ note: Notification) {
updateSortedAccounts()
tableView.reloadData()
}
}
// MARK: - NSTableViewDataSource

View File

@ -8,5 +8,8 @@
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}

View File

@ -8,5 +8,8 @@
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}

View File

@ -18,6 +18,8 @@
512E09352268B25900BDCFDD /* UISplitViewController-Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 512E092B2268B25500BDCFDD /* UISplitViewController-Extensions.swift */; };
512E094D2268B8AB00BDCFDD /* DeleteCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B99C9C1FAE83C600ECDEDB /* DeleteCommand.swift */; };
5144EA2F2279FAB600D19003 /* AccountsDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5144EA2E2279FAB600D19003 /* AccountsDetailViewController.swift */; };
5144EA362279FC3D00D19003 /* AccountsAddLocal.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5144EA352279FC3D00D19003 /* AccountsAddLocal.xib */; };
5144EA382279FC6200D19003 /* AccountsAddLocalWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5144EA372279FC6200D19003 /* AccountsAddLocalWindowController.swift */; };
5183CCD0226E1E880010922C /* NonIntrinsicLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCCF226E1E880010922C /* NonIntrinsicLabel.swift */; };
5183CCDA226E31A50010922C /* NonIntrinsicImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCD9226E31A50010922C /* NonIntrinsicImageView.swift */; };
5183CCDD226F1F5C0010922C /* NavigationProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5183CCDC226F1F5C0010922C /* NavigationProgressView.swift */; };
@ -638,6 +640,8 @@
512E08F722688F7C00BDCFDD /* MasterFeedTableViewSectionHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MasterFeedTableViewSectionHeader.swift; sourceTree = "<group>"; };
512E092B2268B25500BDCFDD /* UISplitViewController-Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UISplitViewController-Extensions.swift"; sourceTree = "<group>"; };
5144EA2E2279FAB600D19003 /* AccountsDetailViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountsDetailViewController.swift; sourceTree = "<group>"; };
5144EA352279FC3D00D19003 /* AccountsAddLocal.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AccountsAddLocal.xib; sourceTree = "<group>"; };
5144EA372279FC6200D19003 /* AccountsAddLocalWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountsAddLocalWindowController.swift; sourceTree = "<group>"; };
5183CCCF226E1E880010922C /* NonIntrinsicLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonIntrinsicLabel.swift; sourceTree = "<group>"; };
5183CCD9226E31A50010922C /* NonIntrinsicImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonIntrinsicImageView.swift; sourceTree = "<group>"; };
5183CCDC226F1F5C0010922C /* NavigationProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationProgressView.swift; sourceTree = "<group>"; };
@ -1570,6 +1574,8 @@
51EF0F912279CA620050506E /* AccountsAddTableCellView.swift */,
84C9FC7422629E1200D921D6 /* AccountsDetail.xib */,
5144EA2E2279FAB600D19003 /* AccountsDetailViewController.swift */,
5144EA352279FC3D00D19003 /* AccountsAddLocal.xib */,
5144EA372279FC6200D19003 /* AccountsAddLocalWindowController.swift */,
);
path = Accounts;
sourceTree = "<group>";
@ -2165,6 +2171,7 @@
51EF0F8E2279C9260050506E /* AccountsAdd.xib in Resources */,
84C9FC8F22629E8F00D921D6 /* NetNewsWire.sdef in Resources */,
84C9FC7D22629E1200D921D6 /* AccountsDetail.xib in Resources */,
5144EA362279FC3D00D19003 /* AccountsAddLocal.xib in Resources */,
84C9FC8C22629E8F00D921D6 /* KeyboardShortcuts.html in Resources */,
844B5B691FEA20DF00C7C76A /* SidebarKeyboardShortcuts.plist in Resources */,
84A3EE5F223B667F00557320 /* DefaultFeeds.opml in Resources */,
@ -2392,6 +2399,7 @@
84E185C3203BB12600F69BFA /* MultilineTextFieldSizer.swift in Sources */,
8477ACBE22238E9500DF7F37 /* SearchFeedDelegate.swift in Sources */,
8472058120142E8900AD578B /* FeedInspectorViewController.swift in Sources */,
5144EA382279FC6200D19003 /* AccountsAddLocalWindowController.swift in Sources */,
84AD1EAA2031617300BC20B7 /* FolderPasteboardWriter.swift in Sources */,
84AD1EBC2032AF5C00BC20B7 /* SidebarOutlineDataSource.swift in Sources */,
845A29241FC9255E007B49E3 /* SidebarCellAppearance.swift in Sources */,