2017-02-24 02:24:30 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import RxSwift
|
|
|
|
|
2017-02-24 12:51:24 +03:00
|
|
|
class FileBrowserTransformer: Transformer {
|
2017-02-24 02:24:30 +03:00
|
|
|
|
2017-02-24 12:51:24 +03:00
|
|
|
typealias Pair = StateActionPair<UuidState<MainWindow.State>, FileBrowser.Action>
|
2017-02-24 02:24:30 +03:00
|
|
|
|
|
|
|
func transform(_ source: Observable<Pair>) -> Observable<Pair> {
|
|
|
|
return source.map { pair in
|
|
|
|
var state = pair.state.payload
|
|
|
|
|
|
|
|
switch pair.action {
|
|
|
|
|
|
|
|
case let .open(url, mode):
|
|
|
|
state.urlsToOpen.append(Marked([url: mode]))
|
2017-02-25 00:47:32 +03:00
|
|
|
state.focusedView = .neoVimView
|
2017-02-24 02:24:30 +03:00
|
|
|
|
|
|
|
case let .setAsWorkingDirectory(url):
|
|
|
|
state.cwd = url
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return StateActionPair(state: UuidState(uuid: state.uuid, state: state), action: pair.action)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|