Add the ability to specify a selected Folder when running the add-feed sheet.

This commit is contained in:
Brent Simmons 2018-09-22 12:46:24 -07:00
parent bcdd9057b2
commit 6390bd4a57
5 changed files with 26 additions and 10 deletions

View File

@ -97,10 +97,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
addFolderWindowController!.runSheetOnWindow(window) addFolderWindowController!.runSheetOnWindow(window)
} }
func showAddFeedSheetOnWindow(_ window: NSWindow, urlString: String?, name: String?) { func showAddFeedSheetOnWindow(_ window: NSWindow, urlString: String?, name: String?, folder: Folder?) {
addFeedController = AddFeedController(hostWindow: window) addFeedController = AddFeedController(hostWindow: window)
addFeedController?.showAddFeedSheet(urlString, name) addFeedController?.showAddFeedSheet(urlString, name, folder)
} }
func showAddFeedFromListOnMainWindow(_ feedListFeeds: [FeedListFeed]) { func showAddFeedFromListOnMainWindow(_ feedListFeeds: [FeedListFeed]) {
@ -256,14 +256,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
// MARK: Add Feed // MARK: Add Feed
func addFeed(_ urlString: String?, _ name: String? = nil) { func addFeed(_ urlString: String?, name: String? = nil, folder: Folder? = nil) {
createAndShowMainWindow() createAndShowMainWindow()
if mainWindowController!.isDisplayingSheet { if mainWindowController!.isDisplayingSheet {
return return
} }
showAddFeedSheetOnWindow(mainWindowController!.window!, urlString: urlString, name: name) showAddFeedSheetOnWindow(mainWindowController!.window!, urlString: urlString, name: name, folder: folder)
} }
// MARK: - Actions // MARK: - Actions
@ -416,7 +416,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations,
if AccountManager.shared.anyAccountHasFeedWithURL(appNewsURLString) { if AccountManager.shared.anyAccountHasFeedWithURL(appNewsURLString) {
return return
} }
addFeed(appNewsURLString, "NetNewsWire News") addFeed(appNewsURLString, name: "NetNewsWire News")
} }
@IBAction func openWebsite(_ sender: Any?) { @IBAction func openWebsite(_ sender: Any?) {

View File

@ -40,7 +40,7 @@ class AddFeedController: AddFeedWindowControllerDelegate, FeedFinderDelegate {
self.hostWindow = hostWindow self.hostWindow = hostWindow
} }
func showAddFeedSheet(_ urlString: String?, _ name: String?) { func showAddFeedSheet(_ urlString: String?, _ name: String?, _ folder: Folder?) {
let folderTreeControllerDelegate = FolderTreeControllerDelegate() let folderTreeControllerDelegate = FolderTreeControllerDelegate()
@ -48,7 +48,7 @@ class AddFeedController: AddFeedWindowControllerDelegate, FeedFinderDelegate {
rootNode.canHaveChildNodes = true rootNode.canHaveChildNodes = true
let folderTreeController = TreeController(delegate: folderTreeControllerDelegate, rootNode: rootNode) let folderTreeController = TreeController(delegate: folderTreeControllerDelegate, rootNode: rootNode)
addFeedWindowController = AddFeedWindowController(urlString: urlString ?? urlStringFromPasteboard, name: name, folderTreeController: folderTreeController, delegate: self) addFeedWindowController = AddFeedWindowController(urlString: urlString ?? urlStringFromPasteboard, name: name, folder: folder, folderTreeController: folderTreeController, delegate: self)
addFeedWindowController!.runSheetOnWindow(hostWindow) addFeedWindowController!.runSheetOnWindow(hostWindow)
} }

View File

@ -29,6 +29,7 @@ class AddFeedWindowController : NSWindowController {
private var urlString: String? private var urlString: String?
private var initialName: String? private var initialName: String?
private var initialFolder: Folder?
fileprivate weak var delegate: AddFeedWindowControllerDelegate? fileprivate weak var delegate: AddFeedWindowControllerDelegate?
fileprivate var folderTreeController: TreeController! fileprivate var folderTreeController: TreeController!
@ -43,11 +44,12 @@ class AddFeedWindowController : NSWindowController {
var hostWindow: NSWindow! var hostWindow: NSWindow!
convenience init(urlString: String?, name: String?, folderTreeController: TreeController, delegate: AddFeedWindowControllerDelegate?) { convenience init(urlString: String?, name: String?, folder: Folder?, folderTreeController: TreeController, delegate: AddFeedWindowControllerDelegate?) {
self.init(windowNibName: NSNib.Name(rawValue: "AddFeedSheet")) self.init(windowNibName: NSNib.Name(rawValue: "AddFeedSheet"))
self.urlString = urlString self.urlString = urlString
self.initialName = name self.initialName = name
self.initialFolder = folder
self.delegate = delegate self.delegate = delegate
self.folderTreeController = folderTreeController self.folderTreeController = folderTreeController
} }
@ -69,6 +71,10 @@ class AddFeedWindowController : NSWindowController {
} }
folderPopupButton.menu = FolderTreeMenu.createFolderPopupMenu(with: folderTreeController.rootNode) folderPopupButton.menu = FolderTreeMenu.createFolderPopupMenu(with: folderTreeController.rootNode)
if let folder = initialFolder {
FolderTreeMenu.select(folder, in: folderPopupButton)
}
updateUI() updateUI()
} }

View File

@ -9,6 +9,7 @@
import AppKit import AppKit
import RSCore import RSCore
import RSTree import RSTree
import Account
class FolderTreeMenu { class FolderTreeMenu {
@ -26,6 +27,15 @@ class FolderTreeMenu {
return menu return menu
} }
static func select(_ folder: Folder, in popupButton: NSPopUpButton) {
for menuItem in popupButton.itemArray {
if let oneFolder = menuItem.representedObject as? Folder, oneFolder == folder {
popupButton.select(menuItem)
return
}
}
}
private static func addFolderItemsToMenuWithNodes(menu: NSMenu, nodes: [Node], indentationLevel: Int) { private static func addFolderItemsToMenuWithNodes(menu: NSMenu, nodes: [Node], indentationLevel: Int) {
nodes.forEach { (oneNode) in nodes.forEach { (oneNode) in

View File

@ -231,7 +231,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
@IBAction func showAddFeedWindow(_ sender: Any?) { @IBAction func showAddFeedWindow(_ sender: Any?) {
appDelegate.showAddFeedSheetOnWindow(window!, urlString: nil, name: nil) appDelegate.showAddFeedSheetOnWindow(window!, urlString: nil, name: nil, folder: nil)
} }
@IBAction func openArticleInBrowser(_ sender: Any?) { @IBAction func openArticleInBrowser(_ sender: Any?) {