/
basic_menu_events.go
62 lines (53 loc) · 2.12 KB
/
basic_menu_events.go
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
package main
import (
"fmt"
"github.com/miketheprogrammer/go-thrust/commands"
"github.com/miketheprogrammer/go-thrust/dispatcher"
"github.com/miketheprogrammer/go-thrust/menu"
"github.com/miketheprogrammer/go-thrust/spawn"
"github.com/miketheprogrammer/go-thrust/window"
)
func main() {
spawn.SetBaseDirectory("./")
spawn.Run()
thrustWindow := window.NewWindow("http://breach.cc/", nil)
thrustWindow.Show()
thrustWindow.Maximize()
thrustWindow.Focus()
// make our top menus
//applicationMenu, is essentially the menu bar
applicationMenu := menu.NewMenu()
//applicationMenuRoot is the first menu, on darwin this is always named the name of your application.
applicationMenuRoot := menu.NewMenu()
//File menu is our second menu
fileMenu := menu.NewMenu()
// Lets build our root menu.
// the first argument to AddItem is a CommandID
// A CommandID is used by Thrust Core to communicate back results and events.
applicationMenuRoot.AddItem(1, "About")
applicationMenuRoot.RegisterEventHandlerByCommandID(1,
func(reply commands.CommandResponse, item *menu.MenuItem) {
fmt.Println("About Handled")
})
// Now for the File menu
fileMenu.AddItem(2, "Open")
fileMenu.RegisterEventHandlerByCommandID(2,
func(reply commands.CommandResponse, item *menu.MenuItem) {
fmt.Println("Open Handled")
})
fileMenu.AddItem(3, "Edit")
fileMenu.AddSeparator()
fileMenu.AddItem(4, "Close")
// Now we just need to plumb our menus together any way we want.
applicationMenu.AddSubmenu(5, "Application", applicationMenuRoot)
applicationMenu.AddSubmenu(6, "File", fileMenu)
// Remember how in basic_browser, Window automatically self registered with the dispatcher.
// unfortunately we have no such luck here.
// I suppose this method could be added as an effect of SetApplicationMenu, but the effects of that need to be
// Ironed out.
// However, as least we only need to register the top level menu for events, all sub menus will delegate for the top menu.
// Now we set it as our application Menu
applicationMenu.SetApplicationMenu()
// BLOCKING - Dont run before youve excuted all commands you want first.
dispatcher.RunLoop()
}