diff --git a/Mac/MainWindow/Sidebar/SidebarViewController.swift b/Mac/MainWindow/Sidebar/SidebarViewController.swift index 8ddfff0f4..18f856ca2 100644 --- a/Mac/MainWindow/Sidebar/SidebarViewController.swift +++ b/Mac/MainWindow/Sidebar/SidebarViewController.swift @@ -314,7 +314,7 @@ protocol SidebarDelegate: class { let nodesToDelete = treeController.normalizedSelectedNodes(nodes) - guard let undoManager = undoManager, let deleteCommand = DeleteFromSidebarCommand(nodesToDelete: nodesToDelete, treeController: treeController, undoManager: undoManager) else { + guard let undoManager = undoManager, let deleteCommand = DeleteCommand(nodesToDelete: nodesToDelete, treeController: treeController, undoManager: undoManager) else { return } diff --git a/NetNewsWire.xcodeproj/project.pbxproj b/NetNewsWire.xcodeproj/project.pbxproj index 1e69ba21f..41bd737b8 100644 --- a/NetNewsWire.xcodeproj/project.pbxproj +++ b/NetNewsWire.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ 512E08E72268801200BDCFDD /* FeedTreeControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A97611ED9EB96007D329B /* FeedTreeControllerDelegate.swift */; }; 512E09012268907400BDCFDD /* MasterTableViewSectionHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 512E08F722688F7C00BDCFDD /* MasterTableViewSectionHeader.swift */; }; 512E09352268B25900BDCFDD /* UISplitViewController-Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 512E092B2268B25500BDCFDD /* UISplitViewController-Extensions.swift */; }; + 512E094D2268B8AB00BDCFDD /* DeleteCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B99C9C1FAE83C600ECDEDB /* DeleteCommand.swift */; }; 517D9075226639F500323654 /* AddAccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 517D906B2266392900323654 /* AddAccountViewController.swift */; }; 519B8D332143397200FA689C /* SharingServiceDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 519B8D322143397200FA689C /* SharingServiceDelegate.swift */; }; 51C451A9226377C200C03939 /* ArticlesDatabase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8407167F2262A61100344432 /* ArticlesDatabase.framework */; }; @@ -188,7 +189,7 @@ 84AD1EBA2031649C00BC20B7 /* SmartFeedPasteboardWriter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AD1EB92031649C00BC20B7 /* SmartFeedPasteboardWriter.swift */; }; 84AD1EBC2032AF5C00BC20B7 /* SidebarOutlineDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AD1EBB2032AF5C00BC20B7 /* SidebarOutlineDataSource.swift */; }; 84B7178C201E66580091657D /* SidebarViewController+ContextualMenus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B7178B201E66580091657D /* SidebarViewController+ContextualMenus.swift */; }; - 84B99C9D1FAE83C600ECDEDB /* DeleteFromSidebarCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B99C9C1FAE83C600ECDEDB /* DeleteFromSidebarCommand.swift */; }; + 84B99C9D1FAE83C600ECDEDB /* DeleteCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B99C9C1FAE83C600ECDEDB /* DeleteCommand.swift */; }; 84BAE64921CEDAF20046DB56 /* CrashReporterWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 84BAE64821CEDAF20046DB56 /* CrashReporterWindow.xib */; }; 84BBB12D20142A4700F054F5 /* Inspector.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 84BBB12B20142A4700F054F5 /* Inspector.storyboard */; }; 84BBB12E20142A4700F054F5 /* InspectorWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84BBB12C20142A4700F054F5 /* InspectorWindowController.swift */; }; @@ -736,7 +737,7 @@ 84AD1EB92031649C00BC20B7 /* SmartFeedPasteboardWriter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartFeedPasteboardWriter.swift; sourceTree = ""; }; 84AD1EBB2032AF5C00BC20B7 /* SidebarOutlineDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarOutlineDataSource.swift; sourceTree = ""; }; 84B7178B201E66580091657D /* SidebarViewController+ContextualMenus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SidebarViewController+ContextualMenus.swift"; sourceTree = ""; }; - 84B99C9C1FAE83C600ECDEDB /* DeleteFromSidebarCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteFromSidebarCommand.swift; sourceTree = ""; }; + 84B99C9C1FAE83C600ECDEDB /* DeleteCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteCommand.swift; sourceTree = ""; }; 84BAE64821CEDAF20046DB56 /* CrashReporterWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CrashReporterWindow.xib; sourceTree = ""; }; 84BBB12B20142A4700F054F5 /* Inspector.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Inspector.storyboard; sourceTree = ""; }; 84BBB12C20142A4700F054F5 /* InspectorWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InspectorWindowController.swift; sourceTree = ""; }; @@ -1143,7 +1144,7 @@ children = ( 84702AA31FA27AC0006B8943 /* MarkStatusCommand.swift */, 84162A142038C12C00035290 /* MarkCommandValidationStatus.swift */, - 84B99C9C1FAE83C600ECDEDB /* DeleteFromSidebarCommand.swift */, + 84B99C9C1FAE83C600ECDEDB /* DeleteCommand.swift */, 84A14FF220048CA70046AD9A /* SendToMicroBlogCommand.swift */, 84A1500420048DDF0046AD9A /* SendToMarsEditCommand.swift */, ); @@ -2172,6 +2173,7 @@ 51C452A922650DC600C03939 /* ArticleRenderer.swift in Sources */, 5115CAF42266301400B21BCE /* AddContainerViewController.swift in Sources */, 51C45297226509E300C03939 /* DefaultFeedsImporter.swift in Sources */, + 512E094D2268B8AB00BDCFDD /* DeleteCommand.swift in Sources */, 51C452AC22650FD200C03939 /* AppNotifications.swift in Sources */, 51C452762265091600C03939 /* MasterTimelineViewController.swift in Sources */, 51C452882265093600C03939 /* AddFeedViewController.swift in Sources */, @@ -2295,7 +2297,7 @@ 84E8E0EB202F693600562D8F /* DetailWebView.swift in Sources */, 849A976C1ED9EBC8007D329B /* TimelineTableRowView.swift in Sources */, 849A977B1ED9EC04007D329B /* UnreadIndicatorView.swift in Sources */, - 84B99C9D1FAE83C600ECDEDB /* DeleteFromSidebarCommand.swift in Sources */, + 84B99C9D1FAE83C600ECDEDB /* DeleteCommand.swift in Sources */, 849A97541ED9EAC0007D329B /* AddFeedWindowController.swift in Sources */, 849A976D1ED9EBC8007D329B /* TimelineTableView.swift in Sources */, 84D52E951FE588BB00D14F5B /* DetailStatusBarView.swift in Sources */, diff --git a/Shared/Commands/DeleteFromSidebarCommand.swift b/Shared/Commands/DeleteCommand.swift similarity index 97% rename from Shared/Commands/DeleteFromSidebarCommand.swift rename to Shared/Commands/DeleteCommand.swift index bfc00ad3a..995b9dfec 100644 --- a/Shared/Commands/DeleteFromSidebarCommand.swift +++ b/Shared/Commands/DeleteCommand.swift @@ -12,7 +12,7 @@ import RSTree import Account import Articles -final class DeleteFromSidebarCommand: UndoableCommand { +final class DeleteCommand: UndoableCommand { let treeController: TreeController let undoManager: UndoManager @@ -25,7 +25,7 @@ final class DeleteFromSidebarCommand: UndoableCommand { init?(nodesToDelete: [Node], treeController: TreeController, undoManager: UndoManager) { - guard DeleteFromSidebarCommand.canDelete(nodesToDelete) else { + guard DeleteCommand.canDelete(nodesToDelete) else { return nil } guard let actionName = DeleteActionName.name(for: nodesToDelete) else { diff --git a/iOS/Master/MasterViewController.swift b/iOS/Master/MasterViewController.swift index 6ebb11744..aaf4dca2f 100644 --- a/iOS/Master/MasterViewController.swift +++ b/iOS/Master/MasterViewController.swift @@ -54,7 +54,7 @@ class MasterViewController: UITableViewController, UndoableCommandRunner { shadowTable.append([Node]()) } - rebuildShadow() + rebuildShadowTable() } @@ -379,24 +379,18 @@ class MasterViewController: UITableViewController, UndoableCommandRunner { } func delete(indexPath: IndexPath) { - - guard let deleteNode = nodeFor(indexPath: indexPath), - let containerNode = deleteNode.parent, - let container = containerNode.representedObject as? Container else { - return + + guard let undoManager = undoManager, + let deleteNode = nodeFor(indexPath: indexPath), + let deleteCommand = DeleteCommand(nodesToDelete: [deleteNode], treeController: treeController, undoManager: undoManager) + else { + return } animatingChanges = true - - if let feed = deleteNode.representedObject as? Feed { - container.deleteFeed(feed) - } - - if let folder = deleteNode.representedObject as? Folder { - container.deleteFolder(folder) - } - - rebuildBackingStructures() + + runCommand(deleteCommand) + rebuildShadowTable() tableView.deleteRows(at: [indexPath], with: .automatic) animatingChanges = false @@ -520,10 +514,10 @@ private extension MasterViewController { func rebuildBackingStructures() { treeController.rebuild() - rebuildShadow() + rebuildShadowTable() } - func rebuildShadow() { + func rebuildShadowTable() { for i in 0..