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:
parent
b881b5ce4e
commit
0249a509ef
@ -75,7 +75,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
})
|
})
|
||||||
.addDisposableTo(self.disposeBag)
|
.addDisposableTo(self.disposeBag)
|
||||||
|
|
||||||
let changeFlows: [Flow] = [ self.prefStore ]
|
let changeFlows: [Flow] = [ self.prefStore, self.fileItemService ]
|
||||||
let actionFlows: [Flow] = [ self.prefWindowComponent, self.mainWindowManager ]
|
let actionFlows: [Flow] = [ self.prefWindowComponent, self.mainWindowManager ]
|
||||||
|
|
||||||
changeFlows
|
changeFlows
|
||||||
@ -84,7 +84,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
.subscribe(self.changeSubject)
|
.subscribe(self.changeSubject)
|
||||||
.addDisposableTo(self.disposeBag)
|
.addDisposableTo(self.disposeBag)
|
||||||
|
|
||||||
|
|
||||||
actionFlows
|
actionFlows
|
||||||
.map { $0.sink }
|
.map { $0.sink }
|
||||||
.toMergedObservables()
|
.toMergedObservables()
|
||||||
|
@ -50,6 +50,24 @@ class FileBrowserComponent: ViewComponent, NSOutlineViewDataSource, NSOutlineVie
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.addDisposableTo(self.disposeBag)
|
.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() {
|
override func addViews() {
|
||||||
|
@ -28,7 +28,7 @@ class FileItem : CustomStringConvertible {
|
|||||||
var children: [FileItem] = []
|
var children: [FileItem] = []
|
||||||
|
|
||||||
var description: String {
|
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), "
|
+ "needsScan=\(self.needsScanChildren), childrenScanned=\(self.childrenScanned), "
|
||||||
+ "ignore=\(self.ignore), ignoreToken=\(self.ignoreToken), "
|
+ "ignore=\(self.ignore), ignoreToken=\(self.ignoreToken), "
|
||||||
+ "children=\(self.children.count)>"
|
+ "children=\(self.children.count)>"
|
||||||
|
@ -7,6 +7,11 @@ import Cocoa
|
|||||||
import RxSwift
|
import RxSwift
|
||||||
import EonilFileSystemEvents
|
import EonilFileSystemEvents
|
||||||
|
|
||||||
|
enum FileItemServiceChange {
|
||||||
|
|
||||||
|
case childrenChanged(root: URL, fileItem: FileItem?)
|
||||||
|
}
|
||||||
|
|
||||||
class FileItemService: StandardFlow {
|
class FileItemService: StandardFlow {
|
||||||
|
|
||||||
/// Used to cache fnmatch calls in `FileItem`.
|
/// Used to cache fnmatch calls in `FileItem`.
|
||||||
@ -71,7 +76,11 @@ class FileItemService: StandardFlow {
|
|||||||
{ [unowned self] events in
|
{ [unowned self] events in
|
||||||
let urls = events.map { URL(fileURLWithPath: $0.path) }
|
let urls = events.map { URL(fileURLWithPath: $0.path) }
|
||||||
let parent = FileUtils.commonParent(ofUrls: urls)
|
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
|
self.monitors[url] = monitor
|
||||||
|
@ -92,6 +92,8 @@ class MainWindowComponent: WindowComponent, NSWindowDelegate, NSUserInterfaceVal
|
|||||||
|
|
||||||
self.workspace.delegate = self
|
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 fileBrowser = FileBrowserComponent(source: self.sink, fileItemService: fileItemService)
|
||||||
let fileBrowserTool = WorkspaceToolComponent(title: "Files", viewComponent: fileBrowser, minimumDimension: 100)
|
let fileBrowserTool = WorkspaceToolComponent(title: "Files", viewComponent: fileBrowser, minimumDimension: 100)
|
||||||
self.tools[.fileBrowser] = fileBrowserTool
|
self.tools[.fileBrowser] = fileBrowserTool
|
||||||
|
Loading…
Reference in New Issue
Block a user