-
Notifications
You must be signed in to change notification settings - Fork 15.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default menu items for 'Edit' and 'Window' #2814 #8880
Changes from 2 commits
8aba640
76ee7fd
9e471d8
6a7b4fe
6ae198a
8b4bf1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about calling these |
||
|
||
On macOS `role` can also have following additional values: | ||
|
||
* `about` - Map to the `orderFrontStandardAboutPanel` action | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,6 +154,69 @@ 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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this label needed here? Shouldn't it use the one defined by the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the label is unnecessary - fixed. |
||
role: 'front' | ||
} : {} | ||
|
||
] | ||
} | ||
} | ||
|
||
|
@@ -176,6 +239,21 @@ exports.getDefaultAccelerator = (role) => { | |
if (roles.hasOwnProperty(role)) return roles[role].accelerator | ||
} | ||
|
||
exports.getDefaultSubmenu = (role) => { | ||
if (roles.hasOwnProperty(role)) { | ||
let 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about if instead of empty objects you just had There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
}) | ||
} | ||
|
||
return submenu | ||
} | ||
} | ||
|
||
exports.execute = (role, focusedWindow, focusedWebContents) => { | ||
if (!canExecuteRole(role)) return false | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a spec for these new cases in the https://github.com/electron/electron/blob/master/spec/api-menu-spec.js#L424 block? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added - please check next commits. |
||
if (this.submenu != null && this.submenu.constructor !== Menu) { | ||
this.submenu = Menu.buildFromTemplate(this.submenu) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be a space after
Undo,