2023-01-14 19:47:29 +00:00
|
|
|
package app
|
|
|
|
|
2023-01-20 15:27:51 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
"github.com/wailsapp/wails/v2/pkg/menu"
|
|
|
|
"github.com/wailsapp/wails/v2/pkg/menu/keys"
|
|
|
|
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"
|
|
|
|
)
|
2023-01-14 19:47:29 +00:00
|
|
|
|
|
|
|
type App struct {
|
|
|
|
ctx context.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewApp() *App {
|
|
|
|
return &App{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *App) Startup(ctx context.Context) {
|
|
|
|
a.ctx = ctx
|
|
|
|
}
|
2023-01-20 15:27:51 +00:00
|
|
|
|
2023-01-23 13:12:14 +00:00
|
|
|
func menuEventEmitter(a *App, eventName string, data ...interface{}) func(cd *menu.CallbackData) {
|
|
|
|
return func(cd *menu.CallbackData) {
|
|
|
|
wailsRuntime.EventsEmit(a.ctx, eventName, data...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-20 15:27:51 +00:00
|
|
|
func (a *App) Menu() *menu.Menu {
|
|
|
|
appMenu := menu.NewMenu()
|
|
|
|
|
|
|
|
aboutMenu := appMenu.AddSubmenu("About")
|
2023-01-23 13:12:14 +00:00
|
|
|
aboutMenu.AddText("About…", nil, menuEventEmitter(a, "OpenAboutModal"))
|
|
|
|
aboutMenu.AddText("Prefrences…", keys.CmdOrCtrl(","), menuEventEmitter(a, "OpenPrefrences"))
|
2023-01-20 15:27:51 +00:00
|
|
|
aboutMenu.AddSeparator()
|
2023-01-23 13:12:14 +00:00
|
|
|
aboutMenu.AddText("Quit", keys.CmdOrCtrl("q"), func(cd *menu.CallbackData) { wailsRuntime.Quit(a.ctx) })
|
2023-01-20 15:27:51 +00:00
|
|
|
|
2023-01-20 15:28:36 +00:00
|
|
|
if runtime.GOOS == "darwin" {
|
|
|
|
appMenu.Append(menu.EditMenu())
|
|
|
|
}
|
|
|
|
|
2023-01-23 13:12:14 +00:00
|
|
|
hostMenu := appMenu.AddSubmenu("Host")
|
|
|
|
hostMenu.AddText("New host", keys.CmdOrCtrl("y"), menuEventEmitter(a, "CreateHost"))
|
|
|
|
|
|
|
|
databaseMenu := appMenu.AddSubmenu("Database")
|
|
|
|
databaseMenu.AddText("New database", keys.CmdOrCtrl("u"), menuEventEmitter(a, "CreateDatabase"))
|
|
|
|
|
|
|
|
collectionMenu := appMenu.AddSubmenu("Collection")
|
|
|
|
collectionMenu.AddText("New collection", keys.CmdOrCtrl("i"), menuEventEmitter(a, "CreateCollection"))
|
|
|
|
collectionMenu.AddSeparator()
|
|
|
|
collectionMenu.AddText("Stats", keys.Combo("h", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuEventEmitter(a, "OpenCollectionTab", "stats"))
|
|
|
|
collectionMenu.AddText("Find", keys.Combo("f", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuEventEmitter(a, "OpenCollectionTab", "find"))
|
|
|
|
collectionMenu.AddText("Insert", keys.Combo("i", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuEventEmitter(a, "OpenCollectionTab", "insert"))
|
|
|
|
collectionMenu.AddText("Update", keys.Combo("u", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuEventEmitter(a, "OpenCollectionTab", "update"))
|
|
|
|
collectionMenu.AddText("Remove", keys.Combo("r", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuEventEmitter(a, "OpenCollectionTab", "remove"))
|
|
|
|
collectionMenu.AddText("Indexes", keys.Combo("x", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuEventEmitter(a, "OpenCollectionTab", "indexes"))
|
|
|
|
|
2023-01-20 15:27:51 +00:00
|
|
|
helpMenu := appMenu.AddSubmenu("Help")
|
2023-01-23 13:12:14 +00:00
|
|
|
helpMenu.AddText("User guide", nil, func(cd *menu.CallbackData) { wailsRuntime.BrowserOpenURL(a.ctx, "") })
|
2023-01-20 15:27:51 +00:00
|
|
|
|
|
|
|
return appMenu
|
|
|
|
}
|