1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-18 19:21:39 +03:00
vimr/NvimView/Support/MinimalNvimViewDemo/Document.swift

86 lines
2.4 KiB
Swift
Raw Normal View History

2020-08-19 01:09:13 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Cocoa
import NvimView
import PureLayout
import RxSwift
import Tabs
2020-08-19 01:09:13 +03:00
class Document: NSDocument, NSWindowDelegate {
private var nvimView = NvimView(forAutoLayout: ())
private let disposeBag = DisposeBag()
override init() {
super.init()
self.nvimView.font = NSFont(name: "Fira Code", size: 13)
2020-09-18 23:51:51 +03:00
?? NSFont.userFixedPitchFont(ofSize: 13)!
2020-08-19 01:09:13 +03:00
self.nvimView.usesLigatures = true
self.nvimView.drawsParallel = true
2020-09-18 23:51:51 +03:00
self.nvimView
2020-08-19 01:09:13 +03:00
.events
2022-06-17 17:48:30 +03:00
.observe(on: MainScheduler.instance)
2020-08-19 01:09:13 +03:00
.subscribe(onNext: { event in
switch event {
case .neoVimStopped: self.close()
default: break
}
})
.disposed(by: self.disposeBag)
}
func quitWithoutSaving() {
try? self.nvimView.quitNeoVimWithoutSaving().wait()
self.nvimView.waitTillNvimExits()
}
2020-09-18 23:51:51 +03:00
func windowShouldClose(_: NSWindow) -> Bool {
2020-08-19 01:09:13 +03:00
self.quitWithoutSaving()
return false
}
override func windowControllerDidLoadNib(_ windowController: NSWindowController) {
super.windowControllerDidLoadNib(windowController)
let window = windowController.window!
window.delegate = self
let view = window.contentView!
2021-01-09 10:59:24 +03:00
let nvimView = self.nvimView
// We know that we use custom tabs.
let tabBar = nvimView.tabBar!
// FIXME: Find out why we have to add tabBar after adding ws, otherwise tabBar is not visible
// With deployment target 10_15, adding first tabBar worked fine.
2021-01-09 10:59:24 +03:00
view.addSubview(nvimView)
view.addSubview(tabBar)
2021-01-09 10:59:24 +03:00
tabBar.autoPinEdge(toSuperviewEdge: .left)
tabBar.autoPinEdge(toSuperviewEdge: .top)
tabBar.autoPinEdge(toSuperviewEdge: .right)
// tabBar.autoSetDimension(.height, toSize: Tabs.Theme().tabBarHeight)
// nvimView.autoPinEdge(.top, to: .bottom, of: tabBar)
nvimView.autoPinEdge(toSuperviewEdge: .top, withInset: 50)
2021-01-09 10:59:24 +03:00
nvimView.autoPinEdge(toSuperviewEdge: .left)
nvimView.autoPinEdge(toSuperviewEdge: .right)
nvimView.autoPinEdge(toSuperviewEdge: .bottom)
2020-08-19 01:09:13 +03:00
}
override var windowNibName: NSNib.Name? {
2020-09-18 23:51:51 +03:00
NSNib.Name("Document")
2020-08-19 01:09:13 +03:00
}
2020-09-18 23:51:51 +03:00
override func data(ofType _: String) throws -> Data {
2020-08-19 01:09:13 +03:00
throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil)
}
2020-09-18 23:51:51 +03:00
override func read(from _: Data, ofType _: String) throws {
2020-08-19 01:09:13 +03:00
throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil)
}
}