From 27c5ffa5eb7fcff61dbba2a95be07ca892804673 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 3 Feb 2018 21:30:30 -0800 Subject: [PATCH] =?UTF-8?q?Add=20new-feed=20and=20new-folder=20commands=20?= =?UTF-8?q?to=20the=20sidebar=20gear=20menu=20when=20there=E2=80=99s=20no?= =?UTF-8?q?=20selection.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Evergreen/AppDelegate.swift | 9 +++++++-- .../MainWindowController+ContextualMenus.swift | 13 ++++++++++++- Evergreen/MainWindow/MainWindowController.swift | 7 ++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Evergreen/AppDelegate.swift b/Evergreen/AppDelegate.swift index 1c9567e92..9ac432399 100644 --- a/Evergreen/AppDelegate.swift +++ b/Evergreen/AppDelegate.swift @@ -101,6 +101,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, addFolderWindowController!.runSheetOnWindow(window) } + func showAddFeedSheetOnWindow(_ window: NSWindow, urlString: String?, name: String?) { + + addFeedController = AddFeedController(hostWindow: window) + addFeedController?.showAddFeedSheet(urlString, name) + } + // MARK: - NSApplicationDelegate func applicationDidFinishLaunching(_ note: Notification) { @@ -275,8 +281,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, return } - addFeedController = AddFeedController(hostWindow: mainWindowController!.window!) - addFeedController?.showAddFeedSheet(urlString, name) + showAddFeedSheetOnWindow(mainWindowController!.window!, urlString: urlString, name: name) } // MARK: - Actions diff --git a/Evergreen/MainWindow/ContextualMenus/MainWindowController+ContextualMenus.swift b/Evergreen/MainWindow/ContextualMenus/MainWindowController+ContextualMenus.swift index 4a0a99885..2f6253210 100644 --- a/Evergreen/MainWindow/ContextualMenus/MainWindowController+ContextualMenus.swift +++ b/Evergreen/MainWindow/ContextualMenus/MainWindowController+ContextualMenus.swift @@ -16,7 +16,7 @@ extension MainWindowController { func menu(for objects: [Any]?) -> NSMenu? { guard let objects = objects, objects.count > 0 else { - return nil + return menuForNoSelection() } if objects.count == 1 { @@ -55,6 +55,7 @@ extension MainWindowController { @objc func markObjectsReadFromContextualMenu(_ sender: Any?) { + } @objc func deleteFromContextualMenu(_ sender: Any?) { @@ -92,6 +93,16 @@ extension MainWindowController: RenameWindowControllerDelegate { private extension MainWindowController { + func menuForNoSelection() -> NSMenu { + + let menu = NSMenu(title: "") + + menu.addItem(withTitle: NSLocalizedString("New Feed", comment: "Command"), action: #selector(showAddFeedWindow(_:)), keyEquivalent: "") + menu.addItem(withTitle: NSLocalizedString("New Folder", comment: "Command"), action: #selector(showAddFolderWindow(_:)), keyEquivalent: "") + + return menu + } + func menuForFeed(_ feed: Feed) -> NSMenu? { let menu = NSMenu(title: "") diff --git a/Evergreen/MainWindow/MainWindowController.swift b/Evergreen/MainWindow/MainWindowController.swift index 654a8f115..cd9c5402d 100644 --- a/Evergreen/MainWindow/MainWindowController.swift +++ b/Evergreen/MainWindow/MainWindowController.swift @@ -177,7 +177,12 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations { appDelegate.showAddFolderSheetOnWindow(window!) } - + + @IBAction func showAddFeedWindow(_ sender: Any) { + + appDelegate.showAddFeedSheetOnWindow(window!, urlString: nil, name: nil) + } + @IBAction func openArticleInBrowser(_ sender: Any?) { if let link = currentLink {