File tree Expand file tree Collapse file tree 4 files changed +30
-1
lines changed Expand file tree Collapse file tree 4 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ namespace nwapi {
30
30
Menu::Menu (int id,
31
31
const base::WeakPtr<DispatcherHost>& dispatcher_host,
32
32
const base::DictionaryValue& option)
33
- : Base(id, dispatcher_host, option) {
33
+ : enable_show_event_( false ), Base(id, dispatcher_host, option) {
34
34
Create (option);
35
35
}
36
36
@@ -63,6 +63,8 @@ void Menu::Call(const std::string& method,
63
63
arguments.GetInteger (1 , &y);
64
64
Popup (x, y, content::Shell::FromRenderViewHost (
65
65
dispatcher_host ()->render_view_host ()));
66
+ } else if (method == " EnableShowEvent" ) {
67
+ arguments.GetBoolean (0 , &enable_show_event_);
66
68
} else {
67
69
NOTREACHED () << " Invalid call to Menu method:" << method
68
70
<< " arguments:" << arguments;
Original file line number Diff line number Diff line change @@ -101,6 +101,10 @@ class Menu : public Base {
101
101
ui::NwMenuModel* model () { return menu_model_.get (); }
102
102
#endif
103
103
104
+ bool enable_show_event () { return enable_show_event_; }
105
+ protected:
106
+ bool enable_show_event_;
107
+
104
108
private:
105
109
friend class MenuItem;
106
110
friend class Tray;
Original file line number Diff line number Diff line change 19
19
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
21
21
var v8_util = process . binding ( 'v8_util' ) ;
22
+ var EventEmitter = process . EventEmitter ;
23
+
22
24
23
25
function Menu ( option ) {
24
26
if ( typeof option != 'object' )
@@ -70,9 +72,26 @@ Menu.prototype.popup = function(x, y) {
70
72
}
71
73
72
74
if ( require ( 'os' ) . platform ( ) === 'darwin' ) {
75
+ Menu . prototype . on = Menu . prototype . addListener = function ( ev , callback ) {
76
+ if ( ev == 'show' ) {
77
+ nw . callObjectMethod ( this , 'EnableShowEvent' , [ true ] ) ;
78
+ }
79
+ // Call parent.
80
+ EventEmitter . prototype . addListener . apply ( this , arguments ) ;
81
+ }
82
+
83
+ Menu . prototype . removeListener = function ( ev , callback ) {
84
+ // Call parent.
85
+ EventEmitter . prototype . removeListener . apply ( this , arguments ) ;
86
+ if ( ev == 'show' && EventEmitter . listenerCount ( this , 'show' ) === 0 ) {
87
+ nw . callObjectMethod ( this , 'EnableShowEvent' , [ false ] ) ;
88
+ }
89
+ }
90
+
73
91
Menu . prototype . createMacBuiltin = function ( app_name , options ) {
74
92
var appleMenu = new Menu ( ) ,
75
93
options = options || { } ;
94
+
76
95
appleMenu . append ( new exports . MenuItem ( {
77
96
label : nw . getNSStringFWithFixup ( "IDS_ABOUT_MAC" , app_name ) ,
78
97
selector : "orderFrontStandardAboutPanel:"
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ - (BOOL)menuHasKeyEquivalent:(NSMenu *)menu forEvent:(NSEvent *)event target:(id
39
39
}
40
40
41
41
- (void )menuNeedsUpdate : (NSMenu *)menu {
42
+
42
43
if (!nwmenu_->enable_show_event () || nwmenu_->dispatcher_host ()->run_loop ())
43
44
return ;
44
45
@@ -50,6 +51,9 @@ - (void)menuNeedsUpdate:(NSMenu*)menu {
50
51
// if ([event type] != NSSystemDefined || [event subtype] == 8)
51
52
// return;
52
53
54
+ if (!nwmenu_->enable_show_event ())
55
+ return ;
56
+
53
57
base::ListValue args;
54
58
base::RunLoop run_loop;
55
59
nwmenu_->dispatcher_host ()->set_run_loop (&run_loop);
You can’t perform that action at this time.
0 commit comments