File tree Expand file tree Collapse file tree 6 files changed +38
-0
lines changed Expand file tree Collapse file tree 6 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,10 @@ void MenuItem::Call(const std::string& method,
50
50
std::string icon;
51
51
arguments.GetString (0 , &icon);
52
52
SetIcon (icon);
53
+ } else if (method == " SetIconIsTemplate" ) {
54
+ bool isTemplate;
55
+ arguments.GetBoolean (0 , &isTemplate);
56
+ SetIconIsTemplate (isTemplate);
53
57
} else if (method == " SetTooltip" ) {
54
58
std::string tooltip;
55
59
arguments.GetString (0 , &tooltip);
Original file line number Diff line number Diff line change @@ -82,11 +82,15 @@ class MenuItem : public Base {
82
82
void SetChecked (bool checked);
83
83
void SetSubmenu (Menu* sub_menu);
84
84
85
+ // Template icon works only on Mac OS X
86
+ void SetIconIsTemplate (bool isTemplate);
87
+
85
88
#if defined(OS_MACOSX)
86
89
std::string type_;
87
90
88
91
NSMenuItem * menu_item_;
89
92
MenuItemDelegate* delegate_;
93
+ bool iconIsTemplate;
90
94
91
95
#elif defined(OS_WIN) || defined(OS_LINUX)
92
96
friend class MenuDelegate;
Original file line number Diff line number Diff line change @@ -46,6 +46,11 @@ function MenuItem(option) {
46
46
option . icon = nw . getAbsolutePath ( option . icon ) ;
47
47
}
48
48
49
+ if ( option . hasOwnProperty ( 'iconIsTemplate' ) )
50
+ option . iconIsTemplate = Boolean ( option . iconIsTemplate ) ;
51
+ else
52
+ option . iconIsTemplate = true ;
53
+
49
54
if ( option . hasOwnProperty ( 'tooltip' ) )
50
55
option . tooltip = String ( option . tooltip ) ;
51
56
@@ -116,6 +121,14 @@ MenuItem.prototype.__defineSetter__('icon', function(val) {
116
121
this . handleSetter ( 'icon' , 'SetIcon' , String , real_path ) ;
117
122
} ) ;
118
123
124
+ MenuItem . prototype . __defineGetter__ ( 'iconIsTemplate' , function ( ) {
125
+ return this . handleGetter ( 'iconIsTemplate' ) ;
126
+ } ) ;
127
+
128
+ MenuItem . prototype . __defineSetter__ ( 'iconIsTemplate' , function ( val ) {
129
+ this . handleSetter ( 'iconIsTemplate' , 'SetIconIsTemplate' , Boolean , val ) ;
130
+ } ) ;
131
+
119
132
MenuItem . prototype . __defineGetter__ ( 'tooltip' , function ( ) {
120
133
return this . handleGetter ( 'tooltip' ) ;
121
134
} ) ;
Original file line number Diff line number Diff line change @@ -124,6 +124,9 @@ void MenuItem::SetIcon(const std::string& icon) {
124
124
}
125
125
}
126
126
127
+ void MenuItem::SetIconIsTemplate (bool isTemplate) {
128
+ }
129
+
127
130
void MenuItem::SetTooltip (const std::string& tooltip) {
128
131
gtk_widget_set_tooltip_text (menu_item_, tooltip.c_str ());
129
132
}
Original file line number Diff line number Diff line change 71
71
if (option.GetBoolean (" enabled" , &enabled))
72
72
SetEnabled (enabled);
73
73
74
+ bool isTemplate;
75
+ if (option.GetBoolean (" iconIsTemplate" , &isTemplate))
76
+ SetIconIsTemplate (isTemplate);
77
+
74
78
std::string icon;
75
79
if (option.GetString (" icon" , &icon) && !icon.empty ())
76
80
SetIcon (icon);
131
135
if (!icon.empty ()) {
132
136
NSImage * image = [[NSImage alloc ]
133
137
initWithContentsOfFile: [NSString stringWithUTF8String: icon.c_str ()]];
138
+ [image setTemplate: iconIsTemplate];
134
139
[menu_item_ setImage: image];
135
140
[image release ];
136
141
} else {
137
142
[menu_item_ setImage: nil ];
138
143
}
139
144
}
140
145
146
+ void MenuItem::SetIconIsTemplate (bool isTemplate) {
147
+ iconIsTemplate = isTemplate;
148
+ if ([menu_item_ image ] != nil )
149
+ [[menu_item_ image ] setTemplate: isTemplate];
150
+ }
151
+
141
152
void MenuItem::SetTooltip (const std::string& tooltip) {
142
153
[menu_item_ setToolTip: [NSString stringWithUTF8String: tooltip.c_str ()]];
143
154
}
Original file line number Diff line number Diff line change @@ -134,6 +134,9 @@ void MenuItem::SetIcon(const std::string& icon) {
134
134
package->GetImage (base::FilePath::FromUTF8Unsafe (icon), &icon_);
135
135
}
136
136
137
+ void MenuItem::SetIconIsTemplate (bool isTemplate) {
138
+ }
139
+
137
140
void MenuItem::SetTooltip (const std::string& tooltip) {
138
141
tooltip_ = base::UTF8ToUTF16 (tooltip);
139
142
if (menu_)
You can’t perform that action at this time.
0 commit comments