1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-29 16:56:40 +03:00
vimr/NvimView/MinimalNvimViewDemo/Document.swift

79 lines
2.6 KiB
Swift
Raw Normal View History

2019-03-26 11:23:02 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
2019-03-22 18:45:00 +03:00
import Cocoa
import NvimView
import PureLayout
import RxSwift
class Document: NSDocument, NSWindowDelegate {
2019-03-27 13:02:27 +03:00
2019-03-26 11:23:02 +03:00
private var nvimView = NvimView(forAutoLayout: ())
private let disposeBag = DisposeBag()
2019-03-27 13:02:27 +03:00
2019-03-22 18:45:00 +03:00
override init() {
super.init()
2019-03-27 13:02:27 +03:00
2019-03-27 13:28:36 +03:00
self.nvimView.font = NSFont(name: "Fira Code", size: 13)
?? NSFont.userFixedPitchFont(ofSize: 13)!
self.nvimView.usesLigatures = true
2019-03-29 15:54:58 +03:00
self.nvimView.drawsParallel = true
2019-03-27 13:28:36 +03:00
2019-03-22 18:45:00 +03:00
nvimView
.events
2019-03-28 11:49:01 +03:00
.observeOn(MainScheduler.instance)
2019-03-22 18:45:00 +03:00
.subscribe(onNext: { event in
switch event {
2019-03-27 13:02:27 +03:00
2019-03-28 11:49:01 +03:00
case .neoVimStopped: self.close()
2019-03-27 13:02:27 +03:00
2019-03-27 13:28:36 +03:00
default: break //Swift.print("Event received: \(event)")
2019-03-27 13:02:27 +03:00
2019-03-22 18:45:00 +03:00
}
})
.disposed(by: self.disposeBag)
}
2019-03-27 13:02:27 +03:00
2019-03-28 11:49:01 +03:00
func quitWithoutSaving() {
try? self.nvimView.quitNeoVimWithoutSaving().wait()
self.nvimView.waitTillNvimExits()
2019-03-27 13:02:27 +03:00
}
2019-03-22 18:45:00 +03:00
func windowShouldClose(_ sender: NSWindow) -> Bool {
2019-03-28 11:49:01 +03:00
self.quitWithoutSaving()
2019-03-22 18:45:00 +03:00
return false
}
2019-03-27 13:02:27 +03:00
2019-03-22 18:45:00 +03:00
override func windowControllerDidLoadNib(_ windowController: NSWindowController) {
super.windowControllerDidLoadNib(windowController)
2019-03-27 13:02:27 +03:00
2019-03-22 18:45:00 +03:00
let window = windowController.window!
window.delegate = self
2019-03-27 13:02:27 +03:00
2019-03-22 18:45:00 +03:00
let view = window.contentView!
view.addSubview(self.nvimView)
self.nvimView.autoPinEdgesToSuperviewEdges()
}
2019-03-27 13:02:27 +03:00
2019-03-22 18:45:00 +03:00
override var windowNibName: NSNib.Name? {
// Returns the nib file name of the document
// If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this property and override -makeWindowControllers instead.
return NSNib.Name("Document")
}
2019-03-27 13:02:27 +03:00
2019-03-22 18:45:00 +03:00
override func data(ofType typeName: String) throws -> Data {
// Insert code here to write your document to data of the specified type, throwing an error in case of failure.
// Alternatively, you could remove this method and override fileWrapper(ofType:), write(to:ofType:), or write(to:ofType:for:originalContentsURL:) instead.
throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil)
}
2019-03-27 13:02:27 +03:00
2019-03-22 18:45:00 +03:00
override func read(from data: Data, ofType typeName: String) throws {
// Insert code here to read your document from the given data of the specified type, throwing an error in case of failure.
// Alternatively, you could remove this method and override read(from:ofType:) instead.
// If you do, you should also override isEntireFileLoaded to return false if the contents are lazily loaded.
throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil)
}
}