From 31a3d0621c3fe7de929d4492536b308c9ae106e4 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Tue, 4 Oct 2016 00:23:54 +0200 Subject: [PATCH 1/7] GH-286 React to file system changes in file browser --- VimR/AppDelegate.swift | 3 +-- VimR/FileBrowserComponent.swift | 18 ++++++++++++++++++ VimR/FileItem.swift | 2 +- VimR/FileItemService.swift | 11 ++++++++++- VimR/MainWindowComponent.swift | 2 ++ 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/VimR/AppDelegate.swift b/VimR/AppDelegate.swift index 6eb09a9a..8a8389e0 100644 --- a/VimR/AppDelegate.swift +++ b/VimR/AppDelegate.swift @@ -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() diff --git a/VimR/FileBrowserComponent.swift b/VimR/FileBrowserComponent.swift index 58f7f2ff..4aa952ef 100644 --- a/VimR/FileBrowserComponent.swift +++ b/VimR/FileBrowserComponent.swift @@ -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() { diff --git a/VimR/FileItem.swift b/VimR/FileItem.swift index d3d91eeb..5a2c7303 100644 --- a/VimR/FileItem.swift +++ b/VimR/FileItem.swift @@ -28,7 +28,7 @@ class FileItem : CustomStringConvertible { var children: [FileItem] = [] var description: String { - return "