diff --git a/Evergreen/ArticleStyles/ArticleStylesManager.swift b/Evergreen/ArticleStyles/ArticleStylesManager.swift index 6014f4f34..a09f502ca 100644 --- a/Evergreen/ArticleStyles/ArticleStylesManager.swift +++ b/Evergreen/ArticleStyles/ArticleStylesManager.swift @@ -66,7 +66,7 @@ public final class ArticleStylesManager { updateStyleNames() updateCurrentStyle() - NotificationCenter.default.addObserver(self, selector: #selector(applicationDidBecomeActive(_:)), name: NSNotification.Name.NSApplication.didBecomeActiveNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(applicationDidBecomeActive(_:)), name: NSNotification.Name.NSApplicationDidBecomeActiveNotification, object: nil) } // MARK: Notifications diff --git a/Evergreen/Data/ArticleUtilities.swift b/Evergreen/Data/ArticleUtilities.swift index a8b516b7b..2024cf5fa 100644 --- a/Evergreen/Data/ArticleUtilities.swift +++ b/Evergreen/Data/ArticleUtilities.swift @@ -12,51 +12,39 @@ import Account // These handle multiple accounts. -func markArticles(_ articles: NSSet, statusKey: ArticleStatusKey, flag: Bool) { +func markArticles(_ articles: Set
, statusKey: String, flag: Bool) { - let d: [String: NSSet] = accountAndArticlesDictionary(articles) + let d: [String: Set
] = accountAndArticlesDictionary(articles) - d.keys.forEach { (oneAccountIdentifier) in + d.keys.forEach { (accountID) in - guard let oneAccountArticles = d[oneAccountIdentifier], let oneAccount = accountWithIdentifier(oneAccountIdentifier) else { + guard let accountArticles = d[accountID], let account = accountWithID(accountID) else { return } - oneAccount.markArticles(oneAccountArticles, statusKey: statusKey, flag: flag) + account.markArticles(accountArticles, statusKey: statusKey, flag: flag) } } -private func accountAndArticlesDictionary(_ articles: NSSet) -> [String: NSSet] { +private func accountAndArticlesDictionary(_ articles: Set
) -> [String: Set
] { - var d = [String: NSMutableSet]() + var d = [String: Set
]() - articles.forEach { (oneObject) in + articles.forEach { (article) in - guard let oneArticle = oneObject as? Article else { - return - } - guard let oneAccountIdentifier = oneArticle.account?.accountID else { - return - } - - let oneArticleSet: NSMutableSet = d[oneAccountIdentifier] ?? NSMutableSet() - oneArticleSet.add(oneArticle) - d[oneAccountIdentifier] = oneArticleSet + let accountID = article.accountID + var articleSet: Set
= d[accountID] ?? Set
() + articleSet.insert(article) + d[accountID] = articleSet } return d } -private func accountWithID(_ accountID: String) -> Account? { - - return AccountManager.sharedInstance.existingAccountWithIdentifier(accountID) -} - -func preferredLink(for article: Article) -> String? { +extension Article { - if let s = article.permalink { - return s + func preferredLink() -> String? { + + return url ?? externalURL } - return article.link } - diff --git a/Evergreen/MainWindow/AddFeed/AddFeedController.swift b/Evergreen/MainWindow/AddFeed/AddFeedController.swift index 30312f69d..12e40dae8 100644 --- a/Evergreen/MainWindow/AddFeed/AddFeedController.swift +++ b/Evergreen/MainWindow/AddFeed/AddFeedController.swift @@ -58,7 +58,7 @@ class AddFeedController: AddFeedWindowControllerDelegate, FeedFinderDelegate { func addFeedWindowController(_: AddFeedWindowController, userEnteredURL url: URL, userEnteredTitle title: String?, folder: Folder) { - closeAddFeedSheet(NSModalResponseOK) + closeAddFeedSheet(NSApplication.ModalResponse.OK) assert(folder.account != nil, "Folder must have an account.") let account = folder.account ?? AccountManager.sharedInstance.localAccount @@ -77,7 +77,7 @@ class AddFeedController: AddFeedWindowControllerDelegate, FeedFinderDelegate { func addFeedWindowControllerUserDidCancel(_: AddFeedWindowController) { - closeAddFeedSheet(NSModalResponseCancel) + closeAddFeedSheet(NSApplication.ModalResponse.cancel) } // MARK: FeedFinderDelegate @@ -128,14 +128,14 @@ private extension AddFeedController { var urlStringFromPasteboard: String? { get { - if let urlString = NSPasteboard.rs_urlString(from: NSPasteboard.general()) { + if let urlString = NSPasteboard.rs_urlString(from: NSPasteboard.general) { return urlString.rs_normalizedURL() } return nil } } - func closeAddFeedSheet(_ returnCode: NSModalResponse) { + func closeAddFeedSheet(_ returnCode: NSApplication.ModalResponse) { if let sheetWindow = addFeedWindowController?.window { hostWindow.endSheet(sheetWindow, returnCode: returnCode) diff --git a/Evergreen/MainWindow/AddFeed/AddFeedWindowController.swift b/Evergreen/MainWindow/AddFeed/AddFeedWindowController.swift index 5c43aaf4e..7aae030c1 100644 --- a/Evergreen/MainWindow/AddFeed/AddFeedWindowController.swift +++ b/Evergreen/MainWindow/AddFeed/AddFeedWindowController.swift @@ -112,7 +112,7 @@ class AddFeedWindowController : NSWindowController { @IBAction func localShowFeedList(_ sender: AnyObject) { NSApplication.shared.sendAction(NSSelectorFromString("showFeedList:"), to: nil, from: sender) - hostWindow.endSheet(window!, returnCode: NSModalResponseContinue) + hostWindow.endSheet(window!, returnCode: NSApplication.ModalResponse.continue) } // MARK: NSTextFieldDelegate diff --git a/Evergreen/MainWindow/AddFolder/AddFolderWindowController.swift b/Evergreen/MainWindow/AddFolder/AddFolderWindowController.swift index fd85227f4..6a40baa2b 100644 --- a/Evergreen/MainWindow/AddFolder/AddFolderWindowController.swift +++ b/Evergreen/MainWindow/AddFolder/AddFolderWindowController.swift @@ -8,6 +8,7 @@ import Cocoa import Data +import Account //func addFolderWindowController() -> AddFolderWindowController { // @@ -22,7 +23,7 @@ class AddFolderWindowController : NSWindowController { convenience init() { - self.init(windowNibName: "AddFolderSheet") + self.init(windowNibName: NSNib.Name(rawValue: "AddFolderSheet")) } // MARK: API @@ -30,9 +31,9 @@ class AddFolderWindowController : NSWindowController { func runSheetOnWindow(_ w: NSWindow) { hostWindow = w - hostWindow!.beginSheet(window!) { (returnCode: NSModalResponse) -> Void in + hostWindow!.beginSheet(window!) { (returnCode: NSApplication.ModalResponse) -> Void in - if returnCode == NSModalResponseOK { + if returnCode == NSApplication.ModalResponse.OK { self.addFolderIfNeeded() } } @@ -74,12 +75,12 @@ class AddFolderWindowController : NSWindowController { @IBAction func cancel(_ sender: AnyObject) { - hostWindow!.endSheet(window!, returnCode: NSModalResponseCancel) + hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.cancel) } @IBAction func addFolder(_ sender: AnyObject) { - hostWindow!.endSheet(window!, returnCode: NSModalResponseOK) + hostWindow!.endSheet(window!, returnCode: NSApplication.ModalResponse.OK) } } diff --git a/Evergreen/MainWindow/Detail/DetailViewController.swift b/Evergreen/MainWindow/Detail/DetailViewController.swift index 112449bb0..6b4c5d687 100644 --- a/Evergreen/MainWindow/Detail/DetailViewController.swift +++ b/Evergreen/MainWindow/Detail/DetailViewController.swift @@ -48,7 +48,7 @@ class DetailViewController: NSViewController, WKNavigationDelegate, WKUIDelegate // MARK: Notifications - func timelineSelectionDidChange(_ note: Notification) { + @objc func timelineSelectionDidChange(_ note: Notification) { let timelineView = note.userInfo?[viewKey] as! NSView diff --git a/Evergreen/MainWindow/MainWindowController.swift b/Evergreen/MainWindow/MainWindowController.swift index a74dfc3e1..abd6e1759 100644 --- a/Evergreen/MainWindow/MainWindowController.swift +++ b/Evergreen/MainWindow/MainWindowController.swift @@ -20,7 +20,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations { super.windowDidLoad() // window?.titleVisibility = .hidden - window?.setFrameUsingName(kWindowFrameKey, force: true) + window?.setFrameUsingName(NSWindow.FrameAutosaveName(rawValue: kWindowFrameKey), force: true) detailSplitViewItem?.minimumThickness = 384 @@ -33,12 +33,12 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations { // MARK: Notifications - func applicationWillTerminate(_ note: Notification) { + @objc func applicationWillTerminate(_ note: Notification) { - window?.saveFrame(usingName: kWindowFrameKey) + window?.saveFrame(usingName: NSWindow.FrameAutosaveName(rawValue: kWindowFrameKey)) } - func appNavigationKeyPressed(_ note: Notification) { + @objc func appNavigationKeyPressed(_ note: Notification) { guard let key = note.userInfo?[appNavigationKey] as? Int else { return @@ -50,14 +50,14 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations { print(key) } - func refreshProgressDidChange(_ note: Notification) { + @objc func refreshProgressDidChange(_ note: Notification) { rs_performSelectorCoalesced(#selector(MainWindowController.coalescedMakeToolbarValidate(_:)), with: nil, afterDelay: 0.1) } // MARK: Toolbar - func coalescedMakeToolbarValidate(_ sender: Any) { + @objc func coalescedMakeToolbarValidate(_ sender: Any) { window?.toolbar?.validateVisibleItems() } diff --git a/Evergreen/MainWindow/Sidebar/SidebarViewController.swift b/Evergreen/MainWindow/Sidebar/SidebarViewController.swift index 5841d26c6..14a6d8f8e 100644 --- a/Evergreen/MainWindow/Sidebar/SidebarViewController.swift +++ b/Evergreen/MainWindow/Sidebar/SidebarViewController.swift @@ -103,14 +103,14 @@ import Account outlineView.selectRowIndexes(IndexSet([row]), byExtendingSelection: false) - NSApplication.shared().sendAction(NSSelectorFromString("nextUnread:"), to: nil, from: self) + NSApplication.shared.sendAction(NSSelectorFromString("nextUnread:"), to: nil, from: self) } // MARK: NSOutlineViewDelegate func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? { - let cell = outlineView.make(withIdentifier: "DataCell", owner: self) as! SidebarCell + let cell = outlineView.make(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "DataCell"), owner: self) as! SidebarCell let node = item as! Node configure(cell, node) diff --git a/Evergreen/MainWindow/StatusBar/StatusBarView.swift b/Evergreen/MainWindow/StatusBar/StatusBarView.swift index 363b90418..66dc2a817 100644 --- a/Evergreen/MainWindow/StatusBar/StatusBarView.swift +++ b/Evergreen/MainWindow/StatusBar/StatusBarView.swift @@ -33,7 +33,7 @@ final class StatusBarView: NSView { override func awakeFromNib() { let progressLabelFontSize = progressLabel.font?.pointSize ?? 13.0 - progressLabel.font = NSFont.monospacedDigitSystemFont(ofSize: progressLabelFontSize, weight: NSFontWeightRegular) + progressLabel.font = NSFont.monospacedDigitSystemFont(ofSize: progressLabelFontSize, weight: NSFont.Weight.regular) progressLabel.stringValue = "" NotificationCenter.default.addObserver(self, selector: #selector(progressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil) @@ -91,7 +91,7 @@ private extension StatusBarView { return } - let s = preferredLink(for: article) + let s = article.preferredLink() if let s = s { urlLabel.stringValue = (s as NSString).rs_stringByStrippingHTTPOrHTTPSScheme() } diff --git a/Evergreen/MainWindow/Timeline/Cell/TimelineStringUtilities.swift b/Evergreen/MainWindow/Timeline/Cell/TimelineStringUtilities.swift index 87399b5b8..c003231e3 100644 --- a/Evergreen/MainWindow/Timeline/Cell/TimelineStringUtilities.swift +++ b/Evergreen/MainWindow/Timeline/Cell/TimelineStringUtilities.swift @@ -8,6 +8,7 @@ import Foundation import Data +import RSParser private let truncatedFeedNameCache = NSMutableDictionary() private let truncatedTitleCache = NSMutableDictionary() @@ -102,7 +103,7 @@ func timelineNormalizedTextTruncated(_ text: String) -> String { return cachedText } - var s: NSString = (text as NSString).rs_stringByDecodingHTMLEntities() as NSString + var s: NSString = (text as NSString).rsparser_stringByDecodingHTMLEntities() as NSString s = s.rs_stringByTrimmingWhitespace() as NSString s = s.rs_stringWithCollapsedWhitespace() as NSString diff --git a/Evergreen/MainWindow/Timeline/TimelineViewController.swift b/Evergreen/MainWindow/Timeline/TimelineViewController.swift index de6300e87..eb28dd0a8 100644 --- a/Evergreen/MainWindow/Timeline/TimelineViewController.swift +++ b/Evergreen/MainWindow/Timeline/TimelineViewController.swift @@ -78,7 +78,7 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView NotificationCenter.default.addObserver(self, selector: #selector(sidebarSelectionDidChange(_:)), name: .SidebarSelectionDidChange, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(articleStatusesDidChange(_:)), name: .ArticleStatusesDidChange, object: nil) - NSUserDefaultsController.shared().addObserver(self, forKeyPath:timelineFontSizeKVOKey, options: NSKeyValueObservingOptions(rawValue: 0), context: nil) + NSUserDefaultsController.shared.addObserver(self, forKeyPath:timelineFontSizeKVOKey, options: NSKeyValueObservingOptions(rawValue: 0), context: nil) didRegisterForNotifications = true } @@ -133,7 +133,7 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView // MARK: Actions - func openArticleInBrowser(_ sender: AnyObject) { + @objc func openArticleInBrowser(_ sender: AnyObject) { guard let article = oneSelectedArticle else { return @@ -221,7 +221,7 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView // MARK: Notifications - func sidebarSelectionDidChange(_ note: Notification) { + @objc func sidebarSelectionDidChange(_ note: Notification) { let sidebarView = note.userInfo?[viewKey] as! NSView @@ -230,7 +230,7 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView } } - func articleStatusesDidChange(_ note: Notification) { + @objc func articleStatusesDidChange(_ note: Notification) { guard let articles = note.userInfo?[articlesKey] as? NSSet else { return diff --git a/Evergreen/ProgressWindow/IndeterminateProgressWindowController.swift b/Evergreen/ProgressWindow/IndeterminateProgressWindowController.swift index 1b62da467..644570852 100644 --- a/Evergreen/ProgressWindow/IndeterminateProgressWindowController.swift +++ b/Evergreen/ProgressWindow/IndeterminateProgressWindowController.swift @@ -16,7 +16,7 @@ class IndeterminateProgressWindowController: NSWindowController { convenience init(message: String) { - self.init(windowNibName: "IndeterminateProgressWindow") + self.init(windowNibName: NSNib.Name(rawValue: "IndeterminateProgressWindow")) self.message = message } @@ -29,10 +29,10 @@ class IndeterminateProgressWindowController: NSWindowController { func runIndeterminateProgressWithMessage(_ message: String) { let windowController = IndeterminateProgressWindowController(message: message) - NSApplication.shared().runModal(for: windowController.window!) + NSApplication.shared.runModal(for: windowController.window!) } func stopIndeterminateProgress() { - NSApplication.shared().stopModal() + NSApplication.shared.stopModal() } diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index 21beb4a47..5be79a9db 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -65,6 +65,11 @@ public final class Account: DisplayNameProvider, Hashable { // TODO } + public func markArticles(_ articles: Set
, statusKey: String, flag: Bool) { + + // TODO + } + // MARK: - Equatable public class func ==(lhs: Account, rhs: Account) -> Bool { diff --git a/Frameworks/Account/AccountManager.swift b/Frameworks/Account/AccountManager.swift index 7ffd4b5ea..a29397aac 100644 --- a/Frameworks/Account/AccountManager.swift +++ b/Frameworks/Account/AccountManager.swift @@ -34,7 +34,7 @@ public final class AccountManager: UnreadCountProvider { } } - var sortedAccounts: [Account] { + public var sortedAccounts: [Account] { get { return accountsSortedByName() } @@ -191,6 +191,12 @@ private func accountFilePathWithFolder(_ folderPath: String) -> String { return NSString(string: folderPath).appendingPathComponent(accountDataFileName) } +public func accountWithID(_ accountID: String) -> Account? { + + // Shortcut. + return AccountManager.sharedInstance.existingAccountWithID(accountID) +} + private struct AccountSpecifier { let type: String diff --git a/Frameworks/Account/Extensions/Article+Account.swift b/Frameworks/Account/Extensions/Article+Account.swift index 44e4940a5..796ad7dc4 100644 --- a/Frameworks/Account/Extensions/Article+Account.swift +++ b/Frameworks/Account/Extensions/Article+Account.swift @@ -13,7 +13,7 @@ public extension Article { var account: Account? { get { - return AccountManager.sharedInstance.existingAccountWithID(accountID) + return accountWithID(accountID) } } } diff --git a/Frameworks/Account/Extensions/Feed+Account.swift b/Frameworks/Account/Extensions/Feed+Account.swift index 71474cd65..3f032fecc 100644 --- a/Frameworks/Account/Extensions/Feed+Account.swift +++ b/Frameworks/Account/Extensions/Feed+Account.swift @@ -13,7 +13,7 @@ public extension Feed { var account: Account? { get { - return AccountManager.sharedInstance.existingAccountWithID(accountID) + return accountWithID(accountID) } } } diff --git a/Frameworks/Account/Folder.swift b/Frameworks/Account/Folder.swift index 07594d2a1..d34c98597 100644 --- a/Frameworks/Account/Folder.swift +++ b/Frameworks/Account/Folder.swift @@ -13,7 +13,13 @@ public final class Folder: DisplayNameProvider, UnreadCountProvider { public let accountID: String var childObjects = [AnyObject]() - + + public var account: Account? { + get { + return accountWithID(accountID) + } + } + // MARK: - DisplayNameProvider public var nameForDisplay: String