Menu improvements
This PR cointains:
application.DefaultApplicationMenu() *Menuwhich will return the default application menu for the current platformMenu.FindByLabel(label string)to find a menu item by its label. Returns nil if not found.Menu.ItemAt(index int)for retrieving menu items by index. Returns nil if out of bounds.Menu.RemoveMenuItem(*MenuItem)for removing a menu item.MenuItem.RemoveAccelerator()for removing the accelerator.MenuItem.GetAccelerator() stringfor getting a menu item's accelerator.MenuItem.GetSubmenu() *Menufor getting a submenu (nil if not a submenu item).
Menu.Update() needs calling after any changes.
Deploying wails with
Cloudflare Pages
| Latest commit: |
3c6dd7e
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://8480eef8.wails.pages.dev |
| Branch Preview URL: | https://v3-alpha-feature-improve-men.wails.pages.dev |
A small change that I had to make to fix an error when running wails3 dev
diff --git a/v3/pkg/application/menuitem_darwin.go b/v3/pkg/application/menuitem_darwin.go
index 74ee9c4b..8b1217e1 100644
--- a/v3/pkg/application/menuitem_darwin.go
+++ b/v3/pkg/application/menuitem_darwin.go
@@ -419,7 +419,7 @@ func newSpeechMenu() *MenuItem {
OnClick(func(ctx *Context) {
C.stopSpeaking()
})
- subMenu := newSubMenuItem("Speech")
+ subMenu := NewSubMenuItem("Speech")
subMenu.submenu = speechMenu
return subMenu
}
This pr does give you the ability to get the default menu, but I am not sure how you would update it besides adding.
If I wanted to remove Toggle Fullscreen, how would I go about that? I need to remove the item, but it seems like there's no direct access to the items array.
I tried setting it hidden, but that didn't work
menu := application.DefaultApplicationMenu()
viewMenu := menu.FindByLabel("Toggle Full Screen")
if viewMenu != nil {
viewMenu.SetHidden(true)
}
This doesn't seem to work on the defaultMenu. 👇 is not working for me
menu := application.DefaultApplicationMenu()
menuItem := menu.FindByLabel("Toggle Fullscreen")
if menuItem != nil {
menu.RemoveMenuItem(menuItem)
}
app.SetMenu(menu)
Menu.Update()needs calling after any changes.
Try that ☝️
Still does not work
menu := application.DefaultApplicationMenu()
menuItem := menu.FindByLabel("Toggle Fullscreen")
if menuItem != nil {
menu.RemoveMenuItem(menuItem)
}
menu.Update()
app.SetMenu(menu)
Just pushed a fix. However, you'll need to search for the label "Toggle Full Screen" to find the right one.
This works for me now, thanks
I had to do this:
menu := application.DefaultApplicationMenu()
menuItem := menu.FindByLabel("Toggle Full Screen")
if menuItem != nil {
menu.RemoveMenuItem(menuItem)
}
app.SetMenu(menu)
menu.Update()
Is there a way to give access to the submenu of a menu item if it has one.
For example, if I want to add a menu item to the file menu, it doesn't seem possible.
Doing the below does not give me access to the Add function
Ideally, a GetSubmenu function can be exposed to the MenuItem that can either return the Menu or nil
There is an isSubmenu method, but I am not too sure if that can be used
This worked for my usecase!
Thanks