mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-20 06:30:31 +01:00
Make undo deleting feeds/folders work.
This commit is contained in:
parent
57296279e4
commit
9818278c9b
@ -54,7 +54,7 @@ final class DeleteFromSidebarCommand: UndoableCommand {
|
||||
func undo() {
|
||||
|
||||
BatchUpdate.shared.perform {
|
||||
|
||||
itemSpecifiers.forEach { $0.restore() }
|
||||
}
|
||||
registerRedo()
|
||||
}
|
||||
@ -145,6 +145,49 @@ private struct SidebarItemSpecifier {
|
||||
container.deleteFolder(folder)
|
||||
}
|
||||
}
|
||||
|
||||
func restore() {
|
||||
|
||||
if let feed = feed {
|
||||
restoreFeed()
|
||||
}
|
||||
else if let folder = folder {
|
||||
restoreFolder()
|
||||
}
|
||||
}
|
||||
|
||||
private func restoreFeed() {
|
||||
|
||||
guard let account = account, let feed = feed else {
|
||||
return
|
||||
}
|
||||
|
||||
let feedToUse = uniquedFeed(feed)
|
||||
account.addFeed(feedToUse, to: resolvedFolder())
|
||||
}
|
||||
|
||||
private func restoreFolder() {
|
||||
|
||||
guard let account = account, let folder = folder else {
|
||||
return
|
||||
}
|
||||
account.addFolder(folder, to: nil)
|
||||
}
|
||||
|
||||
private func uniquedFeed(_ feed: Feed) -> Feed {
|
||||
|
||||
// A Feed may appear in multiple places in a given account,
|
||||
// but it’s best if they’re the same Feed instance.
|
||||
// Usually this will return the same Feed that was passed-in,
|
||||
// but not necessarily always.
|
||||
|
||||
return account?.existingFeed(with: feed.feedID) ?? feed
|
||||
}
|
||||
|
||||
private func resolvedFolder() -> Folder? {
|
||||
|
||||
return path.resolveContainer() as? Folder
|
||||
}
|
||||
}
|
||||
|
||||
private extension Node {
|
||||
|
@ -20,6 +20,7 @@ import RSCore
|
||||
TreeController(delegate: treeControllerDelegate)
|
||||
}()
|
||||
var undoableCommands = [UndoableCommand]()
|
||||
private var animatingChanges = false
|
||||
|
||||
//MARK: NSViewController
|
||||
|
||||
@ -79,11 +80,13 @@ import RSCore
|
||||
|
||||
let selectedRows = outlineView.selectedRowIndexes
|
||||
|
||||
animatingChanges = true
|
||||
outlineView.beginUpdates()
|
||||
outlineView.removeItems(at: selectedRows, inParent: nil, withAnimation: [.slideDown])
|
||||
outlineView.endUpdates()
|
||||
|
||||
runCommand(deleteCommand)
|
||||
animatingChanges = false
|
||||
}
|
||||
|
||||
// MARK: Navigation
|
||||
@ -170,7 +173,7 @@ private extension SidebarViewController {
|
||||
|
||||
func rebuildTreeAndReloadDataIfNeeded() {
|
||||
|
||||
if !BatchUpdate.shared.isPerforming {
|
||||
if !animatingChanges && !BatchUpdate.shared.isPerforming {
|
||||
treeController.rebuild()
|
||||
outlineView.reloadData()
|
||||
}
|
||||
|
@ -276,7 +276,15 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
||||
@discardableResult
|
||||
public func addFolder(_ folder: Folder, to parentFolder: Folder?) -> Bool {
|
||||
|
||||
return false // TODO
|
||||
// TODO: support subfolders, maybe, some day, if one of the sync systems
|
||||
// supports subfolders. But, for now, parentFolder is ignored.
|
||||
|
||||
if objectIsChild(folder) {
|
||||
return true
|
||||
}
|
||||
children += [folder]
|
||||
postChildrenDidChangeNotification()
|
||||
return true
|
||||
}
|
||||
|
||||
public func importOPML(_ opmlDocument: RSOPMLDocument) {
|
||||
|
Loading…
Reference in New Issue
Block a user