diff --git a/docs/src/content/docs/changelog.mdx b/docs/src/content/docs/changelog.mdx index 2f3d83917..d34e8660b 100644 --- a/docs/src/content/docs/changelog.mdx +++ b/docs/src/content/docs/changelog.mdx @@ -124,8 +124,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed transparency issue for frameless windows by [@leaanthony](https://github.com/leaanthony) based on work by @kron. - Fixed focus calls when window is disabled or minimised by [@leaanthony](https://github.com/leaanthony) based on work by @kron. - Fixed system trays not showing after taskbar restarts by [@leaanthony](https://github.com/leaanthony) based on work by @kron. -- Fixed fallbackResponseWriter not implementing Flush() in -[#4245](https://github.com/wailsapp/wails/pull/4245) +- Fixed fallbackResponseWriter not implementing Flush() in [#4245](https://github.com/wailsapp/wails/pull/4245) +- Fixed fallbackResponseWriter not implementing Flush() by [@superDingda] in [#4236](https://github.com/wailsapp/wails/issues/4236) ### Changed diff --git a/v3/examples/menu/main.go b/v3/examples/menu/main.go index 218f93a2d..9e25d0ffd 100644 --- a/v3/examples/menu/main.go +++ b/v3/examples/menu/main.go @@ -113,6 +113,37 @@ func main() { ctx.ClickedMenuItem().SetLabel("Unhide the beatles!") } }) + + myMenu.AddSeparator() + + coffee := myMenu.Add("Request Coffee").OnClick(func(*application.Context) { + println("Coffee dispatched. Productivity +10!") + }) + + myMenu.Add("Toggle coffee availability").OnClick(func(*application.Context) { + if coffee.Enabled() { + coffee.SetEnabled(false) + coffee.SetLabel("Coffee Machine Broken") + println("Alert: Developer morale critically low.") + } else { + coffee.SetEnabled(true) + coffee.SetLabel("Request Coffee") + println("All systems nominal. Coffee restored.") + } + }) + + myMenu.Add("Hide the coffee option").OnClick(func(ctx *application.Context) { + if coffee.Hidden() { + ctx.ClickedMenuItem().SetLabel("Hide the coffee option") + coffee.SetHidden(false) + println("Coffee menu item has been resurrected!") + } else { + coffee.SetHidden(true) + ctx.ClickedMenuItem().SetLabel("Unhide the coffee option") + println("The coffee option has vanished into the void.") + } + }) + app.SetMenu(menu) window := app.NewWebviewWindow().SetBackgroundColour(application.NewRGB(33, 37, 41)) diff --git a/v3/pkg/application/menuitem_windows.go b/v3/pkg/application/menuitem_windows.go index 825b2f05c..941bf2388 100644 --- a/v3/pkg/application/menuitem_windows.go +++ b/v3/pkg/application/menuitem_windows.go @@ -12,45 +12,32 @@ type windowsMenuItem struct { parent *Menu menuItem *MenuItem - hMenu w32.HMENU - id int - label string - disabled bool - checked bool - itemType menuItemType - hidden bool - submenu w32.HMENU - itemAfter *MenuItem + hMenu w32.HMENU + id int + label string + disabled bool + checked bool + itemType menuItemType + hidden bool + submenu w32.HMENU } func (m *windowsMenuItem) setHidden(hidden bool) { if hidden && !m.hidden { m.hidden = true - // iterate the parent items and find the menu item after us - for i, item := range m.parent.items { - if item == m.menuItem { - if i < len(m.parent.items)-1 { - m.itemAfter = m.parent.items[i+1] - } else { - m.itemAfter = nil - } - break - } - } // Remove from parent menu w32.RemoveMenu(m.hMenu, m.id, w32.MF_BYCOMMAND) } else if !hidden && m.hidden { m.hidden = false - // Add to parent menu before the "itemAfter" + // Reinsert into parent menu at correct visible position var pos int - if m.itemAfter != nil { - for i, item := range m.parent.items { - if item == m.itemAfter { - pos = i - 1 - break - } + for _, item := range m.parent.items { + if item == m.menuItem { + break + } + if item.hidden == false { + pos++ } - m.itemAfter = nil } w32.InsertMenuItem(m.hMenu, uint32(pos), true, m.getMenuInfo()) }