1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-26 23:36:08 +03:00
vimr/VimR/MainWindowReducer.swift

93 lines
2.6 KiB
Swift
Raw Normal View History

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