2017-02-19 20:00:41 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import RxSwift
|
|
|
|
|
2017-03-29 21:10:11 +03:00
|
|
|
class OpenQuicklyReducer {
|
2017-02-19 20:00:41 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
typealias OpenQuicklyWindowPair = StateActionPair<AppState, OpenQuicklyWindow.Action>
|
|
|
|
typealias MainWindowPair = StateActionPair<AppState, UuidAction<MainWindow.Action>>
|
2017-02-19 20:00:41 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
func reduceOpenQuicklyWindow(_ pair: OpenQuicklyWindowPair) -> OpenQuicklyWindowPair {
|
|
|
|
var appState = pair.state
|
2017-02-20 21:33:22 +03:00
|
|
|
|
2017-04-30 10:25:15 +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-04-30 10:25:15 +03:00
|
|
|
switch pair.action {
|
2017-02-20 21:33:22 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
case let .open(url):
|
|
|
|
guard let uuid = appState.currentMainWindowUuid else {
|
|
|
|
return pair
|
|
|
|
}
|
2017-02-19 20:00:41 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
appState.mainWindows[uuid]?.urlsToOpen[url] = .newTab
|
2017-02-28 12:20:25 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
case .close:
|
|
|
|
break
|
2017-02-19 20:00:41 +03:00
|
|
|
|
|
|
|
}
|
2017-02-20 21:33:22 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
return StateActionPair(state: appState, action: pair.action)
|
|
|
|
}
|
2017-02-23 00:51:24 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
func reduceMainWindow(_ pair: MainWindowPair) -> MainWindowPair {
|
|
|
|
switch pair.action.payload {
|
2017-02-23 00:51:24 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
case .openQuickly:
|
|
|
|
var appState = pair.state
|
2017-02-20 21:33:22 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
guard let uuid = appState.currentMainWindowUuid else {
|
|
|
|
return pair
|
|
|
|
}
|
2017-02-20 21:33:22 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
guard let cwd = appState.mainWindows[uuid]?.cwd else {
|
|
|
|
return pair
|
|
|
|
}
|
2017-02-23 00:51:24 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
appState.openQuickly.open = true
|
|
|
|
appState.openQuickly.cwd = cwd
|
2017-02-20 21:33:22 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
return StateActionPair(state: appState, action: pair.action)
|
2017-02-23 00:51:24 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
default:
|
|
|
|
return pair
|
2017-02-28 12:20:25 +03:00
|
|
|
|
2017-02-20 21:33:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|