From 0b3a00056f44c8a905e374f12854c95e74aed05b Mon Sep 17 00:00:00 2001 From: Matt Colyer Date: Fri, 4 Oct 2013 14:26:09 -0700 Subject: [PATCH] Handles nested submenus --- src/menu-manager.coffee | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/menu-manager.coffee b/src/menu-manager.coffee index decf508c7..f23653027 100644 --- a/src/menu-manager.coffee +++ b/src/menu-manager.coffee @@ -26,6 +26,7 @@ class MenuManager # Returns nothing. add: (items) -> @merge(@template, item) for item in items + @update() # Public: Refreshes the currently visible menu. update: -> @@ -38,15 +39,16 @@ class MenuManager data = CSON.readFileSync(menuPath) @add(data.menu) - # Private: Merges an item in a menu aware way such that new items are always - # appended to the bottom. - merge: (template, item) -> - if match = _.find(template, (t) -> t.label == item.label) - match.submenu = match.submenu.concat(item.submenu) + # Private: Merges an item in a submenu aware way such that new items are always + # appended to the bottom of existing menus where possible. + merge: (menu, item) -> + if item.submenu? and match = _.find(menu, (o) -> o.submenu? and o.label == item.label) + @merge(match.submenu, i) for i in item.submenu else - template.push(item) + menu.push(item) # Private sendToBrowserProcess: -> + return unless atom.keymap ipc.sendChannel 'update-application-menu', @template, atom.keymap.keystrokesByCommandForSelector('body')