]> khamidou — GitHub mirrors - electron.git/commitdiff
win: Newly created window should also be aware of application menu.
authorCheng Zhao <zcbenz@gmail.com>
Sat, 5 Oct 2013 13:05:59 +0000 (21:05 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 7 Oct 2013 00:56:52 +0000 (08:56 +0800)
browser/api/atom_api_window.cc
browser/api/lib/app.coffee
browser/api/lib/browser-window.coffee
browser/api/lib/menu.coffee
spec/main.js

index 8d1cd0a66749ac18a4116d42dfe18ff4003f0c8c..b0753491bf3c2fc27d54dccaa67277cc899a4515 100644 (file)
@@ -101,6 +101,9 @@ v8::Handle<v8::Value> Window::New(const v8::Arguments &args) {
 
   new Window(args.This(), static_cast<base::DictionaryValue*>(options.get()));
 
+  // Give js code a chance to do initialization.
+  node::MakeCallback(args.This(), "_init", 0, NULL);
+
   return args.This();
 }
 
index 5e0d7e9a00500e95da6ed26139c4f74e92d8f531..9fc9664ed4237f6896f36d433b1cabfcea0e9717 100644 (file)
@@ -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
index a016883aa0a7cc9545916c39670e3351bb1b19d2..cd768404641e097a7bde2da29df61df7d90ce95c 100644 (file)
@@ -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
index 5d00504da9ff369074658494682b3d95f31e0d89..17c768e956eb61f8a459d652297d5f3aac75545e 100644 (file)
@@ -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) ->
index 0c2f64dc419471297851a39b77fa08ba4fb4e8f1..d5bad145713114bbb7145b58a65a7eb49f2ee1c5 100644 (file)
@@ -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);
 });