2017-02-24 02:24:30 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
class FileBrowserReducer {
|
2017-02-24 02:24:30 +03:00
|
|
|
|
2017-02-24 12:51:24 +03:00
|
|
|
typealias Pair = StateActionPair<UuidState<MainWindow.State>, FileBrowser.Action>
|
2017-02-24 02:24:30 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
func reduce(_ pair: Pair) -> Pair {
|
|
|
|
var state = pair.state.payload
|
2017-02-24 02:24:30 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
switch pair.action {
|
2017-02-24 02:24:30 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
case let .open(url, mode):
|
|
|
|
state.urlsToOpen[url] = mode
|
|
|
|
state.viewToBeFocused = .neoVimView
|
2017-02-24 02:24:30 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
case let .setAsWorkingDirectory(url):
|
|
|
|
state.cwd = url
|
2017-02-24 02:24:30 +03:00
|
|
|
|
2017-04-30 10:25:15 +03:00
|
|
|
case let .setShowHidden(show):
|
|
|
|
state.fileBrowserShowHidden = show
|
2017-02-26 12:55:07 +03:00
|
|
|
|
2017-05-12 00:33:59 +03:00
|
|
|
case .refresh:
|
|
|
|
guard let fileItem = FileItemUtils.item(for: state.cwd, root: state.root, create: false) else {
|
|
|
|
return pair
|
|
|
|
}
|
|
|
|
|
|
|
|
state.lastFileSystemUpdate = Marked(fileItem)
|
|
|
|
|
2017-02-24 02:24:30 +03:00
|
|
|
}
|
2017-04-30 10:25:15 +03:00
|
|
|
|
|
|
|
return StateActionPair(state: UuidState(uuid: state.uuid, state: state), action: pair.action)
|
2017-02-24 02:24:30 +03:00
|
|
|
}
|
|
|
|
}
|