From ea42851c9bcfc13efb822db517677fcb73b85007 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 26 Sep 2017 09:47:13 -0400 Subject: [PATCH] add first pass at getMenuItemById --- lib/browser/api/menu.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/browser/api/menu.js b/lib/browser/api/menu.js index 99d650d773..d7cdbe81be 100644 --- a/lib/browser/api/menu.js +++ b/lib/browser/api/menu.js @@ -189,6 +189,19 @@ Menu.prototype.closePopup = function (window) { } } +Menu.prototype.getMenuItemById = function (items, id) { + if (items instanceof Menu) { + items = items.items; + } + let found = items.find(item => item.id === id) || false; + for(let i = 0, length = items.length; !found && i < length; i++) { + if (items[i].submenu) { + found = this.getMenuItemById(items[i].submenu, id); + } + } + return found; +}; + Menu.prototype.append = function (item) { return this.insert(this.getItemCount(), item) }