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
|
|
|
|
|
|
|
|
typealias ActionEmitter = Emitter<Any>
|
|
|
|
|
|
|
|
class Emitter<T> {
|
|
|
|
|
|
|
|
let observable: Observable<T>
|
|
|
|
|
|
|
|
init() {
|
|
|
|
self.observable = self.subject.asObservable().observeOn(scheduler)
|
|
|
|
}
|
|
|
|
|
|
|
|
func emit(_ action: T) {
|
|
|
|
self.subject.onNext(action)
|
|
|
|
}
|
|
|
|
|
|
|
|
deinit {
|
|
|
|
self.subject.onCompleted()
|
|
|
|
}
|
|
|
|
|
|
|
|
fileprivate let scheduler = SerialDispatchQueueScheduler(qos: .userInitiated)
|
|
|
|
fileprivate let subject = PublishSubject<T>()
|
|
|
|
}
|
|
|
|
|
|
|
|
class StateActionPair<S, A> {
|
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
let modified: Bool
|
2017-01-17 21:47:59 +03:00
|
|
|
let state: S
|
|
|
|
let action: A
|
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
init(state: S, action: A, modified: Bool = true) {
|
|
|
|
self.modified = modified
|
2017-01-17 21:47:59 +03:00
|
|
|
self.state = state
|
|
|
|
self.action = action
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class UuidAction<A>: CustomStringConvertible {
|
|
|
|
|
|
|
|
let uuid: String
|
|
|
|
let payload: A
|
|
|
|
|
|
|
|
var description: String {
|
|
|
|
return "UuidAction(uuid: \(uuid), payload: \(String(reflecting: payload)))"
|
|
|
|
}
|
|
|
|
|
|
|
|
init(uuid: String, action: A) {
|
|
|
|
self.uuid = uuid
|
|
|
|
self.payload = action
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class UuidState<S>: CustomStringConvertible {
|
|
|
|
|
|
|
|
let uuid: String
|
|
|
|
let payload: S
|
|
|
|
|
|
|
|
var description: String {
|
2017-02-03 00:39:05 +03:00
|
|
|
return "UuidState(uuid: \(uuid), payload: \(String(reflecting: payload)))"
|
2017-01-17 21:47:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
init(uuid: String, state: S) {
|
|
|
|
self.uuid = uuid
|
|
|
|
self.payload = state
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
protocol Morpher {
|
2017-01-17 21:47:59 +03:00
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
associatedtype In
|
|
|
|
associatedtype Out
|
2017-01-17 21:47:59 +03:00
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
func transform(_ source: Observable<In>) -> Observable<Out>
|
2017-01-17 21:47:59 +03:00
|
|
|
}
|
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
protocol Transformer: Morpher {
|
2017-01-17 21:47:59 +03:00
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
associatedtype Element
|
2017-01-17 21:47:59 +03:00
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
typealias In = Element
|
|
|
|
typealias Out = Element
|
2017-01-17 21:47:59 +03:00
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
func transform(_ source: Observable<Element>) -> Observable<Element>
|
2017-01-17 21:47:59 +03:00
|
|
|
}
|
|
|
|
|
2017-02-05 17:17:25 +03:00
|
|
|
protocol Service {
|
|
|
|
|
|
|
|
associatedtype Element
|
|
|
|
|
|
|
|
func apply(_: Element)
|
|
|
|
}
|
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
struct AppState {
|
2017-01-17 21:47:59 +03:00
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
static let `default` = AppState(mainWindow: MainWindow.State.default)
|
2017-01-17 21:47:59 +03:00
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
var currentMainWindow: MainWindow.State
|
|
|
|
var mainWindows: [String: MainWindow.State] = [:]
|
2017-01-17 21:47:59 +03:00
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
let baseServerUrl: URL
|
2017-01-17 21:47:59 +03:00
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
init(mainWindow: MainWindow.State) {
|
|
|
|
self.baseServerUrl = URL(string: "http://localhost:\(NetUtils.openPort())")!
|
|
|
|
self.currentMainWindow = mainWindow
|
2017-01-17 21:47:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-06 00:39:55 +03:00
|
|
|
struct PreviewState {
|
2017-02-03 00:39:05 +03:00
|
|
|
|
2017-02-06 00:39:55 +03:00
|
|
|
static let `default` = PreviewState(buffer: nil, html: nil, server: nil)
|
|
|
|
|
|
|
|
var buffer: URL?
|
|
|
|
var html: URL?
|
|
|
|
var server: URL?
|
2017-02-03 00:39:05 +03:00
|
|
|
}
|
|
|
|
|
2017-01-17 21:47:59 +03:00
|
|
|
extension MainWindow {
|
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
struct State {
|
2017-01-17 21:47:59 +03:00
|
|
|
|
2017-02-04 17:34:13 +03:00
|
|
|
static let `default` = State(isAllToolsVisible: true, isToolButtonsVisible: true)
|
2017-01-17 21:47:59 +03:00
|
|
|
|
|
|
|
var isAllToolsVisible = true
|
|
|
|
var isToolButtonsVisible = true
|
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
////// transient
|
|
|
|
|
2017-02-06 00:39:55 +03:00
|
|
|
var preview = PreviewState.default
|
2017-02-04 17:34:13 +03:00
|
|
|
var isClosed = false
|
2017-02-03 00:39:05 +03:00
|
|
|
|
2017-01-22 16:22:05 +03:00
|
|
|
// neovim
|
2017-01-17 21:47:59 +03:00
|
|
|
var uuid = UUID().uuidString
|
2017-01-22 16:22:05 +03:00
|
|
|
var currentBuffer: NeoVimBuffer?
|
2017-01-17 21:47:59 +03:00
|
|
|
var buffers = [NeoVimBuffer]()
|
|
|
|
var cwd = FileUtils.userHomeUrl
|
|
|
|
|
|
|
|
var isDirty = false
|
|
|
|
|
|
|
|
var font = NSFont.userFixedPitchFont(ofSize: 13)!
|
|
|
|
var linespacing: CGFloat = 1
|
|
|
|
var isUseLigatures = false
|
|
|
|
var isUseInteractiveZsh = false
|
|
|
|
|
|
|
|
// transient^2
|
|
|
|
var urlsToOpen = [URL: OpenMode]()
|
|
|
|
|
2017-02-04 17:34:13 +03:00
|
|
|
init(isAllToolsVisible: Bool, isToolButtonsVisible: Bool) {
|
2017-01-17 21:47:59 +03:00
|
|
|
self.isAllToolsVisible = isAllToolsVisible
|
|
|
|
self.isToolButtonsVisible = isToolButtonsVisible
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|