37 lines
1 KiB
Swift
37 lines
1 KiB
Swift
|
|
import Cocoa
|
||
|
|
|
||
|
|
class LogWindowController: NSWindowController {
|
||
|
|
|
||
|
|
var textView: NSTextView!
|
||
|
|
|
||
|
|
convenience init() {
|
||
|
|
|
||
|
|
let contentRect = NSRect(x: 0, y: 0, width: 600, height: 400)
|
||
|
|
let styleMask: NSWindow.StyleMask = [.titled, .closable, .resizable]
|
||
|
|
|
||
|
|
let window = NSWindow(contentRect: contentRect,
|
||
|
|
styleMask: styleMask,
|
||
|
|
backing: .buffered,
|
||
|
|
defer: false)
|
||
|
|
|
||
|
|
self.init(window: window)
|
||
|
|
|
||
|
|
window.title = "Logs"
|
||
|
|
|
||
|
|
let scrollView = NSScrollView(frame: window.contentView!.bounds)
|
||
|
|
scrollView.autoresizingMask = [.width, .height]
|
||
|
|
|
||
|
|
textView = NSTextView(frame: scrollView.bounds)
|
||
|
|
textView.isEditable = false
|
||
|
|
textView.autoresizingMask = [.width, .height]
|
||
|
|
|
||
|
|
scrollView.documentView = textView
|
||
|
|
window.contentView?.addSubview(scrollView)
|
||
|
|
}
|
||
|
|
|
||
|
|
func update(text: String) {
|
||
|
|
textView.string = text
|
||
|
|
textView.scrollToEndOfDocument(nil)
|
||
|
|
}
|
||
|
|
}
|