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

View File

@ -40,7 +40,7 @@ class AddFeedController: AddFeedWindowControllerDelegate, FeedFinderDelegate {
self.hostWindow = hostWindow
}
func showAddFeedSheet(_ urlString: String?, _ name: String?) {
func showAddFeedSheet(_ urlString: String?, _ name: String?, _ folder: Folder?) {
let folderTreeControllerDelegate = FolderTreeControllerDelegate()
@ -48,7 +48,7 @@ class AddFeedController: AddFeedWindowControllerDelegate, FeedFinderDelegate {
rootNode.canHaveChildNodes = true
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)
}

View File

@ -29,6 +29,7 @@ class AddFeedWindowController : NSWindowController {
private var urlString: String?
private var initialName: String?
private var initialFolder: Folder?
fileprivate weak var delegate: AddFeedWindowControllerDelegate?
fileprivate var folderTreeController: TreeController!
@ -43,11 +44,12 @@ class AddFeedWindowController : NSWindowController {
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.urlString = urlString
self.initialName = name
self.initialFolder = folder
self.delegate = delegate
self.folderTreeController = folderTreeController
}
@ -69,6 +71,10 @@ class AddFeedWindowController : NSWindowController {
}
folderPopupButton.menu = FolderTreeMenu.createFolderPopupMenu(with: folderTreeController.rootNode)
if let folder = initialFolder {
FolderTreeMenu.select(folder, in: folderPopupButton)
}
updateUI()
}

View File

@ -9,6 +9,7 @@
import AppKit
import RSCore
import RSTree
import Account
class FolderTreeMenu {
@ -26,6 +27,15 @@ class FolderTreeMenu {
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) {
nodes.forEach { (oneNode) in

View File

@ -231,7 +231,7 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations {
@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?) {