2017-05-27 19:43:27 +02:00
|
|
|
//
|
|
|
|
// MainWindowController.swift
|
|
|
|
// Evergreen
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 8/1/15.
|
|
|
|
// Copyright © 2015 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2018-02-03 07:51:32 +01:00
|
|
|
import AppKit
|
2018-07-24 03:29:08 +02:00
|
|
|
import Articles
|
2017-10-07 23:40:14 +02:00
|
|
|
import Account
|
2018-02-18 02:45:05 +01:00
|
|
|
import RSCore
|
2017-05-27 19:43:27 +02:00
|
|
|
|
|
|
|
class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
2018-02-08 06:42:33 +01:00
|
|
|
|
2018-02-18 05:33:30 +01:00
|
|
|
@IBOutlet var toolbarDelegate: MainWindowToolbarDelegate?
|
|
|
|
private let sharingServicePickerDelegate = MainWindowSharingServicePickerDelegate()
|
2017-05-27 19:43:27 +02:00
|
|
|
|
2018-02-18 05:58:30 +01:00
|
|
|
private let windowAutosaveName = NSWindow.FrameAutosaveName(rawValue: "MainWindow")
|
2018-02-18 05:45:15 +01:00
|
|
|
static var didPositionWindowOnFirstRun = false
|
|
|
|
|
2017-10-19 06:53:45 +02:00
|
|
|
private var unreadCount: Int = 0 {
|
|
|
|
didSet {
|
|
|
|
if unreadCount != oldValue {
|
|
|
|
updateWindowTitle()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-06 03:17:07 +02:00
|
|
|
|
2018-02-18 05:45:15 +01:00
|
|
|
private var shareToolbarItem: NSToolbarItem? {
|
|
|
|
return window?.toolbar?.existingItem(withIdentifier: .Share)
|
|
|
|
}
|
2018-02-18 05:33:30 +01:00
|
|
|
|
2018-02-27 07:31:07 +01:00
|
|
|
private static var detailViewMinimumThickness = 384
|
|
|
|
|
2018-02-18 05:45:15 +01:00
|
|
|
// MARK: - NSWindowController
|
2017-12-21 23:47:12 +01:00
|
|
|
|
2018-02-08 06:42:33 +01:00
|
|
|
override func windowDidLoad() {
|
|
|
|
|
|
|
|
super.windowDidLoad()
|
2018-02-18 05:45:15 +01:00
|
|
|
|
2017-12-02 23:54:12 +01:00
|
|
|
if !AppDefaults.shared.showTitleOnMainWindow {
|
|
|
|
window?.titleVisibility = .hidden
|
|
|
|
}
|
2017-12-21 23:43:29 +01:00
|
|
|
|
2017-10-06 03:17:07 +02:00
|
|
|
window?.setFrameUsingName(windowAutosaveName, force: true)
|
2017-12-21 23:47:12 +01:00
|
|
|
if AppDefaults.shared.isFirstRun && !MainWindowController.didPositionWindowOnFirstRun {
|
2017-12-21 23:43:29 +01:00
|
|
|
|
2017-12-24 19:28:34 +01:00
|
|
|
if let window = window {
|
|
|
|
let point = NSPoint(x: 128, y: 64)
|
|
|
|
let size = NSSize(width: 1000, height: 700)
|
|
|
|
let minSize = NSSize(width: 600, height: 600)
|
|
|
|
window.setPointAndSizeAdjustingForScreen(point: point, size: size, minimumSize: minSize)
|
2017-12-21 23:47:12 +01:00
|
|
|
MainWindowController.didPositionWindowOnFirstRun = true
|
2017-12-21 23:43:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-27 07:31:07 +01:00
|
|
|
detailSplitViewItem?.minimumThickness = CGFloat(MainWindowController.detailViewMinimumThickness)
|
|
|
|
restoreSplitViewState()
|
|
|
|
|
2017-09-18 01:30:45 +02:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(applicationWillTerminate(_:)), name: NSApplication.willTerminateNotification, object: nil)
|
2017-05-27 19:43:27 +02:00
|
|
|
|
2017-10-07 23:40:14 +02:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(refreshProgressDidChange(_:)), name: .AccountRefreshDidBegin, object: nil)
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(refreshProgressDidChange(_:)), name: .AccountRefreshDidFinish, object: nil)
|
2017-10-08 02:43:10 +02:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(refreshProgressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil)
|
2017-10-19 06:53:45 +02:00
|
|
|
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
|
|
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
self.updateWindowTitle()
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
2017-10-19 06:53:45 +02:00
|
|
|
}
|
2018-01-21 20:35:50 +01:00
|
|
|
|
2018-02-18 05:58:30 +01:00
|
|
|
// MARK: - API
|
|
|
|
|
2018-02-12 22:31:43 +01:00
|
|
|
func saveState() {
|
|
|
|
|
2018-02-27 07:31:07 +01:00
|
|
|
saveSplitViewState()
|
2018-02-12 22:31:43 +01:00
|
|
|
}
|
|
|
|
|
2018-02-27 07:31:07 +01:00
|
|
|
|
2018-01-21 20:35:50 +01:00
|
|
|
func selectedObjectsInSidebar() -> [AnyObject]? {
|
|
|
|
|
|
|
|
return sidebarViewController?.selectedObjects
|
|
|
|
}
|
|
|
|
|
2018-02-18 05:58:30 +01:00
|
|
|
// MARK: - Notifications
|
2018-02-08 06:42:33 +01:00
|
|
|
|
2017-09-17 21:54:08 +02:00
|
|
|
@objc func applicationWillTerminate(_ note: Notification) {
|
2018-02-08 06:42:33 +01:00
|
|
|
|
2018-02-27 07:31:07 +01:00
|
|
|
saveState()
|
2017-10-06 03:17:07 +02:00
|
|
|
window?.saveFrame(usingName: windowAutosaveName)
|
2018-02-08 06:42:33 +01:00
|
|
|
}
|
2017-05-27 19:43:27 +02:00
|
|
|
|
2017-09-17 21:54:08 +02:00
|
|
|
@objc func refreshProgressDidChange(_ note: Notification) {
|
2018-02-18 00:20:07 +01:00
|
|
|
|
2018-02-18 02:45:05 +01:00
|
|
|
CoalescingQueue.standard.add(self, #selector(makeToolbarValidate))
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
2017-10-19 06:53:45 +02:00
|
|
|
|
|
|
|
@objc func unreadCountDidChange(_ note: Notification) {
|
|
|
|
|
|
|
|
if note.object is AccountManager {
|
|
|
|
unreadCount = AccountManager.shared.unreadCount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-18 05:58:30 +01:00
|
|
|
// MARK: - Toolbar
|
2017-05-27 19:43:27 +02:00
|
|
|
|
2018-02-18 00:29:55 +01:00
|
|
|
@objc func makeToolbarValidate() {
|
2017-05-27 19:43:27 +02:00
|
|
|
|
|
|
|
window?.toolbar?.validateVisibleItems()
|
|
|
|
}
|
2017-12-20 00:24:38 +01:00
|
|
|
|
2018-02-18 05:58:30 +01:00
|
|
|
// MARK: - NSUserInterfaceValidations
|
2017-05-27 19:43:27 +02:00
|
|
|
|
|
|
|
public func validateUserInterfaceItem(_ item: NSValidatedUserInterfaceItem) -> Bool {
|
|
|
|
|
|
|
|
if item.action == #selector(openArticleInBrowser(_:)) {
|
|
|
|
return currentLink != nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if item.action == #selector(nextUnread(_:)) {
|
|
|
|
return canGoToNextUnread()
|
|
|
|
}
|
|
|
|
|
|
|
|
if item.action == #selector(markAllAsRead(_:)) {
|
|
|
|
return canMarkAllAsRead()
|
|
|
|
}
|
2017-11-06 06:27:34 +01:00
|
|
|
|
|
|
|
if item.action == #selector(markRead(_:)) {
|
|
|
|
return canMarkRead()
|
|
|
|
}
|
|
|
|
|
2018-02-17 07:35:04 +01:00
|
|
|
if item.action == #selector(toggleStarred(_:)) {
|
|
|
|
return validateToggleStarred(item)
|
|
|
|
}
|
|
|
|
|
2017-12-25 21:21:44 +01:00
|
|
|
if item.action == #selector(markOlderArticlesAsRead(_:)) {
|
|
|
|
return canMarkOlderArticlesAsRead()
|
|
|
|
}
|
2017-12-26 21:50:34 +01:00
|
|
|
|
|
|
|
if item.action == #selector(toolbarShowShareMenu(_:)) {
|
|
|
|
return canShowShareMenu()
|
|
|
|
}
|
2018-02-08 06:42:33 +01:00
|
|
|
|
|
|
|
if item.action == #selector(toggleSidebar(_:)) {
|
|
|
|
|
|
|
|
guard let splitViewItem = sidebarSplitViewItem else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
let sidebarIsShowing = !splitViewItem.isCollapsed
|
|
|
|
if let menuItem = item as? NSMenuItem {
|
|
|
|
let title = sidebarIsShowing ? NSLocalizedString("Hide Sidebar", comment: "Menu item") : NSLocalizedString("Show Sidebar", comment: "Menu item")
|
|
|
|
menuItem.title = title
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2017-05-27 19:43:27 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2017-12-20 21:59:31 +01:00
|
|
|
// MARK: - Actions
|
|
|
|
|
|
|
|
@IBAction func scrollOrGoToNextUnread(_ sender: Any?) {
|
|
|
|
|
2017-12-20 22:39:31 +01:00
|
|
|
guard let detailViewController = detailViewController else {
|
|
|
|
return
|
|
|
|
}
|
2017-12-20 21:59:31 +01:00
|
|
|
|
2017-12-20 22:39:31 +01:00
|
|
|
detailViewController.canScrollDown { (canScroll) in
|
|
|
|
|
|
|
|
canScroll ? detailViewController.scrollPageDown(sender) : self.nextUnread(sender)
|
|
|
|
}
|
2017-12-20 21:59:31 +01:00
|
|
|
}
|
|
|
|
|
2018-02-12 03:58:50 +01:00
|
|
|
@IBAction func showAddFolderWindow(_ sender: Any?) {
|
2017-11-15 22:13:40 +01:00
|
|
|
|
2018-02-08 06:42:33 +01:00
|
|
|
appDelegate.showAddFolderSheetOnWindow(window!)
|
|
|
|
}
|
2018-02-04 06:30:30 +01:00
|
|
|
|
2018-02-12 03:58:50 +01:00
|
|
|
@IBAction func showAddFeedWindow(_ sender: Any?) {
|
2018-02-04 06:30:30 +01:00
|
|
|
|
|
|
|
appDelegate.showAddFeedSheetOnWindow(window!, urlString: nil, name: nil)
|
|
|
|
}
|
|
|
|
|
2017-12-20 21:59:31 +01:00
|
|
|
@IBAction func openArticleInBrowser(_ sender: Any?) {
|
2017-05-27 19:43:27 +02:00
|
|
|
|
|
|
|
if let link = currentLink {
|
2017-10-06 03:12:58 +02:00
|
|
|
Browser.open(link)
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
|
|
|
}
|
2017-12-20 21:59:31 +01:00
|
|
|
|
|
|
|
@IBAction func openInBrowser(_ sender: Any?) {
|
|
|
|
|
|
|
|
openArticleInBrowser(sender)
|
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func nextUnread(_ sender: Any?) {
|
2017-05-27 19:43:27 +02:00
|
|
|
|
|
|
|
guard let timelineViewController = timelineViewController, let sidebarViewController = sidebarViewController else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if timelineViewController.canGoToNextUnread() {
|
2017-12-24 07:18:42 +01:00
|
|
|
goToNextUnreadInTimeline()
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
|
|
|
else if sidebarViewController.canGoToNextUnread() {
|
|
|
|
sidebarViewController.goToNextUnread()
|
2017-12-24 07:18:42 +01:00
|
|
|
if timelineViewController.canGoToNextUnread() {
|
|
|
|
goToNextUnreadInTimeline()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-20 21:59:31 +01:00
|
|
|
@IBAction func markAllAsRead(_ sender: Any?) {
|
2017-05-27 19:43:27 +02:00
|
|
|
|
|
|
|
timelineViewController?.markAllAsRead()
|
|
|
|
}
|
2017-11-06 06:27:34 +01:00
|
|
|
|
2017-12-20 21:59:31 +01:00
|
|
|
@IBAction func markRead(_ sender: Any?) {
|
2017-11-06 06:27:34 +01:00
|
|
|
|
2017-12-20 21:59:31 +01:00
|
|
|
timelineViewController?.markSelectedArticlesAsRead(sender)
|
2017-11-06 06:27:34 +01:00
|
|
|
}
|
2017-12-20 21:59:31 +01:00
|
|
|
|
|
|
|
@IBAction func markUnread(_ sender: Any?) {
|
|
|
|
|
|
|
|
timelineViewController?.markSelectedArticlesAsUnread(sender)
|
|
|
|
}
|
|
|
|
|
2018-02-17 07:35:04 +01:00
|
|
|
@IBAction func toggleStarred(_ sender: Any?) {
|
|
|
|
|
|
|
|
timelineViewController?.toggleStarredStatusForSelectedArticles()
|
|
|
|
}
|
|
|
|
|
2017-12-21 06:23:48 +01:00
|
|
|
@IBAction func markAllAsReadAndGoToNextUnread(_ sender: Any?) {
|
|
|
|
|
|
|
|
markAllAsRead(sender)
|
|
|
|
nextUnread(sender)
|
|
|
|
}
|
|
|
|
|
2017-12-20 21:59:31 +01:00
|
|
|
@IBAction func markUnreadAndGoToNextUnread(_ sender: Any?) {
|
|
|
|
|
|
|
|
markUnread(sender)
|
|
|
|
nextUnread(sender)
|
|
|
|
}
|
|
|
|
|
2017-12-21 05:51:17 +01:00
|
|
|
@IBAction func markReadAndGoToNextUnread(_ sender: Any?) {
|
|
|
|
|
|
|
|
markUnread(sender)
|
|
|
|
nextUnread(sender)
|
|
|
|
}
|
|
|
|
|
2017-12-20 21:59:31 +01:00
|
|
|
@IBAction func toggleSidebar(_ sender: Any?) {
|
2017-05-27 19:43:27 +02:00
|
|
|
|
|
|
|
splitViewController!.toggleSidebar(sender)
|
|
|
|
}
|
2017-11-17 03:23:07 +01:00
|
|
|
|
2017-11-20 00:45:20 +01:00
|
|
|
@IBAction func markOlderArticlesAsRead(_ sender: Any?) {
|
2017-11-17 03:23:07 +01:00
|
|
|
|
2017-12-25 21:21:44 +01:00
|
|
|
timelineViewController?.markOlderArticlesAsRead()
|
2017-11-20 01:28:26 +01:00
|
|
|
}
|
2017-12-21 06:23:48 +01:00
|
|
|
|
|
|
|
@IBAction func navigateToTimeline(_ sender: Any?) {
|
|
|
|
|
|
|
|
timelineViewController?.focus()
|
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func navigateToSidebar(_ sender: Any?) {
|
|
|
|
|
|
|
|
sidebarViewController?.focus()
|
|
|
|
}
|
2017-12-21 23:43:29 +01:00
|
|
|
|
|
|
|
@IBAction func goToPreviousSubscription(_ sender: Any?) {
|
|
|
|
|
|
|
|
sidebarViewController?.outlineView.selectPreviousRow(sender)
|
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func goToNextSubscription(_ sender: Any?) {
|
|
|
|
|
|
|
|
sidebarViewController?.outlineView.selectNextRow(sender)
|
|
|
|
}
|
2017-12-26 21:50:34 +01:00
|
|
|
|
2018-01-27 21:39:07 +01:00
|
|
|
@IBAction func gotoToday(_ sender: Any?) {
|
|
|
|
|
|
|
|
sidebarViewController?.gotoToday(sender)
|
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func gotoAllUnread(_ sender: Any?) {
|
|
|
|
|
|
|
|
sidebarViewController?.gotoAllUnread(sender)
|
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func gotoStarred(_ sender: Any?) {
|
|
|
|
|
|
|
|
sidebarViewController?.gotoStarred(sender)
|
|
|
|
}
|
2018-01-28 00:04:45 +01:00
|
|
|
|
2017-12-26 21:50:34 +01:00
|
|
|
@IBAction func toolbarShowShareMenu(_ sender: Any?) {
|
|
|
|
|
|
|
|
guard let selectedArticles = selectedArticles, !selectedArticles.isEmpty else {
|
|
|
|
assertionFailure("Expected toolbarShowShareMenu to be called only when there are selected articles.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
guard let shareToolbarItem = shareToolbarItem else {
|
|
|
|
assertionFailure("Expected toolbarShowShareMenu to be called only by the Share item in the toolbar.")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
guard let view = shareToolbarItem.view else {
|
|
|
|
// TODO: handle menu form representation
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let items = selectedArticles.map { ArticlePasteboardWriter(article: $0) }
|
|
|
|
let sharingServicePicker = NSSharingServicePicker(items: items)
|
2018-02-18 05:33:30 +01:00
|
|
|
sharingServicePicker.delegate = sharingServicePickerDelegate
|
2017-12-26 21:50:34 +01:00
|
|
|
sharingServicePicker.show(relativeTo: view.bounds, of: view, preferredEdge: .minY)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-08 09:11:52 +01:00
|
|
|
// MARK: - Scripting Access
|
|
|
|
|
|
|
|
/*
|
|
|
|
the ScriptingMainWindowController protocol exposes a narrow set of accessors with
|
|
|
|
internal visibility which are very similar to some private vars.
|
|
|
|
|
|
|
|
These would be unnecessary if the similar accessors were marked internal rather than private,
|
|
|
|
but for now, we'll keep the stratification of visibility
|
|
|
|
*/
|
|
|
|
|
|
|
|
extension MainWindowController : ScriptingMainWindowController {
|
|
|
|
|
|
|
|
internal var scriptingCurrentArticle: Article? {
|
|
|
|
return self.oneSelectedArticle
|
|
|
|
}
|
|
|
|
|
|
|
|
internal var scriptingSelectedArticles: [Article] {
|
|
|
|
return self.selectedArticles ?? []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-06 05:03:35 +02:00
|
|
|
// MARK: - Private
|
|
|
|
|
2017-05-27 19:43:27 +02:00
|
|
|
private extension MainWindowController {
|
|
|
|
|
|
|
|
var splitViewController: NSSplitViewController? {
|
2018-02-08 06:42:33 +01:00
|
|
|
guard let viewController = contentViewController else {
|
|
|
|
return nil
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
2018-02-08 06:42:33 +01:00
|
|
|
return viewController.childViewControllers.first as? NSSplitViewController
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var sidebarViewController: SidebarViewController? {
|
2018-02-08 06:42:33 +01:00
|
|
|
return splitViewController?.splitViewItems[0].viewController as? SidebarViewController
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var timelineViewController: TimelineViewController? {
|
2018-02-08 06:42:33 +01:00
|
|
|
return splitViewController?.splitViewItems[1].viewController as? TimelineViewController
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
2018-02-08 06:42:33 +01:00
|
|
|
|
|
|
|
var sidebarSplitViewItem: NSSplitViewItem? {
|
|
|
|
return splitViewController?.splitViewItems[0]
|
|
|
|
}
|
|
|
|
|
2017-05-27 19:43:27 +02:00
|
|
|
var detailSplitViewItem: NSSplitViewItem? {
|
2018-02-08 06:42:33 +01:00
|
|
|
return splitViewController?.splitViewItems[2]
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var detailViewController: DetailViewController? {
|
2018-02-08 06:42:33 +01:00
|
|
|
return splitViewController?.splitViewItems[2].viewController as? DetailViewController
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var selectedArticles: [Article]? {
|
2018-02-08 06:42:33 +01:00
|
|
|
return timelineViewController?.selectedArticles
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
2018-02-08 06:42:33 +01:00
|
|
|
|
2017-05-27 19:43:27 +02:00
|
|
|
var oneSelectedArticle: Article? {
|
2018-02-08 06:42:33 +01:00
|
|
|
if let articles = selectedArticles {
|
|
|
|
return articles.count == 1 ? articles[0] : nil
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
2018-02-08 06:42:33 +01:00
|
|
|
return nil
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
2018-02-08 06:42:33 +01:00
|
|
|
|
2017-05-27 19:43:27 +02:00
|
|
|
var currentLink: String? {
|
2018-02-08 06:42:33 +01:00
|
|
|
return oneSelectedArticle?.preferredLink
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
2018-02-08 06:42:33 +01:00
|
|
|
|
2018-02-18 05:58:30 +01:00
|
|
|
// MARK: - Command Validation
|
|
|
|
|
2017-05-27 19:43:27 +02:00
|
|
|
func canGoToNextUnread() -> Bool {
|
|
|
|
|
|
|
|
guard let timelineViewController = timelineViewController, let sidebarViewController = sidebarViewController else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return timelineViewController.canGoToNextUnread() || sidebarViewController.canGoToNextUnread()
|
|
|
|
}
|
|
|
|
|
|
|
|
func canMarkAllAsRead() -> Bool {
|
|
|
|
|
|
|
|
return timelineViewController?.canMarkAllAsRead() ?? false
|
|
|
|
}
|
2017-10-19 06:53:45 +02:00
|
|
|
|
2017-11-06 06:27:34 +01:00
|
|
|
func canMarkRead() -> Bool {
|
|
|
|
|
|
|
|
return timelineViewController?.canMarkSelectedArticlesAsRead() ?? false
|
|
|
|
}
|
2017-12-25 21:21:44 +01:00
|
|
|
|
|
|
|
func canMarkOlderArticlesAsRead() -> Bool {
|
|
|
|
|
|
|
|
return timelineViewController?.canMarkOlderArticlesAsRead() ?? false
|
|
|
|
}
|
|
|
|
|
2018-02-18 05:58:30 +01:00
|
|
|
func canShowShareMenu() -> Bool {
|
|
|
|
|
|
|
|
guard let selectedArticles = selectedArticles else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return !selectedArticles.isEmpty
|
|
|
|
}
|
|
|
|
|
|
|
|
func validateToggleStarred(_ item: NSValidatedUserInterfaceItem) -> Bool {
|
|
|
|
|
|
|
|
let validationStatus = timelineViewController?.markStarredCommandStatus() ?? .canDoNothing
|
|
|
|
let starring: Bool
|
|
|
|
let result: Bool
|
|
|
|
|
|
|
|
switch validationStatus {
|
|
|
|
case .canMark:
|
|
|
|
starring = true
|
|
|
|
result = true
|
|
|
|
case .canUnmark:
|
|
|
|
starring = false
|
|
|
|
result = true
|
|
|
|
case .canDoNothing:
|
|
|
|
starring = true
|
|
|
|
result = false
|
|
|
|
}
|
|
|
|
|
|
|
|
let commandName = starring ? NSLocalizedString("Mark as Starred", comment: "Command") : NSLocalizedString("Mark as Unstarred", comment: "Command")
|
|
|
|
|
|
|
|
if let toolbarItem = item as? NSToolbarItem {
|
|
|
|
toolbarItem.toolTip = commandName
|
|
|
|
if let button = toolbarItem.view as? NSButton {
|
|
|
|
button.image = NSImage(named: starring ? .star : .unstar)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if let menuItem = item as? NSMenuItem {
|
|
|
|
menuItem.title = commandName
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Misc.
|
|
|
|
|
|
|
|
func goToNextUnreadInTimeline() {
|
|
|
|
|
|
|
|
guard let timelineViewController = timelineViewController else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if timelineViewController.canGoToNextUnread() {
|
|
|
|
timelineViewController.goToNextUnread()
|
|
|
|
makeTimelineViewFirstResponder()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeTimelineViewFirstResponder() {
|
|
|
|
|
|
|
|
guard let window = window, let timelineViewController = timelineViewController else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
window.makeFirstResponderUnlessDescendantIsFirstResponder(timelineViewController.tableView)
|
|
|
|
}
|
|
|
|
|
2017-10-19 06:53:45 +02:00
|
|
|
func updateWindowTitle() {
|
|
|
|
|
|
|
|
if unreadCount < 1 {
|
2017-11-25 07:05:10 +01:00
|
|
|
window?.title = appDelegate.appName!
|
2017-10-19 06:53:45 +02:00
|
|
|
}
|
|
|
|
else if unreadCount > 0 {
|
2017-11-25 07:05:10 +01:00
|
|
|
window?.title = "\(appDelegate.appName!) (\(unreadCount))"
|
2017-10-19 06:53:45 +02:00
|
|
|
}
|
|
|
|
}
|
2018-02-27 07:31:07 +01:00
|
|
|
|
|
|
|
func saveSplitViewState() {
|
|
|
|
|
|
|
|
// TODO: Update this for multiple windows.
|
|
|
|
|
|
|
|
guard let splitView = splitViewController?.splitView else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let widths = splitView.arrangedSubviews.map{ Int(floor($0.frame.width)) }
|
|
|
|
AppDefaults.shared.mainWindowWidths = widths
|
|
|
|
}
|
|
|
|
|
|
|
|
func restoreSplitViewState() {
|
|
|
|
|
|
|
|
// TODO: Update this for multiple windows.
|
|
|
|
|
|
|
|
guard let splitView = splitViewController?.splitView, let widths = AppDefaults.shared.mainWindowWidths, widths.count == 3, let window = window else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let windowWidth = Int(floor(window.frame.width))
|
|
|
|
let dividerThickness: Int = Int(splitView.dividerThickness)
|
|
|
|
let sidebarWidth: Int = widths[0]
|
|
|
|
let timelineWidth: Int = widths[1]
|
|
|
|
|
|
|
|
// Make sure the detail view has its mimimum thickness, at least.
|
|
|
|
if windowWidth < sidebarWidth + dividerThickness + timelineWidth + dividerThickness + MainWindowController.detailViewMinimumThickness {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
splitView.setPosition(CGFloat(sidebarWidth), ofDividerAt: 0)
|
|
|
|
splitView.setPosition(CGFloat(sidebarWidth + dividerThickness + timelineWidth), ofDividerAt: 1)
|
|
|
|
}
|
2017-05-27 19:43:27 +02:00
|
|
|
}
|
|
|
|
|