Create the timeline column layout.

This commit is contained in:
Brent Simmons committed 2026-09-19 10:26:29 -07:00
1 parent dbf3889e53
commit 299773e9b1
9 files changed
+573 -5

No files matched your search

@@ -8,7 +8,9 @@
<customObject id="-2" userLabel="File's Owner" customClass="TimelineContainerViewController" customModule="NetNewsWire" customModuleProvider="target">
<connections>
<outlet property="containerView" destination="Zpk-pq-9nW" id="Kye-yX-Wyn"/>
<outlet property="containerViewTopToHeaderConstraint" destination="KCa-8b-a6y" id="hdr-cn-st1"/>
<outlet property="groupByFeedMenuItem" destination="YSR-5C-Yjd" id="1aN-9S-nE1"/>
<outlet property="headerSeparator" destination="7p6-pA-iw6" id="hdr-se-p01"/>
<outlet property="newestToOldestMenuItem" destination="40c-kt-vhO" id="AGa-fX-EVy"/>
<outlet property="oldestToNewestMenuItem" destination="sOF-Ez-vIL" id="qSg-ST-ww9"/>
<outlet property="readFilteredButton" destination="iA5-go-AO0" id="kQg-2g-zNZ"/>
@@ -12,7 +12,7 @@ import Images
@MainActor struct TimelineCellData {
private static let noText = NSLocalizedString("(No Text)", comment: "No Text")
static let noText = NSLocalizedString("(No Text)", comment: "No Text")
let title: String
let attributedTitle: NSAttributedString
@@ -0,0 +1,150 @@
//
// TimelineColumnCellViews.swift
// NetNewsWire
//
// Created by Brent Simmons on 9/19/26.
// Copyright © 2026 Ranchero Software. All rights reserved.
//
import AppKit
// Cell views for the timeline’s column layout. Selection state arrives through backgroundStyle,
// which the standard NSTableRowView sets, so no custom row view is needed.
private let columnCellHorizontalPadding: CGFloat = 4.0
private let feedIconDimension: CGFloat = 16.0
private let feedIconMarginRight: CGFloat = 5.0
final class TimelineUnreadColumnCellView: NSTableCellView {
private let unreadIndicatorView = UnreadIndicatorView()
var isUnread = false {
didSet {
unreadIndicatorView.isHidden = !isUnread
}
}
override var backgroundStyle: NSView.BackgroundStyle {
didSet {
let isEmphasized = backgroundStyle == .emphasized
unreadIndicatorView.isSelected = isEmphasized
unreadIndicatorView.isEmphasized = isEmphasized
}
}
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
unreadIndicatorView.translatesAutoresizingMaskIntoConstraints = false
unreadIndicatorView.isHidden = true
addSubview(unreadIndicatorView)
NSLayoutConstraint.activate([
unreadIndicatorView.widthAnchor.constraint(equalToConstant: UnreadIndicatorView.unreadCircleDimension),
unreadIndicatorView.heightAnchor.constraint(equalToConstant: UnreadIndicatorView.unreadCircleDimension),
unreadIndicatorView.centerXAnchor.constraint(equalTo: centerXAnchor),
unreadIndicatorView.centerYAnchor.constraint(equalTo: centerYAnchor)
])
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
}
final class TimelineStarColumnCellView: NSTableCellView {
private let starImageView = NSImageView(image: Assets.Images.timelineStar)
var isStarred = false {
didSet {
starImageView.isHidden = !isStarred
}
}
override var backgroundStyle: NSView.BackgroundStyle {
didSet {
starImageView.contentTintColor = backgroundStyle == .emphasized ? .white : Assets.Colors.star
}
}
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
starImageView.translatesAutoresizingMaskIntoConstraints = false
starImageView.imageScaling = .scaleNone
starImageView.contentTintColor = Assets.Colors.star
starImageView.isHidden = true
addSubview(starImageView)
NSLayoutConstraint.activate([
starImageView.centerXAnchor.constraint(equalTo: centerXAnchor),
starImageView.centerYAnchor.constraint(equalTo: centerYAnchor)
])
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
}
/// Single line of truncating text — used for the Title and Date columns.
final class TimelineTextColumnCellView: NSTableCellView {
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
let label = TimelineTextColumnCellView.makeLabel()
addSubview(label)
textField = label
NSLayoutConstraint.activate([
label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: columnCellHorizontalPadding),
label.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -columnCellHorizontalPadding),
label.centerYAnchor.constraint(equalTo: centerYAnchor)
])
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
static func makeLabel() -> NSTextField {
let label = NSTextField(labelWithString: "")
label.translatesAutoresizingMaskIntoConstraints = false
label.lineBreakMode = .byTruncatingTail
label.maximumNumberOfLines = 1
label.cell?.truncatesLastVisibleLine = true
label.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
return label
}
}
/// Feed icon plus feed name.
final class TimelineFeedColumnCellView: NSTableCellView {
override init(frame frameRect: NSRect) {
super.init(frame: frameRect)
let iconView = NSImageView()
iconView.translatesAutoresizingMaskIntoConstraints = false
iconView.imageScaling = .scaleProportionallyDown
iconView.wantsLayer = true
iconView.layer?.cornerRadius = 2.0
iconView.layer?.masksToBounds = true
addSubview(iconView)
imageView = iconView
let label = TimelineTextColumnCellView.makeLabel()
addSubview(label)
textField = label
NSLayoutConstraint.activate([
iconView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: columnCellHorizontalPadding),
iconView.widthAnchor.constraint(equalToConstant: feedIconDimension),
iconView.heightAnchor.constraint(equalToConstant: feedIconDimension),
iconView.centerYAnchor.constraint(equalTo: centerYAnchor),
label.leadingAnchor.constraint(equalTo: iconView.trailingAnchor, constant: feedIconMarginRight),
label.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -columnCellHorizontalPadding),
label.centerYAnchor.constraint(equalTo: centerYAnchor)
])
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
}
@@ -0,0 +1,127 @@
//
// TimelineColumn.swift
// NetNewsWire
//
// Created by Brent Simmons on 9/19/26.
// Copyright © 2026 Ranchero Software. All rights reserved.
//
import AppKit
/// The columns of the timeline in column layout, in default order.
enum TimelineColumn: String, CaseIterable {
case unread
case starred
case feed
case title
case date
private static let statusColumnWidth: CGFloat = 22.0
private static let titleColumnWidth: CGFloat = 400.0
private static let titleColumnMinimumWidth: CGFloat = 100.0
private static let feedColumnWidth: CGFloat = 180.0
private static let feedColumnMinimumWidth: CGFloat = 80.0
private static let dateColumnWidth: CGFloat = 130.0
private static let dateColumnMinimumWidth: CGFloat = 70.0
private static let textColumnMaximumWidth: CGFloat = 2000.0
var identifier: NSUserInterfaceItemIdentifier {
NSUserInterfaceItemIdentifier(rawValue: rawValue)
}
init?(identifier: NSUserInterfaceItemIdentifier) {
self.init(rawValue: identifier.rawValue)
}
var sortKey: ArticleSortKey {
switch self {
case .unread:
.unread
case .starred:
.starred
case .title:
.title
case .feed:
.feed
case .date:
.date
}
}
/// The status columns have no header text — just a tooltip.
var headerTitle: String {
switch self {
case .unread, .starred:
""
case .title:
NSLocalizedString("Title", comment: "Timeline column header")
case .feed:
NSLocalizedString("Feed", comment: "Timeline column header")
case .date:
NSLocalizedString("Date", comment: "Timeline column header")
}
}
var headerToolTip: String {
switch self {
case .unread:
NSLocalizedString("Unread", comment: "Unread")
case .starred:
NSLocalizedString("Starred", comment: "Starred")
case .title, .feed, .date:
headerTitle
}
}
/// Direction used the first time the user clicks the header. Newest, unread, and starred go on top.
var sortsAscendingFirst: Bool {
switch self {
case .title, .feed:
true
case .unread, .starred, .date:
false
}
}
var isStatusColumn: Bool {
switch self {
case .unread, .starred:
true
case .title, .feed, .date:
false
}
}
@MainActor func makeTableColumn() -> NSTableColumn {
let column = NSTableColumn(identifier: identifier)
column.title = headerTitle
column.headerToolTip = headerToolTip
column.sortDescriptorPrototype = NSSortDescriptor(key: sortKey.rawValue, ascending: sortsAscendingFirst)
switch self {
case .unread, .starred:
column.width = Self.statusColumnWidth
column.minWidth = Self.statusColumnWidth
column.maxWidth = Self.statusColumnWidth
column.resizingMask = []
case .title:
column.width = Self.titleColumnWidth
column.minWidth = Self.titleColumnMinimumWidth
column.maxWidth = Self.textColumnMaximumWidth
// The only column that absorbs window resizing.
column.resizingMask = [.userResizingMask, .autoresizingMask]
case .feed:
column.width = Self.feedColumnWidth
column.minWidth = Self.feedColumnMinimumWidth
column.maxWidth = Self.textColumnMaximumWidth
column.resizingMask = .userResizingMask
case .date:
column.width = Self.dateColumnWidth
column.minWidth = Self.dateColumnMinimumWidth
column.maxWidth = Self.textColumnMaximumWidth
column.resizingMask = .userResizingMask
}
return column
}
}
@@ -24,8 +24,20 @@ final class TimelineContainerViewController: NSViewController {
@IBOutlet var groupByFeedMenuItem: NSMenuItem!
@IBOutlet var readFilteredButton: NSButton!
@IBOutlet var headerSeparator: NSBox!
@IBOutlet var containerViewTopToHeaderConstraint: NSLayoutConstraint!
@IBOutlet var containerView: TimelineContainerView!
private var layout = AppDefaults.shared.timelineLayout {
didSet {
if layout != oldValue {
layoutDidChange()
}
}
}
// Column layout hides the sort/filter header, and this pins the timeline to the top instead.
private lazy var containerViewTopToViewConstraint = containerView.topAnchor.constraint(equalTo: view.topAnchor)
var currentTimelineViewController: TimelineViewController? {
didSet {
let view = currentTimelineViewController?.view
@@ -94,8 +106,23 @@ final class TimelineContainerViewController: NSViewController {
makeMenuItemTitleLarger(oldestToNewestMenuItem)
makeMenuItemTitleLarger(groupByFeedMenuItem)
updateViewOptionsPopUpButton()
updateHeaderVisibility()
NotificationCenter.default.addObserver(self, selector: #selector(handleUserDefaultsDidChange(_:)), name: UserDefaults.didChangeNotification, object: nil)
}
// MARK: - Notifications
@objc nonisolated func handleUserDefaultsDidChange(_ note: Notification) {
Task { @MainActor in
self.userDefaultsDidChange()
}
}
private func userDefaultsDidChange() {
layout = AppDefaults.shared.timelineLayout
}
// MARK: - API
func sortByDate(_ direction: ComparisonResult) {
@@ -185,6 +212,9 @@ extension TimelineContainerViewController: TimelineDelegate {
delegate?.timelineInvalidatedRestorationState(self)
}
func timelineRequestedSortChange(_: TimelineViewController, parameters: ArticleSortParameters) {
sortParameters = parameters
}
}
private extension TimelineContainerViewController {
@@ -230,7 +260,29 @@ private extension TimelineContainerViewController {
groupByFeedMenuItem.state = sortParameters.groupByFeed ? .on : .off
}
func layoutDidChange() {
// Standard layout sorts by date only.
if layout == .standard && sortParameters.key != .date {
sortParameters = sortParameters.withKey(.date, direction: .orderedDescending)
}
updateHeaderVisibility()
}
func updateHeaderVisibility() {
let isHeaderHidden = layout == .column
viewOptionsPopUpButton.isHidden = isHeaderHidden
headerSeparator.isHidden = isHeaderHidden
containerViewTopToHeaderConstraint.isActive = !isHeaderHidden
containerViewTopToViewConstraint.isActive = isHeaderHidden
updateReadFilterButton()
}
func updateReadFilterButton() {
guard layout == .standard else {
readFilteredButton.isHidden = true
return
}
guard currentTimelineViewController == regularTimelineViewController else {
readFilteredButton.isHidden = true
return
@@ -0,0 +1,23 @@
//
// TimelineLayout.swift
// NetNewsWire
//
// Created by Brent Simmons on 9/19/26.
// Copyright © 2026 Ranchero Software. All rights reserved.
//
import Foundation
/// Standard: one custom-drawn column, article view to the right.
/// Column: multi-column table with a header, article view below, like Mail’s Use Column Layout.
enum TimelineLayout {
case standard
case column
}
extension AppDefaults {
var timelineLayout: TimelineLayout {
useColumnLayout ? .column : .standard
}
}
@@ -0,0 +1,166 @@
//
// TimelineViewController+ColumnLayout.swift
// NetNewsWire
//
// Created by Brent Simmons on 9/19/26.
// Copyright © 2026 Ranchero Software. All rights reserved.
//
import AppKit
import Articles
// The table view is shared by both layouts. These reconfigure it for the current one
// and supply the per-column cells used in column layout.
private let columnRowVerticalPadding: CGFloat = 3.0
private let columnAutosaveName = "TimelineColumns"
extension TimelineViewController {
func configureTableView(for layout: TimelineLayout) {
switch layout {
case .standard:
configureTableViewForStandardLayout()
case .column:
configureTableViewForColumnLayout()
}
}
var columnFont: NSFont {
NSFont.systemFont(ofSize: AppDefaults.shared.actualFontSize(for: AppDefaults.shared.timelineFontSize))
}
func columnRowHeight() -> CGFloat {
let font = columnFont
let lineHeight = ceil(font.ascender - font.descender + font.leading)
return lineHeight + (columnRowVerticalPadding * 2.0)
}
func columnCellView(for tableColumn: NSTableColumn?, row: Int) -> NSView? {
guard let tableColumn, let column = TimelineColumn(identifier: tableColumn.identifier) else {
return nil
}
let article = articles.articleAtRow(row)
let identifier = tableColumn.identifier
switch column {
case .unread:
let cell = tableView.makeView(withIdentifier: identifier, owner: nil) as? TimelineUnreadColumnCellView ?? makeCell(TimelineUnreadColumnCellView(), identifier: identifier)
cell.isUnread = article.map { !$0.status.read } ?? false
return cell
case .starred:
let cell = tableView.makeView(withIdentifier: identifier, owner: nil) as? TimelineStarColumnCellView ?? makeCell(TimelineStarColumnCellView(), identifier: identifier)
cell.isStarred = article?.status.starred ?? false
return cell
case .title:
let cell = tableView.makeView(withIdentifier: identifier, owner: nil) as? TimelineTextColumnCellView ?? makeCell(TimelineTextColumnCellView(), identifier: identifier)
cell.textField?.font = columnFont
cell.textField?.stringValue = article.map { columnTitleText(for: $0) } ?? ""
return cell
case .feed:
let cell = tableView.makeView(withIdentifier: identifier, owner: nil) as? TimelineFeedColumnCellView ?? makeCell(TimelineFeedColumnCellView(), identifier: identifier)
cell.textField?.font = columnFont
cell.textField?.stringValue = article?.feed?.nameForDisplay ?? ""
cell.imageView?.image = article?.feed.flatMap { IconImageCache.shared.imageForFeed($0) }?.image
return cell
case .date:
let cell = tableView.makeView(withIdentifier: identifier, owner: nil) as? TimelineTextColumnCellView ?? makeCell(TimelineTextColumnCellView(), identifier: identifier)
cell.textField?.font = columnFont
cell.textField?.stringValue = article.map { ArticleStringFormatter.shared.dateString($0.logicalDatePublished) } ?? ""
return cell
}
}
/// Keeps the header’s sort indicator in step with this window’s sort. Column layout only.
func applySortDescriptorsToTableView() {
guard layout == .column else {
return
}
let descriptors = [NSSortDescriptor(key: sortParameters.key.rawValue, ascending: sortParameters.direction == .orderedAscending)]
if tableView.sortDescriptors != descriptors {
tableView.sortDescriptors = descriptors
}
}
// MARK: - NSTableViewDataSource
func tableView(_ tableView: NSTableView, sortDescriptorsDidChange oldDescriptors: [NSSortDescriptor]) {
// A header click. Don’t sort here — ask the container, which owns the window’s sort.
// Setting sortDescriptors programmatically lands here too, and the equality check ends that loop.
guard let descriptor = tableView.sortDescriptors.first, let rawKey = descriptor.key, let key = ArticleSortKey(rawValue: rawKey) else {
return
}
let direction: ComparisonResult = descriptor.ascending ? .orderedAscending : .orderedDescending
let requestedParameters = sortParameters.withKey(key, direction: direction)
if requestedParameters == sortParameters {
return
}
delegate?.timelineRequestedSortChange(self, parameters: requestedParameters)
}
}
// MARK: - Private
private extension TimelineViewController {
func configureTableViewForStandardLayout() {
tableView.autosaveTableColumns = false
tableView.autosaveName = nil
tableView.sortDescriptors = []
removeAllTableColumns()
if let standardColumn {
tableView.addTableColumn(standardColumn)
}
tableView.headerView = nil
tableView.style = .inset
tableView.columnAutoresizingStyle = .lastColumnOnlyAutoresizingStyle
tableView.allowsColumnReordering = false
tableView.allowsColumnResizing = false
tableView.rowHeight = standardRowHeight
}
func configureTableViewForColumnLayout() {
removeAllTableColumns()
for column in TimelineColumn.allCases {
tableView.addTableColumn(column.makeTableColumn())
}
tableView.headerView = NSTableHeaderView()
tableView.style = .fullWidth
tableView.columnAutoresizingStyle = .uniformColumnAutoresizingStyle
tableView.allowsColumnReordering = true
tableView.allowsColumnResizing = true
tableView.rowHeight = columnRowHeight()
// Set the name before turning autosave on so saved widths and order are read back.
tableView.autosaveName = columnAutosaveName
tableView.autosaveTableColumns = true
applySortDescriptorsToTableView()
}
/// An untitled article shows the start of its body instead, as the standard timeline does.
func columnTitleText(for article: Article) -> String {
let title = ArticleStringFormatter.shared.truncatedTitle(article)
if !title.isEmpty {
return title
}
let summary = ArticleStringFormatter.shared.truncatedSummary(article).collapsingWhitespace
if !summary.isEmpty {
return summary
}
return TimelineCellData.noText
}
func removeAllTableColumns() {
for column in tableView.tableColumns {
tableView.removeTableColumn(column)
}
}
func makeCell<T: NSTableCellView>(_ cell: T, identifier: NSUserInterfaceItemIdentifier) -> T {
cell.identifier = identifier
return cell
}
}
@@ -17,6 +17,7 @@ import Images
func timelineSelectionDidChange(_: TimelineViewController, selectedArticles: [Article]?)
func timelineRequestedFeedSelection(_: TimelineViewController, feed: Feed)
func timelineInvalidatedRestorationState(_: TimelineViewController)
func timelineRequestedSortChange(_: TimelineViewController, parameters: ArticleSortParameters)
}
enum TimelineShowFeedName: Sendable {
@@ -190,9 +191,22 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
didSet {
if isViewLoaded && sortParameters != oldValue {
sortParametersDidChange()
applySortDescriptorsToTableView()
}
}
}
var layout = AppDefaults.shared.timelineLayout {
didSet {
if isViewLoaded && layout != oldValue {
layoutDidChange()
}
}
}
// The nib’s single column, kept so standard layout can put it back.
var standardColumn: NSTableColumn?
var standardRowHeight: CGFloat {
currentRowHeight
}
private var fontSize: FontSize = AppDefaults.shared.timelineFontSize {
didSet {
if fontSize != oldValue {
@@ -227,13 +241,13 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
cellAppearanceWithIcon = TimelineCellAppearance(showIcon: true, fontSize: fontSize)
updateRowHeights()
tableView.rowHeight = currentRowHeight
tableView.target = self
tableView.doubleAction = #selector(openArticleInBrowser(_:))
tableView.setDraggingSourceOperationMask(.copy, forLocal: false)
tableView.keyboardDelegate = keyboardDelegate
tableView.style = .inset
standardColumn = tableView.tableColumns.first
configureTableView(for: layout)
if !didRegisterForNotifications {
NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil)
@@ -757,6 +771,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
@MainActor func userDefaultsDidChange() {
fontSize = AppDefaults.shared.timelineFontSize
layout = AppDefaults.shared.timelineLayout
}
// MARK: - Reloading Data
@@ -804,7 +819,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
if indexes.isEmpty {
return
}
tableView.reloadData(forRowIndexes: indexes, columnIndexes: NSIndexSet(index: 0) as IndexSet)
tableView.reloadData(forRowIndexes: indexes, columnIndexes: IndexSet(integersIn: 0..<tableView.numberOfColumns))
}
// MARK: - Cell Configuring
@@ -915,6 +930,10 @@ extension TimelineViewController: NSTableViewDelegate {
private static let rowViewIdentifier = NSUserInterfaceItemIdentifier(rawValue: "timelineRow")
func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {
if layout == .column {
// The standard row view suits column layout. TimelineTableRowView only knows the standard cell.
return nil
}
if let rowView: TimelineTableRowView = tableView.makeView(withIdentifier: TimelineViewController.rowViewIdentifier, owner: nil) as? TimelineTableRowView {
return rowView
}
@@ -926,6 +945,9 @@ extension TimelineViewController: NSTableViewDelegate {
private static let timelineCellIdentifier = NSUserInterfaceItemIdentifier(rawValue: "timelineCell")
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
if layout == .column {
return columnCellView(for: tableColumn, row: row)
}
func configure(_ cell: TimelineTableCellView) {
cell.cellAppearance = showIcons ? cellAppearanceWithIcon : cellAppearance
@@ -1081,10 +1103,27 @@ private extension TimelineViewController {
}
func updateTableViewRowHeight() {
tableView.rowHeight = currentRowHeight
tableView.rowHeight = layout == .column ? columnRowHeight() : currentRowHeight
}
func layoutDidChange() {
performBlockAndRestoreSelection {
configureTableView(for: layout)
updateShowIcons()
tableView.reloadData()
}
if tableView.selectedRow != -1 {
tableView.scrollRowToVisible(tableView.selectedRow)
}
}
func updateShowIcons() {
if layout == .column {
// The Feed column always shows the feed icon.
self.showIcons = true
return
}
if showFeedNames == .feed {
self.showIcons = true
return
+9
View File
@@ -45,6 +45,15 @@
"%lld months" : {
"comment" : "Dinosaur staleness threshold in months"
},
"Date" : {
"comment" : "Timeline column header"
},
"Feed" : {
"comment" : "Timeline column header"
},
"Title" : {
"comment" : "Timeline column header"
},
"🦖 Dinosaurs" : {
"comment" : "The title of the Dinosaurs screen.",
"isCommentAutoGenerated" : true