2018-09-04 07:33:00 +02:00
|
|
|
//
|
|
|
|
// GeneralPrefencesViewController.swift
|
|
|
|
// NetNewsWire
|
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 9/3/18.
|
|
|
|
// Copyright © 2018 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import AppKit
|
|
|
|
import RSCore
|
2020-05-19 04:29:53 +02:00
|
|
|
import RSWeb
|
2018-09-04 07:33:00 +02:00
|
|
|
|
|
|
|
final class GeneralPreferencesViewController: NSViewController {
|
|
|
|
|
2020-05-19 04:29:53 +02:00
|
|
|
@IBOutlet var defaultBrowserPopup: NSPopUpButton!
|
2020-09-06 19:22:35 +02:00
|
|
|
@IBOutlet weak var showUnreadCountCheckbox: NSButton!
|
|
|
|
|
2018-11-26 22:17:16 +01:00
|
|
|
public override init(nibName nibNameOrNil: NSNib.Name?, bundle nibBundleOrNil: Bundle?) {
|
|
|
|
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
|
|
|
|
commonInit()
|
|
|
|
}
|
|
|
|
|
|
|
|
public required init?(coder: NSCoder) {
|
|
|
|
super.init(coder: coder)
|
|
|
|
commonInit()
|
|
|
|
}
|
2018-09-04 07:33:00 +02:00
|
|
|
|
|
|
|
override func viewWillAppear() {
|
2018-11-26 22:17:16 +01:00
|
|
|
super.viewWillAppear()
|
|
|
|
updateUI()
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Notifications
|
|
|
|
|
|
|
|
@objc func applicationWillBecomeActive(_ note: Notification) {
|
|
|
|
updateUI()
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Actions
|
|
|
|
|
2020-05-19 04:29:53 +02:00
|
|
|
@IBAction func browserPopUpDidChangeValue(_ sender: Any?) {
|
|
|
|
guard let menuItem = defaultBrowserPopup.selectedItem else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
let bundleID = menuItem.representedObject as? String
|
2020-07-02 05:17:38 +02:00
|
|
|
AppDefaults.shared.defaultBrowserID = bundleID
|
2020-05-19 04:29:53 +02:00
|
|
|
updateUI()
|
|
|
|
}
|
2020-09-06 19:22:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
@IBAction func toggleShowingUnreadCount(_ sender: Any) {
|
|
|
|
guard let checkbox = sender as? NSButton else { return }
|
|
|
|
AppDefaults.shared.hideDockUnreadCount = checkbox.state.rawValue == 0
|
|
|
|
}
|
2018-09-04 07:33:00 +02:00
|
|
|
}
|
|
|
|
|
2018-11-26 22:17:16 +01:00
|
|
|
// MARK: - Private
|
|
|
|
|
2018-09-04 07:33:00 +02:00
|
|
|
private extension GeneralPreferencesViewController {
|
|
|
|
|
2018-11-26 22:17:16 +01:00
|
|
|
func commonInit() {
|
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(applicationWillBecomeActive(_:)), name: NSApplication.willBecomeActiveNotification, object: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateUI() {
|
2020-05-19 04:29:53 +02:00
|
|
|
updateBrowserPopup()
|
2020-09-06 19:22:35 +02:00
|
|
|
updateHideUnreadCountCheckbox()
|
2018-11-26 22:17:16 +01:00
|
|
|
}
|
|
|
|
|
2020-05-19 04:29:53 +02:00
|
|
|
func updateBrowserPopup() {
|
|
|
|
let menu = defaultBrowserPopup.menu!
|
|
|
|
let allBrowsers = MacWebBrowser.sortedBrowsers()
|
|
|
|
|
|
|
|
menu.removeAllItems()
|
|
|
|
|
|
|
|
let defaultBrowser = MacWebBrowser.default
|
|
|
|
|
|
|
|
let defaultBrowserFormat = NSLocalizedString("System Default (%@)", comment: "Default browser item title format")
|
|
|
|
let defaultBrowserTitle = String(format: defaultBrowserFormat, defaultBrowser.name!)
|
|
|
|
let item = NSMenuItem(title: defaultBrowserTitle, action: nil, keyEquivalent: "")
|
|
|
|
let icon = defaultBrowser.icon!
|
|
|
|
icon.size = NSSize(width: 16.0, height: 16.0)
|
|
|
|
item.image = icon
|
|
|
|
|
|
|
|
menu.addItem(item)
|
|
|
|
menu.addItem(NSMenuItem.separator())
|
|
|
|
|
|
|
|
for browser in allBrowsers {
|
|
|
|
let item = NSMenuItem(title: browser.name!, action: nil, keyEquivalent: "")
|
|
|
|
item.representedObject = browser.bundleIdentifier
|
|
|
|
|
|
|
|
let icon = browser.icon!
|
|
|
|
icon.size = NSSize(width: 16.0, height: 16.0)
|
|
|
|
item.image = browser.icon
|
|
|
|
menu.addItem(item)
|
|
|
|
}
|
|
|
|
|
2020-07-02 05:17:38 +02:00
|
|
|
defaultBrowserPopup.selectItem(at: defaultBrowserPopup.indexOfItem(withRepresentedObject: AppDefaults.shared.defaultBrowserID))
|
2020-05-19 04:29:53 +02:00
|
|
|
}
|
2020-09-06 19:22:35 +02:00
|
|
|
|
|
|
|
func updateHideUnreadCountCheckbox() {
|
|
|
|
showUnreadCountCheckbox.state = AppDefaults.shared.hideDockUnreadCount ? .off : .on
|
|
|
|
}
|
2018-11-26 22:17:16 +01:00
|
|
|
}
|