@@ -8,50 +8,43 @@ import (
88 "github.com/progrium/macdriver/objc"
99)
1010
11- // menus and tray
12-
13- // Arrange that main.main runs on main thread.
14- func init () {
11+ func main () {
1512 runtime .LockOSThread ()
16- }
1713
18- func initAndRun () {
1914 app := appkit .Application_SharedApplication ()
20- w := appkit .NewWindowWithSize (600 , 400 )
21- w .SetTitle ("Test" )
2215
23- // text field
24- textView := appkit .TextView_ScrollableTextView ()
25- textView .SetTranslatesAutoresizingMaskIntoConstraints (false )
26- tv := appkit .TextViewFrom (textView .DocumentView ().Ptr ())
27- tv .SetAllowsUndo (true )
28- tv .SetRichText (false )
29- w .ContentView ().AddSubview (textView )
30- w .ContentView ().LeadingAnchor ().ConstraintEqualToAnchorConstant (textView .LeadingAnchor (), - 10 ).SetActive (true )
31- w .ContentView ().TopAnchor ().ConstraintEqualToAnchorConstant (textView .TopAnchor (), - 10 ).SetActive (true )
32- w .ContentView ().TrailingAnchor ().ConstraintEqualToAnchorConstant (textView .TrailingAnchor (), 10 ).SetActive (true )
33- w .ContentView ().BottomAnchor ().ConstraintEqualToAnchorConstant (textView .BottomAnchor (), 10 ).SetActive (true )
16+ delegate := & appkit.ApplicationDelegate {}
17+ delegate .SetApplicationDidFinishLaunching (func (foundation.Notification ) {
18+ w := appkit .NewWindowWithSize (600 , 400 )
19+ objc .Retain (& w )
20+ w .SetTitle ("Test" )
21+
22+ textView := appkit .TextView_ScrollableTextView ()
23+ textView .SetTranslatesAutoresizingMaskIntoConstraints (false )
24+ tv := appkit .TextViewFrom (textView .DocumentView ().Ptr ())
25+ tv .SetAllowsUndo (true )
26+ tv .SetRichText (false )
27+ w .ContentView ().AddSubview (textView )
28+ w .ContentView ().LeadingAnchor ().ConstraintEqualToAnchorConstant (textView .LeadingAnchor (), - 10 ).SetActive (true )
29+ w .ContentView ().TopAnchor ().ConstraintEqualToAnchorConstant (textView .TopAnchor (), - 10 ).SetActive (true )
30+ w .ContentView ().TrailingAnchor ().ConstraintEqualToAnchorConstant (textView .TrailingAnchor (), 10 ).SetActive (true )
31+ w .ContentView ().BottomAnchor ().ConstraintEqualToAnchorConstant (textView .BottomAnchor (), 10 ).SetActive (true )
32+
33+ w .MakeKeyAndOrderFront (nil )
34+ w .Center ()
3435
35- w .MakeKeyAndOrderFront (nil )
36- w .Center ()
36+ setSystemBar (app )
3737
38- ad := & appkit.ApplicationDelegate {}
39- ad .SetApplicationDidFinishLaunching (func (foundation.Notification ) {
4038 app .SetActivationPolicy (appkit .ApplicationActivationPolicyRegular )
4139 app .ActivateIgnoringOtherApps (true )
4240 })
43- ad .SetApplicationWillFinishLaunching (func (foundation.Notification ) {
44- // should set menu bar at ApplicationWillFinishLaunching
41+ delegate .SetApplicationWillFinishLaunching (func (foundation.Notification ) {
4542 setMainMenu (app )
4643 })
47- ad .SetApplicationShouldTerminateAfterLastWindowClosed (func (appkit.Application ) bool {
44+ delegate .SetApplicationShouldTerminateAfterLastWindowClosed (func (appkit.Application ) bool {
4845 return true
4946 })
50- app .SetDelegate (ad )
51-
52- // should set system bar after window show
53- setSystemBar (app )
54-
47+ app .SetDelegate (delegate )
5548 app .Run ()
5649}
5750
@@ -69,8 +62,7 @@ func setMainMenu(app appkit.Application) {
6962 testMenuItem := appkit .NewMenuItemWithSelector ("" , "" , objc.Selector {})
7063 testMenu := appkit .NewMenuWithTitle ("Edit" )
7164 testMenu .AddItem (appkit .NewMenuItemWithSelector ("Select All" , "a" , objc .Sel ("selectAll:" )))
72- // missing symbol?
73- //testMenu.AddItem(appkit.MenuItem_SeparatorItem())
65+ testMenu .AddItem (appkit .MenuItem_SeparatorItem ())
7466 testMenu .AddItem (appkit .NewMenuItemWithSelector ("Copy" , "c" , objc .Sel ("copy:" )))
7567 testMenu .AddItem (appkit .NewMenuItemWithSelector ("Paste" , "v" , objc .Sel ("paste:" )))
7668 testMenu .AddItem (appkit .NewMenuItemWithSelector ("Cut" , "x" , objc .Sel ("cut:" )))
@@ -81,17 +73,12 @@ func setMainMenu(app appkit.Application) {
8173}
8274
8375func setSystemBar (app appkit.Application ) {
84- bar := appkit .StatusBar_SystemStatusBar ()
85- item := bar .StatusItemWithLength (appkit .VariableStatusItemLength )
86- button := item .Button ()
87- button .SetTitle ("TestTray" )
76+ item := appkit .StatusBar_SystemStatusBar ().StatusItemWithLength (appkit .VariableStatusItemLength )
77+ objc .Retain (& item )
78+ item .Button ().SetTitle ("TestTray" )
8879
8980 menu := appkit .NewMenuWithTitle ("main" )
9081 menu .AddItem (appkit .NewMenuItemWithAction ("Hide" , "h" , func (sender objc.Object ) { app .Hide (nil ) }))
9182 menu .AddItem (appkit .NewMenuItemWithAction ("Quit" , "q" , func (sender objc.Object ) { app .Terminate (nil ) }))
9283 item .SetMenu (menu )
9384}
94-
95- func main () {
96- initAndRun ()
97- }
0 commit comments