1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-18 04:57:59 +00:00

Simplify menu

This commit is contained in:
Romein van Buren 2023-05-30 19:56:59 +02:00
parent 8db05b7e3f
commit 918365ec93
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49

View File

@ -8,19 +8,25 @@ import (
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"
)
func menuEventEmitter(a *App, eventName string, data ...interface{}) func(cd *menu.CallbackData) {
func menuCallbackEmit(a *App, eventName string, data ...interface{}) func(cd *menu.CallbackData) {
return func(cd *menu.CallbackData) {
wailsRuntime.EventsEmit(a.ctx, eventName, data...)
}
}
func menuCallbackURL(a *App, url string) func(cd *menu.CallbackData) {
return func(cd *menu.CallbackData) {
wailsRuntime.BrowserOpenURL(a.ctx, url)
}
}
func (a *App) Menu() *menu.Menu {
appMenu := menu.NewMenu()
aboutMenu := appMenu.AddSubmenu("File")
aboutMenu.AddText("About Rolens", nil, menuEventEmitter(a, "OpenAboutModal"))
aboutMenu := appMenu.AddSubmenu("Rolens")
aboutMenu.AddText("About Rolens", nil, menuCallbackEmit(a, "OpenAboutModal"))
aboutMenu.AddSeparator()
aboutMenu.AddText("Prefrences…", keys.CmdOrCtrl(","), menuEventEmitter(a, "OpenPrefrences"))
aboutMenu.AddText("Prefrences…", keys.CmdOrCtrl(","), menuCallbackEmit(a, "OpenPrefrences"))
aboutMenu.AddSeparator()
aboutMenu.AddText("Open data directory…", nil, func(cd *menu.CallbackData) { a.ui.Reveal(a.Env.DataDirectory) })
aboutMenu.AddText("Open log directory…", nil, func(cd *menu.CallbackData) { a.ui.Reveal(a.Env.LogDirectory) })
@ -28,33 +34,29 @@ func (a *App) Menu() *menu.Menu {
aboutMenu.AddSeparator()
aboutMenu.AddText("Quit Rolens", keys.CmdOrCtrl("q"), func(cd *menu.CallbackData) { wailsRuntime.Quit(a.ctx) })
fileMenu := appMenu.AddSubmenu("File")
fileMenu.AddText("New host…", keys.CmdOrCtrl("y"), menuCallbackEmit(a, "CreateHost"))
fileMenu.AddText("New database", keys.CmdOrCtrl("y"), menuCallbackEmit(a, "CreateDatabase"))
fileMenu.AddText("New collection…", keys.CmdOrCtrl("i"), menuCallbackEmit(a, "CreateCollection"))
fileMenu.AddSeparator()
fileMenu.AddText("Stats", keys.Combo("h", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuCallbackEmit(a, "OpenCollectionTab", "stats"))
fileMenu.AddText("Find", keys.Combo("f", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuCallbackEmit(a, "OpenCollectionTab", "find"))
fileMenu.AddText("Insert", keys.Combo("i", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuCallbackEmit(a, "OpenCollectionTab", "insert"))
fileMenu.AddText("Update", keys.Combo("u", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuCallbackEmit(a, "OpenCollectionTab", "update"))
fileMenu.AddText("Remove", keys.Combo("r", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuCallbackEmit(a, "OpenCollectionTab", "remove"))
fileMenu.AddText("Indexes", keys.Combo("x", keys.CmdOrCtrlKey, keys.OptionOrAltKey), menuCallbackEmit(a, "OpenCollectionTab", "indexes"))
if runtime.GOOS == "darwin" {
appMenu.Append(menu.EditMenu())
}
hostMenu := appMenu.AddSubmenu("Host")
hostMenu.AddText("New host…", keys.CmdOrCtrl("y"), menuEventEmitter(a, "CreateHost"))
databaseMenu := appMenu.AddSubmenu("Database")
databaseMenu.Append(&menu.MenuItem{
Label: "New database…",
Accelerator: keys.CmdOrCtrl("u"),
Click: menuEventEmitter(a, "CreateDatabase"),
Disabled: a.State["currenthost"] == "",
})
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"))
helpMenu := appMenu.AddSubmenu("Help")
helpMenu.AddText("User guide", nil, func(cd *menu.CallbackData) { wailsRuntime.BrowserOpenURL(a.ctx, "") })
helpMenu.AddText("User guide", nil, menuCallbackURL(a, ""))
helpMenu.AddSeparator()
helpMenu.AddText("Report a problem", nil, menuCallbackURL(a, "https://github.com/garraflavatra/rolens/issues/new"))
helpMenu.AddSeparator()
helpMenu.AddText("Star Rolens on GitHub", nil, menuCallbackURL(a, "https://github.com/garraflavatra/rolens"))
helpMenu.AddText("License", nil, menuCallbackURL(a, "https://github.com/garraflavatra/rolens/blob/main/LICENSE"))
return appMenu
}