Change the name of the Show/Hide Sidebar command as needed. Fix #98.

This commit is contained in:
Brent Simmons 2018-02-07 21:42:33 -08:00
parent a3a9d467dc
commit 78530dbb96
1 changed files with 47 additions and 44 deletions

View File

@ -38,9 +38,9 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
static var didPositionWindowOnFirstRun = false static var didPositionWindowOnFirstRun = false
override func windowDidLoad() { override func windowDidLoad() {
super.windowDidLoad() super.windowDidLoad()
if !AppDefaults.shared.showTitleOnMainWindow { if !AppDefaults.shared.showTitleOnMainWindow {
window?.titleVisibility = .hidden window?.titleVisibility = .hidden
@ -82,12 +82,12 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
return sidebarViewController?.selectedObjects return sidebarViewController?.selectedObjects
} }
// MARK: Notifications // MARK: Notifications
@objc func applicationWillTerminate(_ note: Notification) { @objc func applicationWillTerminate(_ note: Notification) {
window?.saveFrame(usingName: windowAutosaveName) window?.saveFrame(usingName: windowAutosaveName)
} }
@objc func appNavigationKeyPressed(_ note: Notification) { @objc func appNavigationKeyPressed(_ note: Notification) {
@ -153,6 +153,21 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
return canShowShareMenu() return canShowShareMenu()
} }
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
}
return true return true
} }
@ -171,10 +186,10 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
} }
@IBAction func showAddFolderWindow(_ sender: Any) { @IBAction func showAddFolderWindow(_ sender: Any) {
appDelegate.showAddFolderSheetOnWindow(window!) appDelegate.showAddFolderSheetOnWindow(window!)
} }
@IBAction func showAddFeedWindow(_ sender: Any) { @IBAction func showAddFeedWindow(_ sender: Any) {
@ -390,57 +405,45 @@ extension MainWindowController: NSToolbarDelegate {
private extension MainWindowController { private extension MainWindowController {
var splitViewController: NSSplitViewController? { var splitViewController: NSSplitViewController? {
get { guard let viewController = contentViewController else {
guard let viewController = contentViewController else { return nil
return nil
}
return viewController.childViewControllers.first as? NSSplitViewController
} }
return viewController.childViewControllers.first as? NSSplitViewController
} }
var sidebarViewController: SidebarViewController? { var sidebarViewController: SidebarViewController? {
get { return splitViewController?.splitViewItems[0].viewController as? SidebarViewController
return splitViewController?.splitViewItems[0].viewController as? SidebarViewController
}
} }
var timelineViewController: TimelineViewController? { var timelineViewController: TimelineViewController? {
get { return splitViewController?.splitViewItems[1].viewController as? TimelineViewController
return splitViewController?.splitViewItems[1].viewController as? TimelineViewController }
}
var sidebarSplitViewItem: NSSplitViewItem? {
return splitViewController?.splitViewItems[0]
} }
var detailSplitViewItem: NSSplitViewItem? { var detailSplitViewItem: NSSplitViewItem? {
get { return splitViewController?.splitViewItems[2]
return splitViewController?.splitViewItems[2]
}
} }
var detailViewController: DetailViewController? { var detailViewController: DetailViewController? {
get { return splitViewController?.splitViewItems[2].viewController as? DetailViewController
return splitViewController?.splitViewItems[2].viewController as? DetailViewController
}
} }
var selectedArticles: [Article]? { var selectedArticles: [Article]? {
get { return timelineViewController?.selectedArticles
return timelineViewController?.selectedArticles
}
} }
var oneSelectedArticle: Article? { var oneSelectedArticle: Article? {
get { if let articles = selectedArticles {
if let articles = selectedArticles { return articles.count == 1 ? articles[0] : nil
return articles.count == 1 ? articles[0] : nil
}
return nil
} }
return nil
} }
var currentLink: String? { var currentLink: String? {
get { return oneSelectedArticle?.preferredLink
return oneSelectedArticle?.preferredLink
}
} }
func canGoToNextUnread() -> Bool { func canGoToNextUnread() -> Bool {