-
Notifications
You must be signed in to change notification settings - Fork 0
/
macsplitviewtest.swift
75 lines (62 loc) · 2.16 KB
/
macsplitviewtest.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// 3 january 2016
// scratch program 17 august 2015
import Cocoa
import WebKit
var keepAliveMainwin: NSWindow? = nil
func appLaunched() {
let mainwin = NSWindow(
contentRect: NSMakeRect(0, 0, 320, 240),
styleMask: (NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask),
backing: NSBackingStoreType.Buffered,
`defer`: true)
let contentView = mainwin.contentView!
let splitView = NSSplitView(frame: NSZeroRect)
splitView.dividerStyle = NSSplitViewDividerStyle.Thin
splitView.vertical = true
splitView.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(splitView)
let box1 = NSScrollView(frame: NSZeroRect)
let ov = NSOutlineView(frame: NSZeroRect)
ov.headerView = nil
ov.selectionHighlightStyle = NSTableViewSelectionHighlightStyle.SourceList
box1.documentView = ov
box1.translatesAutoresizingMaskIntoConstraints = false
splitView.addSubview(box1)
let box2 = WebView(frame: NSZeroRect)
box2.translatesAutoresizingMaskIntoConstraints = false
splitView.addSubview(box2)
let views: [String: NSView] = [
"splitView": splitView,
]
addConstraint(contentView, "H:|-[splitView]-|", views)
addConstraint(contentView, "V:|-[splitView]-|", views)
splitView.setPosition(50, ofDividerAtIndex: 0)
mainwin.cascadeTopLeftFromPoint(NSMakePoint(20, 20))
mainwin.makeKeyAndOrderFront(mainwin)
keepAliveMainwin = mainwin
}
func addConstraint(view: NSView, _ constraint: String, _ views: [String: NSView]) {
let constraints = NSLayoutConstraint.constraintsWithVisualFormat(
constraint,
options: [],
metrics: nil,
views: views)
view.addConstraints(constraints)
}
class appDelegate : NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(note: NSNotification) {
appLaunched()
}
func applicationShouldTerminateAfterLastWindowClosed(app: NSApplication) -> Bool {
return true
}
}
func main() {
let app = NSApplication.sharedApplication()
app.setActivationPolicy(NSApplicationActivationPolicy.Regular)
// NSApplication.delegate is weak; if we don't use the temporary variable, the delegate will die before it's used
let delegate = appDelegate()
app.delegate = delegate
app.run()
}
main()