2017-01-22 16:22:05 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
2017-01-17 21:47:59 +03:00
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import RxSwift
|
|
|
|
|
2017-03-29 21:10:11 +03:00
|
|
|
class MainWindowReducer: Reducer {
|
2017-01-17 21:47:59 +03:00
|
|
|
|
|
|
|
typealias Pair = StateActionPair<UuidState<MainWindow.State>, MainWindow.Action>
|
|
|
|
|
2017-03-29 21:17:45 +03:00
|
|
|
func reduce(_ source: Observable<Pair>) -> Observable<Pair> {
|
2017-01-17 21:47:59 +03:00
|
|
|
return source.map { pair in
|
|
|
|
var state = pair.state.payload
|
|
|
|
|
|
|
|
switch pair.action {
|
|
|
|
|
2017-02-23 00:51:24 +03:00
|
|
|
case let .cd(to:cwd):
|
2017-01-17 21:47:59 +03:00
|
|
|
if state.cwd != cwd {
|
|
|
|
state.cwd = cwd
|
|
|
|
}
|
|
|
|
|
|
|
|
case let .setBufferList(buffers):
|
|
|
|
state.buffers = buffers
|
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
case let .setCurrentBuffer(buffer):
|
|
|
|
state.currentBuffer = buffer
|
|
|
|
|
2017-02-26 12:26:37 +03:00
|
|
|
case let .setDirtyStatus(status):
|
2017-03-20 00:05:22 +03:00
|
|
|
// When I gt or w around, we change tab somehow... Dunno why...
|
|
|
|
if status == pair.state.payload.isDirty {
|
|
|
|
return pair
|
|
|
|
}
|
|
|
|
|
2017-02-26 12:26:37 +03:00
|
|
|
state.isDirty = status
|
|
|
|
|
2017-02-23 00:51:24 +03:00
|
|
|
// if we scroll for reverse search we get scroll and set cursor event
|
|
|
|
case let .setCursor(to:position):
|
2017-02-12 18:40:49 +03:00
|
|
|
state.preview.forceNextReverse = false
|
|
|
|
|
2017-02-11 20:32:22 +03:00
|
|
|
if state.preview.ignoreNextForward {
|
|
|
|
state.preview.editorPosition = Marked(mark: state.preview.editorPosition.mark, payload: position.payload)
|
|
|
|
state.preview.ignoreNextForward = false
|
|
|
|
} else {
|
|
|
|
state.preview.editorPosition = position
|
|
|
|
}
|
2017-02-07 00:54:22 +03:00
|
|
|
|
2017-02-25 00:47:32 +03:00
|
|
|
case let .focus(view):
|
2017-03-31 20:32:01 +03:00
|
|
|
state.viewToBeFocused = view
|
2017-02-25 00:47:32 +03:00
|
|
|
|
2017-02-28 17:52:48 +03:00
|
|
|
case let .setState(for: tool, with: workspaceTool):
|
2017-03-01 18:59:23 +03:00
|
|
|
state.tools[tool] = WorkspaceToolState(location: workspaceTool.location,
|
|
|
|
dimension: workspaceTool.dimension,
|
|
|
|
open: workspaceTool.isSelected)
|
|
|
|
if workspaceTool.isSelected {
|
|
|
|
state.tools
|
|
|
|
.filter { $0 != tool && $1.location == workspaceTool.location }
|
|
|
|
.forEach { state.tools[$0.0]?.open = false }
|
|
|
|
}
|
2017-02-28 17:52:48 +03:00
|
|
|
|
|
|
|
case let .toggleAllTools(value):
|
|
|
|
state.isAllToolsVisible = value
|
|
|
|
|
|
|
|
case let .toggleToolButtons(value):
|
|
|
|
state.isToolButtonsVisible = value
|
|
|
|
|
2017-01-17 21:47:59 +03:00
|
|
|
default:
|
2017-01-22 16:22:05 +03:00
|
|
|
return pair
|
2017-01-17 21:47:59 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return StateActionPair(state: UuidState(uuid: state.uuid, state: state), action: pair.action)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|