Accept drops of a single nonlocal feed — a URL from outside the app, for instance — in the sidebar. Show the add-feed sheet after accepting the drop.
This commit is contained in:
parent
6390bd4a57
commit
38b824afca
@ -87,6 +87,23 @@ import Account
|
||||
}
|
||||
|
||||
func outlineView(_ outlineView: NSOutlineView, acceptDrop info: NSDraggingInfo, item: Any?, childIndex index: Int) -> Bool {
|
||||
let parentNode = nodeForItem(item)
|
||||
if parentNode == treeController.rootNode {
|
||||
return false
|
||||
}
|
||||
guard let draggedFeeds = PasteboardFeed.pasteboardFeeds(with: info.draggingPasteboard()), !draggedFeeds.isEmpty else {
|
||||
return false
|
||||
}
|
||||
let contentsType = draggedFeedContentsType(draggedFeeds)
|
||||
if contentsType == .empty || contentsType == .mixed || contentsType == .multipleNonLocal {
|
||||
return false
|
||||
}
|
||||
|
||||
if contentsType == .singleNonLocal {
|
||||
let draggedNonLocalFeed = singleNonLocalFeed(from: draggedFeeds)!
|
||||
return acceptSingleNonLocalFeedDrop(outlineView, draggedNonLocalFeed, parentNode, index)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -173,8 +190,12 @@ private extension SidebarOutlineDataSource {
|
||||
return node.representedObject is Account || node.representedObject is Folder
|
||||
}
|
||||
|
||||
func nodeIsDropTarget(_ node: Node) -> Bool {
|
||||
return node.canHaveChildNodes && nodeIsAccountOrFolder(node)
|
||||
}
|
||||
|
||||
func ancestorThatCanAcceptNonLocalFeed(_ node: Node) -> Node? {
|
||||
if node.canHaveChildNodes && nodeIsAccountOrFolder(node) {
|
||||
if nodeIsDropTarget(node) {
|
||||
return node
|
||||
}
|
||||
guard let parentNode = node.parent else {
|
||||
@ -182,4 +203,15 @@ private extension SidebarOutlineDataSource {
|
||||
}
|
||||
return ancestorThatCanAcceptNonLocalFeed(parentNode)
|
||||
}
|
||||
|
||||
func acceptSingleNonLocalFeedDrop(_ outlineView: NSOutlineView, _ draggedFeed: PasteboardFeed, _ parentNode: Node, _ index: Int) -> Bool {
|
||||
guard nodeIsDropTarget(parentNode), index == NSOutlineViewDropOnItemIndex else {
|
||||
return false
|
||||
}
|
||||
|
||||
// Show the add-feed sheet.
|
||||
let folder = parentNode.representedObject as? Folder
|
||||
appDelegate.addFeed(draggedFeed.url, name: nil, folder: folder)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user