2017-02-19 20:00:41 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import RxSwift
|
|
|
|
|
2017-02-20 21:33:22 +03:00
|
|
|
class MainWindowToOpenQuicklyTransformer: Transformer {
|
2017-02-19 20:00:41 +03:00
|
|
|
|
2017-02-20 21:33:22 +03:00
|
|
|
typealias Pair = StateActionPair<AppState, UuidAction<MainWindow.Action>>
|
2017-02-19 20:00:41 +03:00
|
|
|
|
|
|
|
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
|
|
|
|
return source.map { pair in
|
|
|
|
|
2017-02-20 21:33:22 +03:00
|
|
|
switch pair.action.payload {
|
2017-02-19 20:00:41 +03:00
|
|
|
|
|
|
|
case .openQuickly:
|
2017-02-20 21:33:22 +03:00
|
|
|
var appState = pair.state
|
|
|
|
|
|
|
|
guard let uuid = appState.currentMainWindowUuid else {
|
|
|
|
return pair
|
|
|
|
}
|
|
|
|
|
|
|
|
guard let cwd = appState.mainWindows[uuid]?.cwd else {
|
|
|
|
return pair
|
|
|
|
}
|
|
|
|
|
|
|
|
appState.openQuickly.open = true
|
|
|
|
appState.openQuickly.cwd = cwd
|
|
|
|
appState.openQuickly.flatFileItems = FileItemUtils.flatFileItems(
|
|
|
|
ofUrl: cwd,
|
|
|
|
ignorePatterns: appState.openQuickly.ignorePatterns,
|
|
|
|
ignoreToken: appState.openQuickly.ignoreToken,
|
|
|
|
root: appState.root
|
|
|
|
)
|
|
|
|
|
|
|
|
return StateActionPair(state: appState, action: pair.action)
|
2017-02-19 20:00:41 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
return pair
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-20 21:33:22 +03:00
|
|
|
|
|
|
|
class OpenQuicklyTransformer: Transformer {
|
|
|
|
|
|
|
|
typealias Pair = StateActionPair<AppState, OpenQuicklyWindow.Action>
|
|
|
|
|
|
|
|
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
|
|
|
|
return source.map { pair in
|
|
|
|
switch pair.action {
|
|
|
|
|
|
|
|
case .close:
|
|
|
|
var appState = pair.state
|
|
|
|
|
|
|
|
appState.openQuickly.open = false
|
|
|
|
appState.openQuickly.flatFileItems = Observable.empty()
|
|
|
|
appState.openQuickly.cwd = FileUtils.userHomeUrl
|
|
|
|
|
|
|
|
return StateActionPair(state: appState, action: pair.action)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|