1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-28 02:54:31 +03:00

GH-286 React to file system changes in file browser

This commit is contained in:
Tae Won Ha 2016-10-04 00:23:54 +02:00
parent b881b5ce4e
commit 0249a509ef
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
5 changed files with 32 additions and 4 deletions

View File

@ -75,7 +75,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
})
.addDisposableTo(self.disposeBag)
let changeFlows: [Flow] = [ self.prefStore ]
let changeFlows: [Flow] = [ self.prefStore, self.fileItemService ]
let actionFlows: [Flow] = [ self.prefWindowComponent, self.mainWindowManager ]
changeFlows
@ -84,7 +84,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
.subscribe(self.changeSubject)
.addDisposableTo(self.disposeBag)
actionFlows
.map { $0.sink }
.toMergedObservables()

View File

@ -50,6 +50,24 @@ class FileBrowserComponent: ViewComponent, NSOutlineViewDataSource, NSOutlineVie
}
})
.addDisposableTo(self.disposeBag)
self.fileItemService.sink
.filter { $0 is FileItemServiceChange }
.map { $0 as! FileItemServiceChange }
.subscribe(onNext: { [unowned self] action in
switch action {
case let .childrenChanged(root, fileItem):
guard root == self.cwd else {
return
}
// NSLog("\(root) -> \(fileItem)")
DispatchUtils.gui {
self.fileView.reloadItem(fileItem, reloadChildren: true)
}
}
})
.addDisposableTo(self.disposeBag)
}
override func addViews() {

View File

@ -28,7 +28,7 @@ class FileItem : CustomStringConvertible {
var children: [FileItem] = []
var description: String {
return "<FileItem: \(self.url), dir=\(self.dir), hidden=\(self.hidden), package=\(self.package)"
return "<FileItem: \(self.url), dir=\(self.dir), hidden=\(self.hidden), package=\(self.package), "
+ "needsScan=\(self.needsScanChildren), childrenScanned=\(self.childrenScanned), "
+ "ignore=\(self.ignore), ignoreToken=\(self.ignoreToken), "
+ "children=\(self.children.count)>"

View File

@ -7,6 +7,11 @@ import Cocoa
import RxSwift
import EonilFileSystemEvents
enum FileItemServiceChange {
case childrenChanged(root: URL, fileItem: FileItem?)
}
class FileItemService: StandardFlow {
/// Used to cache fnmatch calls in `FileItem`.
@ -71,7 +76,11 @@ class FileItemService: StandardFlow {
{ [unowned self] events in
let urls = events.map { URL(fileURLWithPath: $0.path) }
let parent = FileUtils.commonParent(ofUrls: urls)
self.fileItem(for: parent)?.needsScanChildren = true
let parentItem = self.fileItem(for: parent)
parentItem?.needsScanChildren = true
self.publish(event: FileItemServiceChange.childrenChanged(root: url, fileItem: parentItem))
}
self.monitors[url] = monitor

View File

@ -92,6 +92,8 @@ class MainWindowComponent: WindowComponent, NSWindowDelegate, NSUserInterfaceVal
self.workspace.delegate = self
// FIXME: We do not use [self.sink, source].toMergedObservables. If we do so, then self.sink seems to live as long
// as source, i.e. forever. Thus, self (MainWindowComponent) does not get deallocated. Not nice...
let fileBrowser = FileBrowserComponent(source: self.sink, fileItemService: fileItemService)
let fileBrowserTool = WorkspaceToolComponent(title: "Files", viewComponent: fileBrowser, minimumDimension: 100)
self.tools[.fileBrowser] = fileBrowserTool