1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-29 16:56:40 +03:00
vimr/VimR/OpenQuicklyReducer.swift

63 lines
1.4 KiB
Swift
Raw Normal View History

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-04-30 10:25:15 +03:00
appState.openQuickly.open = false
appState.openQuickly.flatFileItems = Observable.empty()
appState.openQuickly.cwd = FileUtils.userHomeUrl
2017-04-30 10:25:15 +03:00
switch pair.action {
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-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-04-30 10:25:15 +03:00
guard let uuid = appState.currentMainWindowUuid else {
return pair
}
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-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
}
}
}