From: mst128256 Date: Thu, 9 Mar 2017 15:01:33 +0000 (+0100) Subject: added default menu items for 'Edit' and 'Window' #2814 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8aba64025038e79f043793b29871e77dd88bc118;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git added default menu items for 'Edit' and 'Window' #2814 --- diff --git a/docs/api/menu-item.md b/docs/api/menu-item.md index 1c12d9f..76fcae1 100644 --- a/docs/api/menu-item.md +++ b/docs/api/menu-item.md @@ -64,6 +64,9 @@ The `role` property can have following values: * `zoomin` - Zoom in the focused page by 10% * `zoomout` - Zoom out the focused page by 10% +* `menuEdit` - Whole default "Edit" menu (Undo,Copy, etc.) +* `menuWindow` - Whole default "Window" menu (Minimize, Close, etc.) + On macOS `role` can also have following additional values: * `about` - Map to the `orderFrontStandardAboutPanel` action diff --git a/lib/browser/api/menu-item-roles.js b/lib/browser/api/menu-item-roles.js index 8a78670..254283b 100644 --- a/lib/browser/api/menu-item-roles.js +++ b/lib/browser/api/menu-item-roles.js @@ -154,6 +154,73 @@ const roles = { webContents.setZoomLevel(zoomLevel - 0.5) }) } + }, + // submenu Edit (should fit both Mac & Windows) + menuEdit: { + label: 'Edit', + submenu: [ + { + role: 'undo' + }, + { + role: 'redo' + }, + { + type: 'separator' + }, + { + role: 'cut' + }, + { + role: 'copy' + }, + { + role: 'paste' + }, + + process.platform === 'darwin' ? + { + role: 'pasteandmatchstyle' + } : {}, + + { + role: 'delete' + }, + + process.platform === 'win32' ? + { + type: 'separator' + } : {}, + + { + role: 'selectall' + } + ] + }, + + // submenu Window should be used for Mac only + menuWindow: { + label: 'Window', + submenu: [ + { + role: 'minimize' + }, + { + role: 'close' + }, + + process.platform === 'darwin' ? + { + type: 'separator' + } : {}, + + process.platform === 'darwin' ? + { + label: 'Bring All to Front', + role: 'front' + } : {} + + ] } } @@ -176,6 +243,20 @@ exports.getDefaultAccelerator = (role) => { if (roles.hasOwnProperty(role)) return roles[role].accelerator } +exports.getDefaultSubmenu = (role) => { + if (roles.hasOwnProperty(role)) { + submenu = roles[role].submenu + + // remove empty objects from within the submenu + if (Array.isArray(submenu)) + submenu = submenu.filter(function(n){ + return n.constructor !== Object || Object.keys(n).length > 0 + }) + + return submenu + } +} + exports.execute = (role, focusedWindow, focusedWebContents) => { if (!canExecuteRole(role)) return false diff --git a/lib/browser/api/menu-item.js b/lib/browser/api/menu-item.js index 98b8e99..e95226d 100644 --- a/lib/browser/api/menu-item.js +++ b/lib/browser/api/menu-item.js @@ -11,7 +11,7 @@ const MenuItem = function (options) { for (let key in options) { if (!(key in this)) this[key] = options[key] } - + this.submenu = this.submenu || roles.getDefaultSubmenu(this.role) if (this.submenu != null && this.submenu.constructor !== Menu) { this.submenu = Menu.buildFromTemplate(this.submenu) }