mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-26 15:25:14 +03:00
GH-351 Handle deletions
This commit is contained in:
parent
20a64c540c
commit
bc479d8867
@ -95,38 +95,51 @@ class FileOutlineView: NSOutlineView, Flow, NSOutlineViewDataSource, NSOutlineVi
|
|||||||
|
|
||||||
func update(_ fileItem: FileItem) {
|
func update(_ fileItem: FileItem) {
|
||||||
let url = fileItem.url
|
let url = fileItem.url
|
||||||
Swift.print("updating \(url)")
|
|
||||||
guard let fileBrowserItem = self.fileBrowserItem(with: url) else {
|
guard let fileBrowserItem = self.fileBrowserItem(with: url) else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
Swift.print("got \(fileBrowserItem) to update")
|
Swift.print("got \(fileBrowserItem) to update")
|
||||||
// self.update(fileBrowserItem)
|
self.update(fileBrowserItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func update(_ fileBrowserItem: FileBrowserItem) {
|
fileprivate func update(_ fileBrowserItem: FileBrowserItem) {
|
||||||
// let url = fileBrowserItem.fileItem.url
|
let url = fileBrowserItem.fileItem.url
|
||||||
//
|
|
||||||
// let curChildren = fileBrowserItem.children.filter { !$0.fileItem.isHidden }
|
// Sort the arrays to keep the order.
|
||||||
// let newChildren = (self.fileItemService.fileItemWithChildren(for: url)?.children ?? [])
|
let curChildren = fileBrowserItem.children.sorted()
|
||||||
// .map(FileBrowserItem.init)
|
let newChildren = (self.fileItemService.fileItemWithChildren(for: url)?.children ?? [])
|
||||||
// .filter { !$0.fileItem.isHidden }
|
.map(FileBrowserItem.init)
|
||||||
//
|
.sorted()
|
||||||
// Swift.print("\(fileBrowserItem.fileItem.url.lastPathComponent): \(curChildren.count) vs \(newChildren.count)")
|
|
||||||
//
|
let curPreparedChildren = self.prepare(curChildren)
|
||||||
|
let newPreparedChildren = self.prepare(newChildren)
|
||||||
|
|
||||||
|
// Handle removals.
|
||||||
|
let childrenToRemoveIndices = curPreparedChildren
|
||||||
|
.enumerated()
|
||||||
|
.filter { newPreparedChildren.contains($0.1) == false }
|
||||||
|
.map { $0.0 }
|
||||||
|
self.removeItems(at: IndexSet(childrenToRemoveIndices), inParent: fileBrowserItem)
|
||||||
|
fileBrowserItem.children = curChildren.filter { newChildren.contains($0) }
|
||||||
|
|
||||||
|
// Handle additions.
|
||||||
|
|
||||||
|
// Handle children.
|
||||||
|
let keptChildren = curChildren.filter { newChildren.contains($0) }
|
||||||
|
|
||||||
// let childrenToAdd = newChildren.filter { curChildren.contains($0) == false }
|
// let childrenToAdd = newChildren.filter { curChildren.contains($0) == false }
|
||||||
// let keptChildren = curChildren.filter { newChildren.contains($0) }
|
|
||||||
//
|
|
||||||
// let resultChildren = childrenToAdd.add(keptChildren)
|
// let resultChildren = childrenToAdd.add(keptChildren)
|
||||||
// fileBrowserItem.children = Array(resultChildren)
|
// fileBrowserItem.children = Array(resultChildren)
|
||||||
// Swift.print("new resulting children: \(resultChildren)")
|
// Swift.print("new resulting children: \(resultChildren)")
|
||||||
//
|
|
||||||
// let childrenToRecurse = keptChildren.filter{ self.isItemExpanded(self.fileBrowserItem(with: $0.fileItem.url)) }
|
let childrenToRecurse = keptChildren.filter { self.isItemExpanded(self.fileBrowserItem(with: $0.fileItem.url)) }
|
||||||
// Swift.print("to recurse: \(childrenToRecurse)")
|
Swift.print("to recurse: \(childrenToRecurse)")
|
||||||
//
|
|
||||||
// self.reloadItem(fileBrowserItem, reloadChildren: false)
|
// self.reloadItem(fileBrowserItem, reloadChildren: false)
|
||||||
//
|
|
||||||
// childrenToRecurse.forEach(self.update)
|
childrenToRecurse.forEach(self.update)
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func fileBrowserItem(with url: URL) -> FileBrowserItem? {
|
fileprivate func fileBrowserItem(with url: URL) -> FileBrowserItem? {
|
||||||
|
Loading…
Reference in New Issue
Block a user