Skip to content

Commit

Permalink
Add unix support for removeMenuItem
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Dwyer <[email protected]>
  • Loading branch information
bdwyertech committed Dec 21, 2022
1 parent a146990 commit 7446191
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions systray_menu_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,42 @@ func findSubLayout(id int32, vals []dbus.Variant) (*menuLayout, bool) {
return nil, false
}

func removeSubLayout(id int32, vals []dbus.Variant) ([]dbus.Variant, bool) {
for idx, i := range vals {
item := i.Value().(*menuLayout)
if item.V0 == id {
return append(vals[:idx], vals[idx+1:]...), true
}

if len(item.V2) > 0 {
if child, removed := removeSubLayout(id, item.V2); removed {
return child, true
}
}
}

return vals, false
}

func removeMenuItem(item *MenuItem) {
instance.menuLock.Lock()
defer instance.menuLock.Unlock()

parent := instance.menu
if item.parent != nil {
m, ok := findLayout(int32(item.parent.id))
if !ok {
return
}
parent = m
}

if items, removed := removeSubLayout(int32(item.id), parent.V2); removed {
parent.V2 = items
refresh()
}
}

func hideMenuItem(item *MenuItem) {
instance.menuLock.Lock()
defer instance.menuLock.Unlock()
Expand Down

0 comments on commit 7446191

Please sign in to comment.