mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-30 17:29:23 +00:00
💄 Add `MainFeedCollectionViewController` 💄 Add and hook up UICollectionView in Storyboard 🚧 Collection view loads temp cells 🚧 UICollectionView - Adds capsule shape for iPad selection - Add filter button, newItem button, settings button - Configures the collection view based on platform - implementsDidSelectItem at - Clears cell background on iPad - Adds cell textColor for iPad - Storyboard changes 🚧 Adds unread count and favicon support 🚧 Smartfeed icons now display 🚧 iPhone cells are consistent in light/dark mode 💄 Sidebar modernised Known bug: Sidebar text doesn’t adapt to dark/light mode changes on iPad 💄 Modern Sidebars Fixes some accessibilty issues and adds swipe actions. 🩹 Become firstResponder 🩹 Workaround #4691 💡 Remove print statement 💄 Fixes to storyboard - adjusts constraints on timeline header view - launch screens now adopt look of liquid glass Restore coordinator behaviour ⚡️ Tweaks to MainFeedCollectionViewController - On iPhone, returning to the feeds view deselect the current feed with an animation. - On iPhone, prefers large titles defaults to `false` - Capsule background with smaller corner radius for iPhone added for selected status. 🩹 Fixes folder height 💄 Fix unread count vertical alignment 💄 Restores header & use UICellConfigurationState 💄 Sidebar tweaks 💄 Folders now highlight on as drop target 💄 Sidebar fixes - Moves more code to cell configuation state - Allows sidebar to move to larger sizes 🩹 Fixes #4694 folder expansion using keyboard 💄 Adds new cell types for the Timeline ♻️ Remove dead code and re-orders to viewWillApp 🩹 Reordering of code from viewWA to viewDA 💄 Removes unused code, tweaks layout 💄 Multiple tweaks to sidebar and timeline 💄 Add missing constraint ♿️ Puts timeline metadata in a stackview 🎨 Adds stackview function 💄 🚑️ Moves to modern UISliders Timeline customiser now uses modern UISliders as they have tickmark functionality. `TickMarkSlider` marked as deprecated. 💄 Make All Unread cell icon tint correctly 💄 Extend edges under opaque bars on timeline 💄 Image View Controller uses modern button style 🚚 Renames `MainTimelinePseudoFeedCell` 💄 Improve feed selection animations 🩹 Use shouldSelectItem to handle selection logic 🩹 Fix fill settings for stack view 💄 Comment out usage of MainTimelineTitleView 🔧 Remove iOS cells from macOS target 💄 Give columns some flexibility 💄 Fix chevron size and alignment 💄 Don’t prefer large navigation bar titles They create a delay in animation on iPhone. 🩹 Fixes nav bar subtitle performance 🎨 Minor refactor - Switch logic in cell state - Prefer traitCollection.userInterfaceIdiom ➕ Add updated mac code for the About view 💄 NSGlassVisualEffectView for About
312 lines
11 KiB
Swift
312 lines
11 KiB
Swift
//
|
|
// TimelineViewController+ContextualMenus.swift
|
|
// NetNewsWire
|
|
//
|
|
// Created by Brent Simmons on 2/9/18.
|
|
// Copyright © 2018 Ranchero Software. All rights reserved.
|
|
//
|
|
|
|
import AppKit
|
|
import RSCore
|
|
import Articles
|
|
import Account
|
|
|
|
extension TimelineViewController {
|
|
|
|
func contextualMenuForClickedRows() -> NSMenu? {
|
|
|
|
let row = tableView.clickedRow
|
|
guard row != -1, let article = articles.articleAtRow(row) else {
|
|
return nil
|
|
}
|
|
|
|
if selectedArticles.contains(article) {
|
|
// If the clickedRow is part of the selected rows, then do a contextual menu for all the selected rows.
|
|
return menu(for: selectedArticles)
|
|
}
|
|
return menu(for: [article])
|
|
}
|
|
}
|
|
|
|
// MARK: Contextual Menu Actions
|
|
|
|
extension TimelineViewController {
|
|
|
|
@objc func markArticlesReadFromContextualMenu(_ sender: Any?) {
|
|
guard let articles = articles(from: sender) else { return }
|
|
markArticles(articles, read: true)
|
|
}
|
|
|
|
@objc func markArticlesUnreadFromContextualMenu(_ sender: Any?) {
|
|
guard let articles = articles(from: sender) else { return }
|
|
markArticles(articles, read: false)
|
|
}
|
|
|
|
@objc func markAboveArticlesReadFromContextualMenu(_ sender: Any?) {
|
|
guard let articles = articles(from: sender) else { return }
|
|
markAboveArticlesRead(articles)
|
|
}
|
|
|
|
@objc func markBelowArticlesReadFromContextualMenu(_ sender: Any?) {
|
|
guard let articles = articles(from: sender) else { return }
|
|
markBelowArticlesRead(articles)
|
|
}
|
|
|
|
@objc func markArticlesStarredFromContextualMenu(_ sender: Any?) {
|
|
guard let articles = articles(from: sender) else { return }
|
|
markArticles(articles, starred: true)
|
|
}
|
|
|
|
@objc func markArticlesUnstarredFromContextualMenu(_ sender: Any?) {
|
|
guard let articles = articles(from: sender) else {
|
|
return
|
|
}
|
|
markArticles(articles, starred: false)
|
|
}
|
|
|
|
@objc func selectFeedInSidebarFromContextualMenu(_ sender: Any?) {
|
|
guard let menuItem = sender as? NSMenuItem, let webFeed = menuItem.representedObject as? WebFeed else {
|
|
return
|
|
}
|
|
delegate?.timelineRequestedWebFeedSelection(self, webFeed: webFeed)
|
|
}
|
|
|
|
@objc func markAllInFeedAsRead(_ sender: Any?) {
|
|
guard let menuItem = sender as? NSMenuItem, let feedArticles = menuItem.representedObject as? ArticleArray else {
|
|
return
|
|
}
|
|
|
|
guard let undoManager = undoManager, let markReadCommand = MarkStatusCommand(initialArticles: feedArticles, markingRead: true, undoManager: undoManager) else {
|
|
return
|
|
}
|
|
|
|
runCommand(markReadCommand)
|
|
}
|
|
|
|
@objc func openInBrowserFromContextualMenu(_ sender: Any?) {
|
|
|
|
guard let menuItem = sender as? NSMenuItem, let urlString = menuItem.representedObject as? String else {
|
|
return
|
|
}
|
|
Browser.open(urlString, inBackground: false)
|
|
}
|
|
|
|
@objc func copyURLFromContextualMenu(_ sender: Any?) {
|
|
guard let menuItem = sender as? NSMenuItem, let urlString = menuItem.representedObject as? String else {
|
|
return
|
|
}
|
|
URLPasteboardWriter.write(urlString: urlString, to: .general)
|
|
}
|
|
|
|
@objc func performShareServiceFromContextualMenu(_ sender: Any?) {
|
|
guard let menuItem = sender as? NSMenuItem, let sharingCommandInfo = menuItem.representedObject as? SharingCommandInfo else {
|
|
return
|
|
}
|
|
sharingCommandInfo.perform()
|
|
}
|
|
}
|
|
|
|
|
|
private extension TimelineViewController {
|
|
|
|
func markArticles(_ articles: [Article], read: Bool) {
|
|
markArticles(articles, statusKey: .read, flag: read)
|
|
}
|
|
|
|
func markArticles(_ articles: [Article], starred: Bool) {
|
|
markArticles(articles, statusKey: .starred, flag: starred)
|
|
}
|
|
|
|
func markArticles(_ articles: [Article], statusKey: ArticleStatus.Key, flag: Bool) {
|
|
guard let undoManager = undoManager, let markStatusCommand = MarkStatusCommand(initialArticles: articles, statusKey: statusKey, flag: flag, undoManager: undoManager) else {
|
|
return
|
|
}
|
|
|
|
runCommand(markStatusCommand)
|
|
}
|
|
|
|
func unreadArticles(from articles: [Article]) -> [Article]? {
|
|
let filteredArticles = articles.filter { !$0.status.read }
|
|
return filteredArticles.isEmpty ? nil : filteredArticles
|
|
}
|
|
|
|
func readArticles(from articles: [Article]) -> [Article]? {
|
|
let filteredArticles = articles.filter { $0.status.read }
|
|
return filteredArticles.isEmpty ? nil : filteredArticles
|
|
}
|
|
|
|
func articles(from sender: Any?) -> [Article]? {
|
|
return (sender as? NSMenuItem)?.representedObject as? [Article]
|
|
}
|
|
|
|
func menu(for articles: [Article]) -> NSMenu? {
|
|
let menu = NSMenu(title: "")
|
|
|
|
if articles.anyArticleIsUnread() {
|
|
menu.addItem(markReadMenuItem(articles))
|
|
}
|
|
if articles.anyArticleIsReadAndCanMarkUnread() {
|
|
menu.addItem(markUnreadMenuItem(articles))
|
|
}
|
|
if articles.anyArticleIsUnstarred() {
|
|
menu.addItem(markStarredMenuItem(articles))
|
|
}
|
|
if articles.anyArticleIsStarred() {
|
|
menu.addItem(markUnstarredMenuItem(articles))
|
|
}
|
|
if let first = articles.first, self.articles.articlesAbove(article: first).canMarkAllAsRead() {
|
|
menu.addItem(markAboveReadMenuItem(articles))
|
|
}
|
|
if let last = articles.last, self.articles.articlesBelow(article: last).canMarkAllAsRead() {
|
|
menu.addItem(markBelowReadMenuItem(articles))
|
|
}
|
|
|
|
menu.addSeparatorIfNeeded()
|
|
|
|
if articles.count == 1, let feed = articles.first!.webFeed {
|
|
if !(representedObjects?.contains(where: { $0 as? WebFeed == feed }) ?? false) {
|
|
menu.addItem(selectFeedInSidebarMenuItem(feed))
|
|
}
|
|
if let markAllMenuItem = markAllAsReadMenuItem(feed) {
|
|
menu.addItem(markAllMenuItem)
|
|
}
|
|
}
|
|
|
|
if articles.count == 1, let link = articles.first!.preferredLink {
|
|
menu.addSeparatorIfNeeded()
|
|
menu.addItem(openInBrowserMenuItem(link))
|
|
menu.addSeparatorIfNeeded()
|
|
menu.addItem(copyArticleURLMenuItem(link))
|
|
|
|
if let externalLink = articles.first?.externalLink, externalLink != link {
|
|
menu.addItem(copyExternalURLMenuItem(externalLink))
|
|
}
|
|
}
|
|
|
|
if let sharingMenu = shareMenu(for: articles) {
|
|
menu.addSeparatorIfNeeded()
|
|
let menuItem = NSMenuItem(title: sharingMenu.title, action: nil, keyEquivalent: "")
|
|
menuItem.submenu = sharingMenu
|
|
menu.addItem(menuItem)
|
|
}
|
|
|
|
return menu
|
|
}
|
|
|
|
func shareMenu(for articles: [Article]) -> NSMenu? {
|
|
if articles.isEmpty {
|
|
return nil
|
|
}
|
|
|
|
let sortedArticles = articles.sortedByDate(.orderedAscending)
|
|
let items = sortedArticles.map { ArticlePasteboardWriter(article: $0) }
|
|
let standardServices = NSSharingService.sharingServices(forItems_noDeprecationWarning: items) as? [NSSharingService] ?? [NSSharingService]()
|
|
let customServices = SharingServicePickerDelegate.customSharingServices(for: items)
|
|
let services = standardServices + customServices
|
|
if services.isEmpty {
|
|
return nil
|
|
}
|
|
|
|
let menu = NSMenu(title: NSLocalizedString("Share", comment: "Share menu name"))
|
|
services.forEach { (service) in
|
|
service.delegate = sharingServiceDelegate
|
|
let menuItem = NSMenuItem(title: service.menuItemTitle, action: #selector(performShareServiceFromContextualMenu(_:)), keyEquivalent: "")
|
|
menuItem.image = service.image
|
|
let sharingCommandInfo = SharingCommandInfo(service: service, items: items)
|
|
menuItem.representedObject = sharingCommandInfo
|
|
menu.addItem(menuItem)
|
|
}
|
|
|
|
return menu
|
|
}
|
|
|
|
func markReadMenuItem(_ articles: [Article]) -> NSMenuItem {
|
|
|
|
return menuItem(NSLocalizedString("Mark as Read", comment: "Command"), #selector(markArticlesReadFromContextualMenu(_:)), articles, image: AppAssets.swipeMarkReadImage)
|
|
}
|
|
|
|
func markUnreadMenuItem(_ articles: [Article]) -> NSMenuItem {
|
|
|
|
return menuItem(NSLocalizedString("Mark as Unread", comment: "Command"), #selector(markArticlesUnreadFromContextualMenu(_:)), articles, image: AppAssets.swipeMarkUnreadImage)
|
|
}
|
|
|
|
func markStarredMenuItem(_ articles: [Article]) -> NSMenuItem {
|
|
|
|
return menuItem(NSLocalizedString("Mark as Starred", comment: "Command"), #selector(markArticlesStarredFromContextualMenu(_:)), articles, image: AppAssets.swipeMarkStarredImage)
|
|
}
|
|
|
|
func markUnstarredMenuItem(_ articles: [Article]) -> NSMenuItem {
|
|
|
|
return menuItem(NSLocalizedString("Mark as Unstarred", comment: "Command"), #selector(markArticlesUnstarredFromContextualMenu(_:)), articles, image: AppAssets.swipeMarkUnstarredImage)
|
|
}
|
|
|
|
func markAboveReadMenuItem(_ articles: [Article]) -> NSMenuItem {
|
|
return menuItem(NSLocalizedString("Mark Above as Read", comment: "Command"), #selector(markAboveArticlesReadFromContextualMenu(_:)), articles, image: AppAssets.markAboveAsReadImage)
|
|
}
|
|
|
|
func markBelowReadMenuItem(_ articles: [Article]) -> NSMenuItem {
|
|
return menuItem(NSLocalizedString("Mark Below as Read", comment: "Command"), #selector(markBelowArticlesReadFromContextualMenu(_:)), articles, image: AppAssets.markBelowAsReadImage)
|
|
}
|
|
|
|
func selectFeedInSidebarMenuItem(_ feed: WebFeed) -> NSMenuItem {
|
|
let localizedMenuText = NSLocalizedString("Select “%@” in Sidebar", comment: "Command")
|
|
let formattedMenuText = NSString.localizedStringWithFormat(localizedMenuText as NSString, feed.nameForDisplay)
|
|
return menuItem(formattedMenuText as String, #selector(selectFeedInSidebarFromContextualMenu(_:)), feed, image: nil)
|
|
}
|
|
|
|
func markAllAsReadMenuItem(_ feed: WebFeed) -> NSMenuItem? {
|
|
guard let articlesSet = try? feed.fetchArticles() else {
|
|
return nil
|
|
}
|
|
let articles = Array(articlesSet)
|
|
guard articles.canMarkAllAsRead() else {
|
|
return nil
|
|
}
|
|
|
|
let localizedMenuText = NSLocalizedString("Mark All as Read in “%@”", comment: "Command")
|
|
let menuText = NSString.localizedStringWithFormat(localizedMenuText as NSString, feed.nameForDisplay) as String
|
|
|
|
return menuItem(menuText, #selector(markAllInFeedAsRead(_:)), articles, image: AppAssets.markAllAsReadImage)
|
|
}
|
|
|
|
func openInBrowserMenuItem(_ urlString: String) -> NSMenuItem {
|
|
|
|
return menuItem(NSLocalizedString("Open in Browser", comment: "Command"), #selector(openInBrowserFromContextualMenu(_:)), urlString, image: AppAssets.openInBrowserImage)
|
|
}
|
|
|
|
func copyArticleURLMenuItem(_ urlString: String) -> NSMenuItem {
|
|
return menuItem(NSLocalizedString("Copy Article URL", comment: "Command"), #selector(copyURLFromContextualMenu(_:)), urlString, image: AppAssets.copyImage)
|
|
}
|
|
|
|
func copyExternalURLMenuItem(_ urlString: String) -> NSMenuItem {
|
|
return menuItem(NSLocalizedString("Copy External URL", comment: "Command"), #selector(copyURLFromContextualMenu(_:)), urlString, image: AppAssets.copyImage)
|
|
}
|
|
|
|
|
|
func menuItem(_ title: String, _ action: Selector, _ representedObject: Any, image: RSImage?) -> NSMenuItem {
|
|
|
|
let item = NSMenuItem(title: title, action: action, keyEquivalent: "")
|
|
item.representedObject = representedObject
|
|
item.target = self
|
|
if let image {
|
|
item.image = image
|
|
}
|
|
return item
|
|
}
|
|
}
|
|
|
|
private final class SharingCommandInfo {
|
|
|
|
let service: NSSharingService
|
|
let items: [Any]
|
|
|
|
init(service: NSSharingService, items: [Any]) {
|
|
self.service = service
|
|
self.items = items
|
|
}
|
|
|
|
func perform() {
|
|
service.perform(withItems: items)
|
|
}
|
|
}
|