+BrowserWindow = require 'browser-window'
+
nextCommandId = 0
class MenuItem
@commandId = ++nextCommandId
@click = =>
if typeof click is 'function'
- click.apply this, arguments
+ click this, BrowserWindow.getFocusedWindow()
else if typeof @selector is 'string'
Menu.sendActionToFirstResponder @selector
IDWeakMap = require 'id-weak-map'
MenuItem = require 'menu-item'
+app = require 'app'
bindings = process.atomBinding 'menu'
Menu = bindings.Menu
getAcceleratorForCommandId: (commandId) => @commandsMap[commandId]?.accelerator
executeCommand: (commandId) =>
activeItem = @commandsMap[commandId]
- activeItem.click(activeItem) if activeItem?
+ activeItem.click() if activeItem?
@items.splice pos, 0, item
@commandsMap[item.commandId] = item
Menu.setApplicationMenu = (menu) ->
throw new TypeError('Invalid menu') unless menu?.constructor is Menu
applicationMenu = menu # Keep a reference.
- bindings.setApplicationMenu menu
+
+ if process.platform is 'darwin'
+ bindings.setApplicationMenu menu
+ else
+ windows = app.getBrowserWindows()
+ w.setMenu menu for w in windows
Menu.sendActionToFirstResponder = bindings.sendActionToFirstResponder
var app = require('app');
var ipc = require('ipc');
var BrowserWindow = require('browser-window');
+var Menu = require('menu');
var window = null;
});
app.on('finish-launching', function() {
+ var template = [
+ {
+ label: 'File',
+ submenu: [
+ {
+ label: 'Open',
+ accelerator: 'Command+O',
+ },
+ {
+ label: 'Close',
+ accelerator: 'Command+W',
+ click: function(item, window) { window.close(); }
+ },
+ ]
+ },
+ {
+ label: 'View',
+ submenu: [
+ {
+ label: 'Reload',
+ accelerator: 'Command+R',
+ click: function(item, window) { window.restart(); }
+ },
+ {
+ label: 'Enter Fullscreen',
+ click: function(item, window) { window.setFullScreen(true); }
+ },
+ {
+ label: 'Toggle DevTools',
+ accelerator: 'Alt+Command+I',
+ click: function(item, window) { window.toggleDevTools(); }
+ },
+ ]
+ },
+ ];
+
// Test if using protocol module would crash.
require('protocol').registerProtocol('test-if-crashes', function() {});
height: 600
});
window.loadUrl('file://' + __dirname + '/index.html');
+
+ var menu = Menu.buildFromTemplate(template);
+ app.setApplicationMenu(menu);
});