Show unread count in window title.
This commit is contained in:
parent
2383ecd480
commit
3812c216b2
|
@ -17,6 +17,13 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
|||
// MARK: NSWindowController
|
||||
|
||||
private let windowAutosaveName = NSWindow.FrameAutosaveName(rawValue: kWindowFrameKey)
|
||||
private var unreadCount: Int = 0 {
|
||||
didSet {
|
||||
if unreadCount != oldValue {
|
||||
updateWindowTitle()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func windowDidLoad() {
|
||||
|
||||
|
@ -33,7 +40,13 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
|||
NotificationCenter.default.addObserver(self, selector: #selector(refreshProgressDidChange(_:)), name: .AccountRefreshDidBegin, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(refreshProgressDidChange(_:)), name: .AccountRefreshDidFinish, object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(refreshProgressDidChange(_:)), name: .AccountRefreshProgressDidChange, object: nil)
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil)
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.updateWindowTitle()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Notifications
|
||||
|
||||
|
@ -58,7 +71,14 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
|||
|
||||
rs_performSelectorCoalesced(#selector(MainWindowController.makeToolbarValidate(_:)), with: nil, afterDelay: 0.1)
|
||||
}
|
||||
|
||||
|
||||
@objc func unreadCountDidChange(_ note: Notification) {
|
||||
|
||||
if note.object is AccountManager {
|
||||
unreadCount = AccountManager.shared.unreadCount
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Toolbar
|
||||
|
||||
@objc func makeToolbarValidate(_ sender: Any) {
|
||||
|
@ -101,6 +121,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
|
|||
}
|
||||
|
||||
func makeTimelineViewFirstResponder() {
|
||||
|
||||
window!.makeFirstResponderUnlessDescendantIsFirstResponder(timelineViewController.tableView)
|
||||
}
|
||||
|
||||
|
@ -196,5 +217,15 @@ private extension MainWindowController {
|
|||
|
||||
return timelineViewController?.canMarkAllAsRead() ?? false
|
||||
}
|
||||
|
||||
func updateWindowTitle() {
|
||||
|
||||
if unreadCount < 1 {
|
||||
window?.title = appName
|
||||
}
|
||||
else if unreadCount > 0 {
|
||||
window?.title = "\(appName) (\(unreadCount))"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -175,12 +175,28 @@ private extension SidebarViewController {
|
|||
let appInfo = AppInfo()
|
||||
if let selectedObjects = selectedObjects {
|
||||
appInfo.objects = selectedObjects
|
||||
updateUnreadCounts(for: selectedObjects)
|
||||
}
|
||||
appInfo.view = outlineView
|
||||
|
||||
NotificationCenter.default.post(name: .SidebarSelectionDidChange, object: self, userInfo: appInfo.userInfo)
|
||||
}
|
||||
|
||||
func updateUnreadCounts(for objects: [AnyObject]) {
|
||||
|
||||
// On selection, update unread counts for folders and feeds.
|
||||
// For feeds, actually fetch from database.
|
||||
|
||||
for object in objects {
|
||||
if let feed = object as? Feed, let account = feed.account {
|
||||
account.updateUnreadCounts(for: Set([feed]))
|
||||
}
|
||||
else if let folder = object as? Folder {
|
||||
folder.account.updateUnreadCounts(for: folder.flattenedFeeds())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func nodeForItem(_ item: AnyObject?) -> Node {
|
||||
|
||||
if item == nil {
|
||||
|
|
|
@ -265,6 +265,10 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
|||
|
||||
public func updateUnreadCounts(for feeds: Set<Feed>) {
|
||||
|
||||
if feeds.isEmpty {
|
||||
return
|
||||
}
|
||||
|
||||
database.fetchUnreadCounts(for: feeds) { (unreadCountDictionary) in
|
||||
|
||||
for feed in feeds {
|
||||
|
|
15
ToDo.opml
15
ToDo.opml
|
@ -6,27 +6,28 @@
|
|||
</editor> -->
|
||||
<title>ToDo</title>
|
||||
<dateCreated>Tue, 12 Sep 2017 20:15:17 GMT</dateCreated>
|
||||
<expansionState>0,22,23,26,30,36,44,45,47,62,67</expansionState>
|
||||
<expansionState>0,12,20,23,24,27,31,37,45,46,48,63,68</expansionState>
|
||||
<vertScrollState>0</vertScrollState>
|
||||
<windowTop>3254</windowTop>
|
||||
<windowLeft>551</windowLeft>
|
||||
<windowRight>1283</windowRight>
|
||||
<windowBottom>4013</windowBottom>
|
||||
<windowTop>581</windowTop>
|
||||
<windowLeft>54</windowLeft>
|
||||
<windowRight>786</windowRight>
|
||||
<windowBottom>1340</windowBottom>
|
||||
</head>
|
||||
<body>
|
||||
<outline text="App">
|
||||
<outline text="Make adding a Folder work — accounts don’t show up in Accounts popup"/>
|
||||
<outline text="Make adding a Folder work — the sidebar should update"/>
|
||||
<outline text="Update Sparkle"/>
|
||||
<outline text="Use new app icon"/>
|
||||
<outline text="Set -NSApplicationCrashOnExceptions YES"/>
|
||||
<outline text="Store colors in accent catalog"/>
|
||||
<outline text="Use NSBox for container"/>
|
||||
<outline text="Restorable state"/>
|
||||
<outline text="Use new build system"/>
|
||||
<outline text="NSError.setUserInfoValueProvider"/>
|
||||
<outline text="NSDictionary.sharedKeySet"/>
|
||||
<outline text="Update unread count on selecting feed, in case it’s out of sync"/>
|
||||
<outline text="Periodic refresh"/>
|
||||
<outline text="OPML Import">
|
||||
<outline text="Finish implementation in Account"/>
|
||||
<outline text="Accessory view in choose-file sheet for choosing account"/>
|
||||
<outline text="Import from URL">
|
||||
<outline text="Sheet with URL text field and account popup"/>
|
||||
|
|
Loading…
Reference in New Issue