Adds checkmarks

Also adds notification to keep Inspector in sync.
This commit is contained in:
Stuart Breckenridge 2021-02-02 10:26:34 +08:00
parent 6b1ad170ca
commit 62ed7492eb
No known key found for this signature in database
GPG Key ID: ED2F112EEA9EF8A5
2 changed files with 25 additions and 13 deletions

View File

@ -50,6 +50,7 @@ final class WebFeedInspectorViewController: NSViewController, Inspector {
override func viewDidLoad() {
updateUI()
NotificationCenter.default.addObserver(self, selector: #selector(imageDidBecomeAvailable(_:)), name: .ImageDidBecomeAvailable, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(updateUI), name: .DidUpdateFeedPreferencesFromContextMenu, object: nil)
}
override func viewDidAppear() {
@ -129,7 +130,8 @@ private extension WebFeedInspectorViewController {
feed = singleFeed
}
func updateUI() {
@objc func updateUI() {
updateImage()
updateName()
updateHomePageURL()

View File

@ -11,6 +11,10 @@ import Articles
import Account
import RSCore
extension Notification.Name {
public static let DidUpdateFeedPreferencesFromContextMenu = Notification.Name(rawValue: "DidUpdateFeedPreferencesFromContextMenu")
}
extension SidebarViewController {
func menu(for objects: [Any]?) -> NSMenu? {
@ -105,6 +109,7 @@ extension SidebarViewController {
return
}
feed.isNotifyAboutNewArticles?.toggle()
NotificationCenter.default.post(Notification(name: .DidUpdateFeedPreferencesFromContextMenu))
}
@objc func toggleArticleExtractorFromContextMenu(_ sender: Any?) {
@ -113,6 +118,7 @@ extension SidebarViewController {
return
}
feed.isArticleExtractorAlwaysOn?.toggle()
NotificationCenter.default.post(Notification(name: .DidUpdateFeedPreferencesFromContextMenu))
}
}
@ -181,21 +187,25 @@ private extension SidebarViewController {
}
menu.addItem(NSMenuItem.separator())
var notificationText: String!
if webFeed.isNotifyAboutNewArticles != nil && webFeed.isNotifyAboutNewArticles! {
notificationText = NSLocalizedString("Disable New Article Notifications", comment: "Disable Notifications")
} else {
notificationText = NSLocalizedString("Enable New Article Notifications", comment: "Enable Notifications")
}
menu.addItem(menuItem(notificationText, #selector(toggleNotificationsFromContextMenu(_:)), webFeed))
let notificationText = NSLocalizedString("Show Notifications for New Articles", comment: "Show Notifications for New Articles")
var articleExtractorText: String!
if webFeed.isArticleExtractorAlwaysOn != nil && webFeed.isArticleExtractorAlwaysOn! {
articleExtractorText = NSLocalizedString("Disable Reader View", comment: "Disable Reader View")
let notificationMenuItem = menuItem(notificationText, #selector(toggleNotificationsFromContextMenu(_:)), webFeed)
if webFeed.isNotifyAboutNewArticles == nil || webFeed.isNotifyAboutNewArticles! == false {
notificationMenuItem.state = .off
} else {
articleExtractorText = NSLocalizedString("Enable Reader View", comment: "Enable Reader View")
notificationMenuItem.state = .on
}
menu.addItem(menuItem(articleExtractorText, #selector(toggleArticleExtractorFromContextMenu(_:)), webFeed))
menu.addItem(notificationMenuItem)
let articleExtractorText = NSLocalizedString("Always Use Reader View", comment: "Always Use Reader View")
let articleExtractorMenuItem = menuItem(articleExtractorText, #selector(toggleArticleExtractorFromContextMenu(_:)), webFeed)
if webFeed.isArticleExtractorAlwaysOn == nil || webFeed.isArticleExtractorAlwaysOn! == false {
articleExtractorMenuItem.state = .off
} else {
articleExtractorMenuItem.state = .on
}
menu.addItem(articleExtractorMenuItem)
menu.addItem(NSMenuItem.separator())
menu.addItem(renameMenuItem(webFeed))