1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-18 13:07:58 +00:00
rolens/internal/app/app_menu.go

96 lines
5.2 KiB
Go
Raw Normal View History

2023-05-27 19:18:47 +00:00
package app
import (
"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-05-30 17:56:59 +00:00
func menuCallbackEmit(a *App, eventName string, data ...interface{}) func(cd *menu.CallbackData) {
2023-05-27 19:18:47 +00:00
return func(cd *menu.CallbackData) {
wailsRuntime.EventsEmit(a.ctx, eventName, data...)
}
}
2023-06-26 19:05:05 +00:00
func menuCallbackOpenURL(a *App, url string) func(cd *menu.CallbackData) {
2023-05-30 17:56:59 +00:00
return func(cd *menu.CallbackData) {
wailsRuntime.BrowserOpenURL(a.ctx, url)
}
}
2023-05-27 19:18:47 +00:00
func (a *App) Menu() *menu.Menu {
appMenu := menu.NewMenu()
2023-05-30 17:56:59 +00:00
aboutMenu := appMenu.AddSubmenu("Rolens")
aboutMenu.AddText("About Rolens", nil, menuCallbackEmit(a, "global.about"))
2023-05-27 19:18:47 +00:00
aboutMenu.AddSeparator()
aboutMenu.AddText("Preferences…", keys.CmdOrCtrl(","), menuCallbackEmit(a, "global.settings"))
2023-05-27 19:18:47 +00:00
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) })
2023-06-24 18:27:48 +00:00
aboutMenu.AddText("Purge logs…", nil, func(cd *menu.CallbackData) { a.PurgeLogDirectory() })
2023-05-27 19:18:47 +00:00
aboutMenu.AddSeparator()
2023-05-30 17:56:59 +00:00
2023-05-27 19:18:47 +00:00
if runtime.GOOS == "darwin" {
2023-06-26 19:05:05 +00:00
aboutMenu.AddText("Minimize", keys.CmdOrCtrl("M"), func(cd *menu.CallbackData) { wailsRuntime.WindowMinimise(a.ctx) })
aboutMenu.AddText("Hide Rolens", keys.CmdOrCtrl("H"), func(cd *menu.CallbackData) { wailsRuntime.WindowHide(a.ctx) })
aboutMenu.AddSeparator()
2023-06-24 20:10:25 +00:00
2023-06-26 19:05:05 +00:00
appMenu.Append(menu.EditMenu())
2023-05-27 19:18:47 +00:00
}
2023-06-29 07:50:18 +00:00
aboutMenu.AddText("Quit Rolens", keys.CmdOrCtrl("Q"), func(cd *menu.CallbackData) { wailsRuntime.Quit(a.ctx) })
2023-06-26 19:05:05 +00:00
hostMenu := appMenu.AddSubmenu("Host")
2023-06-29 07:50:18 +00:00
hostMenu.AddText("New…", keys.OptionOrAlt("C"), menuCallbackEmit(a, "ui.host.new"))
hostMenu.AddText("Edit host…", keys.OptionOrAlt("H"), menuCallbackEmit(a, "ui.host.edit"))
2023-06-26 19:05:05 +00:00
hostMenu.AddSeparator()
2023-08-26 18:27:44 +00:00
hostMenu.AddText("Host status", nil, menuCallbackEmit(a, "ui.host.tab", "status"))
2023-06-26 19:05:05 +00:00
hostMenu.AddText("Shell", nil, menuCallbackEmit(a, "ui.host.tab", "shell"))
2023-08-26 18:27:44 +00:00
hostMenu.AddText("Logs", nil, menuCallbackEmit(a, "ui.host.tab", "logs"))
hostMenu.AddText("System info", nil, menuCallbackEmit(a, "ui.host.tab", "systemInfo"))
2023-06-26 19:05:05 +00:00
hostMenu.AddSeparator()
hostMenu.AddText("Remove host…", nil, menuCallbackEmit(a, "ui.host.remove"))
dbMenu := appMenu.AddSubmenu("Database")
2023-06-29 07:50:18 +00:00
dbMenu.AddText("New…", keys.OptionOrAlt("D"), menuCallbackEmit(a, "ui.db.new"))
2023-06-26 19:05:05 +00:00
dbMenu.AddSeparator()
dbMenu.AddText("Database statistics", nil, menuCallbackEmit(a, "ui.db.tab", "stats"))
dbMenu.AddText("Shell", nil, menuCallbackEmit(a, "ui.db.tab", "shell"))
dbMenu.AddSeparator()
dbMenu.AddText("Dump…", nil, menuCallbackEmit(a, "ui.db.dump"))
dbMenu.AddText("Drop…", nil, menuCallbackEmit(a, "ui.db.drop"))
collMenu := appMenu.AddSubmenu("Collection")
2023-06-29 07:50:18 +00:00
collMenu.AddText("New…", keys.OptionOrAlt("T"), menuCallbackEmit(a, "ui.coll.new"))
2023-06-26 19:05:05 +00:00
collMenu.AddSeparator()
2023-06-29 07:50:18 +00:00
collMenu.AddText("Collection statistics", keys.Combo("S", keys.CmdOrCtrlKey, keys.ShiftKey), menuCallbackEmit(a, "ui.coll.tab", "stats"))
collMenu.AddText("Find", keys.Combo("F", keys.CmdOrCtrlKey, keys.ShiftKey), menuCallbackEmit(a, "ui.coll.tab", "find"))
collMenu.AddText("Insert", keys.Combo("I", keys.CmdOrCtrlKey, keys.ShiftKey), menuCallbackEmit(a, "ui.coll.tab", "insert"))
collMenu.AddText("Update", keys.Combo("P", keys.CmdOrCtrlKey, keys.ShiftKey), menuCallbackEmit(a, "ui.coll.tab", "update"))
collMenu.AddText("Remove", keys.Combo("R", keys.CmdOrCtrlKey, keys.ShiftKey), menuCallbackEmit(a, "ui.coll.tab", "remove"))
collMenu.AddText("Indexes", keys.Combo("X", keys.CmdOrCtrlKey, keys.ShiftKey), menuCallbackEmit(a, "ui.coll.tab", "indexes"))
collMenu.AddText("Aggregate", keys.Combo("A", keys.CmdOrCtrlKey, keys.ShiftKey), menuCallbackEmit(a, "ui.coll.tab", "aggregate"))
collMenu.AddText("Shell", keys.Combo("H", keys.CmdOrCtrlKey, keys.ShiftKey), menuCallbackEmit(a, "ui.coll.tab", "shell"))
2023-06-26 19:05:05 +00:00
collMenu.AddSeparator()
2023-06-29 07:50:18 +00:00
collMenu.AddText("Export…", keys.OptionOrAlt("E"), menuCallbackEmit(a, "ui.coll.exort"))
2023-06-26 19:05:05 +00:00
collMenu.AddText("Truncate…", nil, menuCallbackEmit(a, "ui.coll.truncate"))
collMenu.AddText("Drop…", nil, menuCallbackEmit(a, "ui.coll.drop"))
2023-05-27 19:18:47 +00:00
helpMenu := appMenu.AddSubmenu("Help")
2023-06-29 07:50:18 +00:00
helpMenu.AddText("User guide", keys.CmdOrCtrl("/"), menuCallbackOpenURL(a, "https://garraflavatra.github.io/rolens/user-guide/"))
2023-06-26 19:05:05 +00:00
helpMenu.AddText("Website", nil, menuCallbackOpenURL(a, "https://garraflavatra.github.io/rolens/"))
helpMenu.AddText("Discussion board", nil, menuCallbackOpenURL(a, "https://github.com/garraflavatra/rolens/discussions"))
2023-05-30 17:56:59 +00:00
helpMenu.AddSeparator()
2023-06-26 19:05:05 +00:00
helpMenu.AddText("Report a problem", nil, menuCallbackOpenURL(a, "https://github.com/garraflavatra/rolens/issues/new"))
helpMenu.AddText("Ask a question", nil, menuCallbackOpenURL(a, "https://github.com/garraflavatra/rolens/discussions/new?category=questions"))
2023-05-30 17:56:59 +00:00
helpMenu.AddSeparator()
2023-06-26 19:05:05 +00:00
helpMenu.AddText("Star Rolens on GitHub", nil, menuCallbackOpenURL(a, "https://github.com/garraflavatra/rolens"))
2023-06-29 12:37:39 +00:00
helpMenu.AddText("Changelog", nil, menuCallbackOpenURL(a, "https://garraflavatra.github.io/rolens/colophon/changelog/"))
2023-06-26 19:05:05 +00:00
helpMenu.AddText("License", nil, menuCallbackOpenURL(a, "https://github.com/garraflavatra/rolens/blob/main/LICENSE"))
2023-05-27 19:18:47 +00:00
return appMenu
}