1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-01 10:02:36 +03:00
vimr/VimR/UiRootReducer.swift
Tae Won Ha 7a4c5f955e
GH-436 Add an option in appearance pref pane
- Added a theme struct to VimR module for the case when the option is turned off
2017-06-27 06:41:16 +02:00

68 lines
1.9 KiB
Swift

/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Foundation
class UiRootReducer {
typealias Pair = StateActionPair<AppState, UuidAction<MainWindow.Action>>
func reduce(_ pair: Pair) -> Pair {
var appState = pair.state
let uuid = pair.action.uuid
switch pair.action.payload {
case .becomeKey:
appState.currentMainWindowUuid = uuid
appState.mainWindowTemplate = self.mainWindowTemplate(
from: appState.mainWindowTemplate, new: appState.mainWindows[uuid] ?? appState.mainWindowTemplate
)
case let .setToolsState(tools):
appState.mainWindowTemplate.orderedTools = tools.map { $0.0 }
case let .toggleAllTools(value):
appState.mainWindowTemplate.isAllToolsVisible = value
case let .toggleToolButtons(value):
appState.mainWindowTemplate.isToolButtonsVisible = value
case .close:
if appState.currentMainWindowUuid == uuid, let mainWindowToClose = appState.mainWindows[uuid] {
appState.mainWindowTemplate = self.mainWindowTemplate(from: appState.mainWindowTemplate,
new: mainWindowToClose)
appState.currentMainWindowUuid = nil
}
appState.mainWindows.removeValue(forKey: uuid)
case let .setTheme(theme):
appState.mainWindowTemplate.appearance.theme = Marked(theme)
default:
return pair
}
return StateActionPair(state: appState, action: pair.action)
}
fileprivate func mainWindowTemplate(from old: MainWindow.State, new: MainWindow.State) -> MainWindow.State {
var result = old
result.isAllToolsVisible = new.isAllToolsVisible
result.isToolButtonsVisible = new.isToolButtonsVisible
result.tools = new.tools
result.orderedTools = new.orderedTools
result.previewTool = new.previewTool
result.fileBrowserShowHidden = new.fileBrowserShowHidden
result.htmlPreview = .default
return result
}
}