Create TimelineTableRowView and TimelineTableCellView in code.

This commit is contained in:
Brent Simmons 2019-02-13 21:33:50 -08:00
parent 8df96613c4
commit 9220cee0bb
6 changed files with 48 additions and 29 deletions

View File

@ -445,16 +445,6 @@
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView identifier="timelineCell" id="58o-U2-ss4" customClass="TimelineTableCellView" customModule="NetNewsWire" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="447" height="68"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</tableCellView>
<customView identifier="timelineRow" id="54E-Vz-WND" customClass="TimelineTableRowView" customModule="NetNewsWire" customModuleProvider="target">
<rect key="frame" x="0.0" y="68" width="447" height="96"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</customView>
</prototypeCellViews>
</tableColumn>
</tableColumns>
<connections>

View File

@ -23,10 +23,6 @@ final class DetailViewController: NSViewController, WKUIDelegate {
@IBOutlet var containerView: DetailContainerView!
@IBOutlet var statusBarView: DetailStatusBarView!
enum WebViewType {
case regular, search
}
lazy var regularWebViewController = {
return createWebViewController()
}()
@ -52,7 +48,7 @@ final class DetailViewController: NSViewController, WKUIDelegate {
// MARK: - API
func showState(_ state: DetailState, in webViewType: WebViewType) {
func showState(_ state: DetailState, mode: TimelineSourceMode) {
// TODO: also to-do is caller
}

View File

@ -11,6 +11,10 @@ import Articles
import Account
import RSCore
enum TimelineSourceMode {
case regular, search
}
class MainWindowController : NSWindowController, NSUserInterfaceValidations {
@IBOutlet var toolbarDelegate: MainWindowToolbarDelegate?

View File

@ -68,17 +68,19 @@ class TimelineTableCellView: NSTableCellView {
}
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
commonInit()
}
required init?(coder: NSCoder) {
required init?(coder: NSCoder) {
super.init(coder: coder)
commonInit()
}
convenience init() {
self.init(frame: NSRect.zero)
}
override func setFrameSize(_ newSize: NSSize) {
if newSize == self.frame.size {

View File

@ -10,6 +10,14 @@ import AppKit
class TimelineTableRowView : NSTableRowView {
init() {
super.init(frame: NSRect.zero)
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
private var cellView: TimelineTableCellView? {
for oneSubview in subviews {
if let foundView = oneSubview as? TimelineTableCellView {

View File

@ -11,6 +11,10 @@ import RSCore
import Articles
import Account
protocol TimelineDelegate: class {
func selectionDidChange(in: TimelineViewController, mode: TimelineSourceMode)
}
class TimelineViewController: NSViewController, UndoableCommandRunner {
@IBOutlet var tableView: TimelineTableView!
@ -582,24 +586,39 @@ extension TimelineViewController: NSTableViewDataSource {
extension TimelineViewController: NSTableViewDelegate {
func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
private static let rowViewIdentifier = NSUserInterfaceItemIdentifier(rawValue: "timelineRow")
let rowView: TimelineTableRowView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "timelineRow"), owner: self) as! TimelineTableRowView
func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
if let rowView: TimelineTableRowView = tableView.makeView(withIdentifier: TimelineViewController.rowViewIdentifier, owner: nil) as? TimelineTableRowView {
return rowView
}
let rowView = TimelineTableRowView()
rowView.identifier = TimelineViewController.rowViewIdentifier
return rowView
}
private static let timelineCellIdentifier = NSUserInterfaceItemIdentifier(rawValue: "timelineCell")
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
let cell: TimelineTableCellView = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "timelineCell"), owner: self) as! TimelineTableCellView
cell.cellAppearance = showAvatars ? cellAppearanceWithAvatar: cellAppearance
if let article = articles.articleAtRow(row) {
configureTimelineCell(cell, article: article)
}
else {
makeTimelineCellEmpty(cell)
func configure(_ cell: TimelineTableCellView) {
cell.cellAppearance = showAvatars ? cellAppearanceWithAvatar : cellAppearance
if let article = articles.articleAtRow(row) {
configureTimelineCell(cell, article: article)
}
else {
makeTimelineCellEmpty(cell)
}
}
if let cell = tableView.makeView(withIdentifier: TimelineViewController.timelineCellIdentifier, owner: nil) as? TimelineTableCellView {
configure(cell)
return cell
}
let cell = TimelineTableCellView()
cell.identifier = TimelineViewController.timelineCellIdentifier
configure(cell)
return cell
}