From e58f115b43e9faedb8a6439ccc3ddebc63b041a2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 16 May 2013 22:22:33 +0800 Subject: [PATCH] Make MenuItem's type default to 'submenu' if it has submenu property. --- browser/api/lib/menu_item.coffee | 8 ++++++-- browser/default_app/main.js | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/browser/api/lib/menu_item.coffee b/browser/api/lib/menu_item.coffee index bd7113f..2764a0b 100644 --- a/browser/api/lib/menu_item.coffee +++ b/browser/api/lib/menu_item.coffee @@ -4,8 +4,13 @@ class MenuItem @types = ['normal', 'separator', 'submenu', 'checkbox', 'radio'] constructor: (options) -> + Menu = require 'menu' + {click, selector, @type, @label, @sublabel, @accelerator, @enabled, @visible, @checked, @groupId, @submenu} = options + @type = 'submenu' if not @type? and @submenu? + throw new Error('Invalid submenu') if @type is 'submenu' and @submenu?.constructor isnt Menu + @type = @type ? 'normal' @label = @label ? '' @sublabel = @sublabel ? '' @@ -13,13 +18,12 @@ class MenuItem @visible = @visible ? true throw new Error('Unknown menu type') if MenuItem.types.indexOf(@type) is -1 - throw new Error('Invalid menu') if @type is 'submenu' and @submenu?.constructor.name isnt 'Menu' @commandId = ++nextCommandId @click = -> if typeof click is 'function' click() else if typeof selector is 'string' - require('menu').sendActionToFirstResponder selector + Menu.sendActionToFirstResponder selector module.exports = MenuItem diff --git a/browser/default_app/main.js b/browser/default_app/main.js index 1660fc6..8e3a76b 100644 --- a/browser/default_app/main.js +++ b/browser/default_app/main.js @@ -72,8 +72,8 @@ delegate.browserMainParts.preMainMessageLoopRun = function() { selector: 'arrangeInFront:' })); - menu.append(new MenuItem({ type: 'submenu', submenu: appleMenu })); - menu.append(new MenuItem({ label: 'Window', type: 'submenu', submenu: windowMenu })); + menu.append(new MenuItem({ submenu: appleMenu })); + menu.append(new MenuItem({ label: 'Window', submenu: windowMenu })); Menu.setApplicationMenu(menu); -- 2.7.4