mirror of
https://github.com/taigrr/wails.git
synced 2026-04-02 05:08:54 -07:00
Updates for dynamic menus
Cleanup of logging
This commit is contained in:
@@ -22,3 +22,30 @@ func NewMenuFromItems(first *MenuItem, rest ...*MenuItem) *Menu {
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (m *Menu) GetByID(menuID string) *MenuItem {
|
||||
|
||||
// Loop over menu items
|
||||
for _, item := range m.Items {
|
||||
result := item.getByID(menuID)
|
||||
if result != nil {
|
||||
return result
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Menu) RemoveByID(id string) bool {
|
||||
// Loop over menu items
|
||||
for index, item := range m.Items {
|
||||
if item.ID == id {
|
||||
m.Items = append(m.Items[:index], m.Items[index+1:]...)
|
||||
return true
|
||||
}
|
||||
result := item.removeByID(id)
|
||||
if result == true {
|
||||
return result
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -43,6 +43,53 @@ func (m *MenuItem) Append(item *MenuItem) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Prepend will attempt to prepend the given menu item to
|
||||
// this item's submenu items. If this menu item is not a
|
||||
// submenu, then this method will not add the item and
|
||||
// simply return false.
|
||||
func (m *MenuItem) Prepend(item *MenuItem) bool {
|
||||
if m.Type != SubmenuType {
|
||||
return false
|
||||
}
|
||||
m.SubMenu = append([]*MenuItem{item}, m.SubMenu...)
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *MenuItem) getByID(id string) *MenuItem {
|
||||
|
||||
// If I have the ID return me!
|
||||
if m.ID == id {
|
||||
return m
|
||||
}
|
||||
|
||||
// Check submenus
|
||||
for _, submenu := range m.SubMenu {
|
||||
result := submenu.getByID(id)
|
||||
if result != nil {
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MenuItem) removeByID(id string) bool {
|
||||
|
||||
for index, item := range m.SubMenu {
|
||||
if item.ID == id {
|
||||
m.SubMenu = append(m.SubMenu[:index], m.SubMenu[index+1:]...)
|
||||
return true
|
||||
}
|
||||
if item.Type == SubmenuType {
|
||||
result := item.removeByID(id)
|
||||
if result == true {
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Text is a helper to create basic Text menu items
|
||||
func Text(label string, id string) *MenuItem {
|
||||
return TextWithAccelerator(label, id, nil)
|
||||
|
||||
Reference in New Issue
Block a user