@@ -2,7 +2,6 @@ package systray
2
2
3
3
import (
4
4
"fmt"
5
- "sync/atomic"
6
5
)
7
6
8
7
// MenuItem is used to keep track each menu item of systray.
@@ -23,6 +22,8 @@ type MenuItem struct {
23
22
checked bool
24
23
// has the menu item a checkbox (Linux)
25
24
isCheckable bool
25
+ // icon is the icon that the item was created from
26
+ icon * Icon
26
27
// parent item, for sub menus
27
28
parent * MenuItem
28
29
}
@@ -35,29 +36,30 @@ func (item *MenuItem) String() string {
35
36
}
36
37
37
38
// newMenuItem returns a populated MenuItem object
38
- func newMenuItem (title string , tooltip string , parent * MenuItem ) * MenuItem {
39
+ func ( icon * Icon ) newMenuItem (title string , tooltip string , parent * MenuItem ) * MenuItem {
39
40
return & MenuItem {
40
41
ClickedCh : make (chan struct {}),
41
- id : atomic . AddUint32 ( & currentID , 1 ),
42
+ id : icon . nextID ( ),
42
43
title : title ,
43
44
tooltip : tooltip ,
44
45
disabled : false ,
45
46
checked : false ,
46
47
isCheckable : false ,
48
+ icon : icon ,
47
49
parent : parent ,
48
50
}
49
51
}
50
52
51
53
// AddSeparator adds a separator bar to the submenu
52
54
func (item * MenuItem ) AddSeparator () {
53
- addSeparator (atomic . AddUint32 ( & currentID , 1 ), item .id )
55
+ item . icon . addSeparator (item .id )
54
56
}
55
57
56
58
// AddSubMenuItem adds a nested sub-menu item with the designated title and tooltip.
57
59
// It can be safely invoked from different goroutines.
58
60
// Created menu items are checkable on Windows and OSX by default. For Linux you have to use AddSubMenuItemCheckbox
59
61
func (item * MenuItem ) AddSubMenuItem (title string , tooltip string ) * MenuItem {
60
- child := newMenuItem (title , tooltip , item )
62
+ child := item . icon . newMenuItem (title , tooltip , item )
61
63
child .update ()
62
64
return child
63
65
}
@@ -66,7 +68,7 @@ func (item *MenuItem) AddSubMenuItem(title string, tooltip string) *MenuItem {
66
68
// It can be safely invoked from different goroutines.
67
69
// On Windows and OSX this is the same as calling AddSubMenuItem
68
70
func (item * MenuItem ) AddSubMenuItemCheckbox (title string , tooltip string , checked bool ) * MenuItem {
69
- child := newMenuItem (title , tooltip , item )
71
+ child := item . icon . newMenuItem (title , tooltip , item )
70
72
child .isCheckable = true
71
73
child .checked = checked
72
74
child .update ()
@@ -110,6 +112,7 @@ func (item *MenuItem) Hide() {
110
112
// Remove removes a menu item
111
113
func (item * MenuItem ) Remove () {
112
114
removeMenuItem (item )
115
+
113
116
menuItemsLock .Lock ()
114
117
delete (menuItems , item .id )
115
118
menuItemsLock .Unlock ()
0 commit comments