From a182de20a42a683bc18ca48789f5c94703883b14 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 5 Oct 2013 21:05:59 +0800 Subject: [PATCH] win: Newly created window should also be aware of application menu. --- browser/api/atom_api_window.cc | 3 +++ browser/api/lib/app.coffee | 3 +++ browser/api/lib/browser-window.coffee | 6 ++++++ browser/api/lib/menu.coffee | 2 ++ spec/main.js | 6 +++--- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/browser/api/atom_api_window.cc b/browser/api/atom_api_window.cc index 8d1cd0a..b075349 100644 --- a/browser/api/atom_api_window.cc +++ b/browser/api/atom_api_window.cc @@ -101,6 +101,9 @@ v8::Handle Window::New(const v8::Arguments &args) { new Window(args.This(), static_cast(options.get())); + // Give js code a chance to do initialization. + node::MakeCallback(args.This(), "_init", 0, NULL); + return args.This(); } diff --git a/browser/api/lib/app.coffee b/browser/api/lib/app.coffee index 5e0d7e9..9fc9664 100644 --- a/browser/api/lib/app.coffee +++ b/browser/api/lib/app.coffee @@ -15,6 +15,9 @@ app.getBrowserWindows = -> app.setApplicationMenu = (menu) -> require('menu').setApplicationMenu menu +app.getApplicationMenu = -> + require('menu').getApplicationMenu() + app.commandLine = appendSwitch: bindings.appendSwitch, appendArgument: bindings.appendArgument diff --git a/browser/api/lib/browser-window.coffee b/browser/api/lib/browser-window.coffee index a016883..cd76840 100644 --- a/browser/api/lib/browser-window.coffee +++ b/browser/api/lib/browser-window.coffee @@ -5,6 +5,12 @@ v8Util = process.atomBinding 'v8_util' BrowserWindow = process.atomBinding('window').BrowserWindow BrowserWindow::__proto__ = EventEmitter.prototype +BrowserWindow::_init = -> + # Simulate the application menu on platforms other than OS X. + if process.platform isnt 'darwin' + menu = app.getApplicationMenu() + @setMenu menu if menu? + BrowserWindow::toggleDevTools = -> opened = v8Util.getHiddenValue this, 'devtoolsOpened' if opened diff --git a/browser/api/lib/menu.coffee b/browser/api/lib/menu.coffee index 5d00504..17c768e 100644 --- a/browser/api/lib/menu.coffee +++ b/browser/api/lib/menu.coffee @@ -55,6 +55,8 @@ Menu.setApplicationMenu = (menu) -> windows = app.getBrowserWindows() w.setMenu menu for w in windows +Menu.getApplicationMenu = -> applicationMenu + Menu.sendActionToFirstResponder = bindings.sendActionToFirstResponder Menu.buildFromTemplate = (template) -> diff --git a/spec/main.js b/spec/main.js index 0c2f64d..d5bad14 100644 --- a/spec/main.js +++ b/spec/main.js @@ -76,6 +76,9 @@ app.on('finish-launching', function() { }, ]; + var menu = Menu.buildFromTemplate(template); + app.setApplicationMenu(menu); + // Test if using protocol module would crash. require('protocol').registerProtocol('test-if-crashes', function() {}); @@ -86,7 +89,4 @@ app.on('finish-launching', function() { height: 600 }); window.loadUrl('file://' + __dirname + '/index.html'); - - var menu = Menu.buildFromTemplate(template); - app.setApplicationMenu(menu); }); -- 2.7.4