Implement account state UI

This commit is contained in:
Maurice Parker 2019-05-02 05:41:44 -05:00
parent f5523dd610
commit 747079157b
4 changed files with 35 additions and 1 deletions

View File

@ -22,7 +22,7 @@ public extension Notification.Name {
static let AccountRefreshDidFinish = Notification.Name(rawValue: "AccountRefreshDidFinish")
static let AccountRefreshProgressDidChange = Notification.Name(rawValue: "AccountRefreshProgressDidChange")
static let AccountDidDownloadArticles = Notification.Name(rawValue: "AccountDidDownloadArticles")
static let AccountStateDidChange = Notification.Name(rawValue: "AccountStateDidChange")
static let StatusesDidChange = Notification.Name(rawValue: "StatusesDidChange")
}
@ -71,6 +71,19 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
}
}
public let defaultName: String
public var isActive: Bool {
get {
return settings.isActive
}
set {
if newValue != settings.isActive {
settings.isActive = newValue
settingsDirty = true
NotificationCenter.default.post(name: .AccountStateDidChange, object: self, userInfo: nil)
}
}
}
public var topLevelFeeds = Set<Feed>()
public var folders: Set<Folder>? = Set<Folder>()

View File

@ -11,4 +11,6 @@ import Foundation
final class AccountSettings: Codable {
var name: String?
var isActive: Bool = true
}

View File

@ -7,6 +7,7 @@
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="AccountsDetailViewController" customModule="NetNewsWire" customModuleProvider="target">
<connections>
<outlet property="activeButton" destination="wxB-dX-nGt" id="ALS-GI-sb5"/>
<outlet property="nameTextField" destination="TT0-Kf-YTC" id="oMG-jn-Qn0"/>
<outlet property="typeLabel" destination="XYX-iz-hnq" id="SKM-et-3h3"/>
<outlet property="view" destination="3ki-rg-6yb" id="ttM-4E-OLN"/>
@ -56,8 +57,20 @@
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="mgt-uY-fuq">
<rect key="frame" x="66" y="123" width="60" height="18"/>
<buttonCell key="cell" type="check" title="Active" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="wxB-dX-nGt">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
<connections>
<action selector="active:" target="-2" id="XgX-JM-UyU"/>
</connections>
</buttonCell>
</button>
</subviews>
<constraints>
<constraint firstItem="mgt-uY-fuq" firstAttribute="leading" secondItem="TT0-Kf-YTC" secondAttribute="leading" id="04V-YD-UZ5"/>
<constraint firstItem="mgt-uY-fuq" firstAttribute="top" secondItem="TT0-Kf-YTC" secondAttribute="bottom" constant="8" symbolic="YES" id="5Kn-79-8tn"/>
<constraint firstItem="XYX-iz-hnq" firstAttribute="firstBaseline" secondItem="jiQ-KJ-SS0" secondAttribute="firstBaseline" id="8ew-wx-9n3"/>
<constraint firstItem="XYX-iz-hnq" firstAttribute="leading" secondItem="jiQ-KJ-SS0" secondAttribute="trailing" constant="8" symbolic="YES" id="NsF-th-Tqq"/>
<constraint firstItem="TT0-Kf-YTC" firstAttribute="leading" secondItem="XYX-iz-hnq" secondAttribute="leading" id="Xqo-JT-9KG"/>

View File

@ -13,6 +13,7 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
@IBOutlet weak var typeLabel: NSTextField!
@IBOutlet weak var nameTextField: NSTextField!
@IBOutlet weak var activeButton: NSButtonCell!
private weak var account: Account?
@ -30,6 +31,7 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
nameTextField.delegate = self
typeLabel.stringValue = account?.defaultName ?? ""
nameTextField.stringValue = account?.name ?? ""
activeButton.state = account?.isActive ?? false ? .on : .off
}
func controlTextDidEndEditing(_ obj: Notification) {
@ -40,4 +42,8 @@ final class AccountsDetailViewController: NSViewController, NSTextFieldDelegate
}
}
@IBAction func active(_ sender: NSButtonCell) {
account?.isActive = sender.state == .on ? true : false
}
}