mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-28 08:13:17 +03:00
Better queue handling
This commit is contained in:
parent
c21abb2272
commit
c52a0e077d
@ -16,10 +16,6 @@ class FileMonitorReducer: ReducerType {
|
|||||||
switch tuple.action {
|
switch tuple.action {
|
||||||
|
|
||||||
case let .change(in: url):
|
case let .change(in: url):
|
||||||
if let fileItem = FileItemUtils.item(for: url, root: state.openQuickly.root, create: false) {
|
|
||||||
fileItem.needsScanChildren = true
|
|
||||||
}
|
|
||||||
|
|
||||||
state.mainWindows
|
state.mainWindows
|
||||||
.filter { (uuid, mainWindow) in url == mainWindow.cwd || url.isContained(in: mainWindow.cwd) }
|
.filter { (uuid, mainWindow) in url == mainWindow.cwd || url.isContained(in: mainWindow.cwd) }
|
||||||
.map { $0.0 }
|
.map { $0.0 }
|
||||||
|
@ -17,7 +17,6 @@ class OpenQuicklyReducer: ReducerType {
|
|||||||
var appState = pair.state
|
var appState = pair.state
|
||||||
|
|
||||||
appState.openQuickly.open = false
|
appState.openQuickly.open = false
|
||||||
appState.openQuickly.flatFileItems = Observable.empty()
|
|
||||||
appState.openQuickly.cwd = FileUtils.userHomeUrl
|
appState.openQuickly.cwd = FileUtils.userHomeUrl
|
||||||
|
|
||||||
switch pair.action {
|
switch pair.action {
|
||||||
|
@ -7,6 +7,7 @@ import Cocoa
|
|||||||
import RxSwift
|
import RxSwift
|
||||||
import RxCocoa
|
import RxCocoa
|
||||||
import PureLayout
|
import PureLayout
|
||||||
|
import os
|
||||||
|
|
||||||
class OpenQuicklyWindow: NSObject,
|
class OpenQuicklyWindow: NSObject,
|
||||||
UiComponent,
|
UiComponent,
|
||||||
@ -31,8 +32,6 @@ class OpenQuicklyWindow: NSObject,
|
|||||||
.throttle(.milliseconds(2 * 500), latest: true, scheduler: MainScheduler.instance)
|
.throttle(.milliseconds(2 * 500), latest: true, scheduler: MainScheduler.instance)
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
|
|
||||||
self.fileService = FileService(root: self.cwd)
|
|
||||||
|
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
self.window.delegate = self
|
self.window.delegate = self
|
||||||
@ -42,6 +41,8 @@ class OpenQuicklyWindow: NSObject,
|
|||||||
source
|
source
|
||||||
.observeOn(MainScheduler.instance)
|
.observeOn(MainScheduler.instance)
|
||||||
.subscribe(onNext: { state in
|
.subscribe(onNext: { state in
|
||||||
|
self.updateRootUrls(state: state)
|
||||||
|
|
||||||
guard state.openQuickly.open else {
|
guard state.openQuickly.open else {
|
||||||
self.windowController.close()
|
self.windowController.close()
|
||||||
return
|
return
|
||||||
@ -81,6 +82,9 @@ class OpenQuicklyWindow: NSObject,
|
|||||||
private(set) var cwd = FileUtils.userHomeUrl
|
private(set) var cwd = FileUtils.userHomeUrl
|
||||||
private var cwdPathCompsCount = 0
|
private var cwdPathCompsCount = 0
|
||||||
|
|
||||||
|
private var fileServicesPerRootUrl: [URL: FileService] = [:]
|
||||||
|
private var rootUrls: Set<URL> { Set(self.fileServicesPerRootUrl.map { url, _ in url }) }
|
||||||
|
|
||||||
// FIXME: migrate to State later...
|
// FIXME: migrate to State later...
|
||||||
private(set) var pattern = ""
|
private(set) var pattern = ""
|
||||||
@objc private(set) var fileViewItems = [ScoredUrl]()
|
@objc private(set) var fileViewItems = [ScoredUrl]()
|
||||||
@ -96,12 +100,36 @@ class OpenQuicklyWindow: NSObject,
|
|||||||
private let fileView = NSTableView.standardTableView()
|
private let fileView = NSTableView.standardTableView()
|
||||||
|
|
||||||
private let searchStream: Observable<String>
|
private let searchStream: Observable<String>
|
||||||
private let fileService: FileService
|
|
||||||
|
private let log = OSLog(subsystem: Defs.loggerSubsystem,
|
||||||
|
category: Defs.LoggerCategory.uiComponents)
|
||||||
|
|
||||||
private var window: NSWindow {
|
private var window: NSWindow {
|
||||||
return self.windowController.window!
|
return self.windowController.window!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func updateRootUrls(state: AppState) {
|
||||||
|
let urlsToMonitor = Set(state.mainWindows.map { $1.cwd })
|
||||||
|
|
||||||
|
let newUrls = urlsToMonitor.subtracting(self.rootUrls)
|
||||||
|
let obsoleteUrls = self.rootUrls.subtracting(urlsToMonitor)
|
||||||
|
|
||||||
|
newUrls.forEach { url in
|
||||||
|
self.log.info("Adding \(url) and its service.")
|
||||||
|
guard let service = try? FileService(root: url) else {
|
||||||
|
self.log.error("Could not create FileService for \(url)")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
self.fileServicesPerRootUrl[url] = service
|
||||||
|
}
|
||||||
|
|
||||||
|
obsoleteUrls.forEach { url in
|
||||||
|
self.log.info("Removing \(url) and its service.")
|
||||||
|
self.fileServicesPerRootUrl.removeValue(forKey: url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func addViews() {
|
private func addViews() {
|
||||||
let searchField = self.searchField
|
let searchField = self.searchField
|
||||||
searchField.rx.delegate.setForwardToDelegate(self, retainDelegate: false)
|
searchField.rx.delegate.setForwardToDelegate(self, retainDelegate: false)
|
||||||
|
@ -80,9 +80,6 @@ extension OpenQuicklyWindow {
|
|||||||
case ignorePatterns = "ignore-patterns"
|
case ignorePatterns = "ignore-patterns"
|
||||||
}
|
}
|
||||||
|
|
||||||
let root = FileItem(URL(fileURLWithPath: "/", isDirectory: true))
|
|
||||||
|
|
||||||
var flatFileItems = Observable<[FileItem]>.empty()
|
|
||||||
var cwd = FileUtils.userHomeUrl
|
var cwd = FileUtils.userHomeUrl
|
||||||
var ignorePatterns = State.defaultIgnorePatterns
|
var ignorePatterns = State.defaultIgnorePatterns
|
||||||
var ignoreToken = Token()
|
var ignoreToken = Token()
|
||||||
|
Loading…
Reference in New Issue
Block a user