mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
fix: restore hidden menuitem at correct position
This commit is contained in:
parent
2bfbe7f902
commit
c922a7e685
3 changed files with 48 additions and 30 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue