2017-02-19 20:00:41 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import RxSwift
|
|
|
|
|
2017-02-28 12:20:25 +03:00
|
|
|
class OpenQuicklyTransformer {
|
2017-02-19 20:00:41 +03:00
|
|
|
|
2017-02-28 12:20:25 +03:00
|
|
|
let forMainWindow = MainWindowTransformer()
|
|
|
|
let forOpenQuicklyWindow = OpenQuicklyWindowTransformer()
|
|
|
|
}
|
|
|
|
|
|
|
|
extension OpenQuicklyTransformer {
|
2017-02-19 20:00:41 +03:00
|
|
|
|
2017-03-11 19:08:50 +03:00
|
|
|
class OpenQuicklyWindowTransformer: Reducer {
|
2017-02-19 20:00:41 +03:00
|
|
|
|
2017-02-28 12:20:25 +03:00
|
|
|
typealias Pair = StateActionPair<AppState, OpenQuicklyWindow.Action>
|
2017-02-19 20:00:41 +03:00
|
|
|
|
2017-02-28 12:20:25 +03:00
|
|
|
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
|
|
|
|
return source.map { pair in
|
2017-02-20 21:33:22 +03:00
|
|
|
var appState = pair.state
|
|
|
|
|
2017-02-28 12:20:25 +03:00
|
|
|
appState.openQuickly.open = false
|
|
|
|
appState.openQuickly.flatFileItems = Observable.empty()
|
|
|
|
appState.openQuickly.cwd = FileUtils.userHomeUrl
|
2017-02-20 21:33:22 +03:00
|
|
|
|
2017-02-28 12:20:25 +03:00
|
|
|
switch pair.action {
|
2017-02-20 21:33:22 +03:00
|
|
|
|
2017-02-28 12:20:25 +03:00
|
|
|
case let .open(url):
|
|
|
|
guard let uuid = appState.currentMainWindowUuid else {
|
|
|
|
return pair
|
|
|
|
}
|
2017-02-20 21:33:22 +03:00
|
|
|
|
2017-02-28 12:20:25 +03:00
|
|
|
appState.mainWindows[uuid]?.urlsToOpen.append(Marked([url: .newTab]))
|
2017-02-19 20:00:41 +03:00
|
|
|
|
2017-02-28 12:20:25 +03:00
|
|
|
case .close:
|
|
|
|
break
|
|
|
|
|
|
|
|
}
|
2017-02-19 20:00:41 +03:00
|
|
|
|
2017-02-28 12:20:25 +03:00
|
|
|
return StateActionPair(state: appState, action: pair.action)
|
2017-02-19 20:00:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-20 21:33:22 +03:00
|
|
|
|
2017-03-11 19:08:50 +03:00
|
|
|
class MainWindowTransformer: Reducer {
|
2017-02-20 21:33:22 +03:00
|
|
|
|
2017-02-28 12:20:25 +03:00
|
|
|
typealias Pair = StateActionPair<AppState, UuidAction<MainWindow.Action>>
|
2017-02-20 21:33:22 +03:00
|
|
|
|
2017-02-28 12:20:25 +03:00
|
|
|
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
|
|
|
|
return source.map { pair in
|
2017-02-23 00:51:24 +03:00
|
|
|
|
2017-02-28 12:20:25 +03:00
|
|
|
switch pair.action.payload {
|
2017-02-23 00:51:24 +03:00
|
|
|
|
2017-02-28 12:20:25 +03:00
|
|
|
case .openQuickly:
|
|
|
|
var appState = pair.state
|
2017-02-20 21:33:22 +03:00
|
|
|
|
2017-02-28 12:20:25 +03:00
|
|
|
guard let uuid = appState.currentMainWindowUuid else {
|
|
|
|
return pair
|
|
|
|
}
|
2017-02-20 21:33:22 +03:00
|
|
|
|
2017-02-28 12:20:25 +03:00
|
|
|
guard let cwd = appState.mainWindows[uuid]?.cwd else {
|
|
|
|
return pair
|
|
|
|
}
|
2017-02-23 00:51:24 +03:00
|
|
|
|
2017-02-28 12:20:25 +03:00
|
|
|
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
|
|
|
|
)
|
2017-02-20 21:33:22 +03:00
|
|
|
|
2017-02-28 12:20:25 +03:00
|
|
|
return StateActionPair(state: appState, action: pair.action)
|
2017-02-23 00:51:24 +03:00
|
|
|
|
2017-02-28 12:20:25 +03:00
|
|
|
default:
|
|
|
|
return pair
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2017-02-20 21:33:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|