don't reassign parameters in Menu.prototype.popup
This commit is contained in:
parent
b1e707d535
commit
f93121b226
1 changed files with 25 additions and 28 deletions
|
@ -11,7 +11,8 @@ let groupIdIndex = 0
|
|||
|
||||
Object.setPrototypeOf(Menu.prototype, EventEmitter.prototype)
|
||||
|
||||
// cleaned up
|
||||
/* Instance Methods */
|
||||
|
||||
Menu.prototype._init = function () {
|
||||
this.commandsMap = {}
|
||||
this.groupsMap = {}
|
||||
|
@ -45,39 +46,33 @@ Menu.prototype._init = function () {
|
|||
// create and show a popup
|
||||
Menu.prototype.popup = function (window, x, y, positioningItem) {
|
||||
let asyncPopup
|
||||
let [newX, newY, newPosition, newWindow] = [x, y, positioningItem, window]
|
||||
|
||||
// menu.popup(x, y, positioningItem)
|
||||
if (window != null && (typeof window !== 'object' || window.constructor !== BrowserWindow)) {
|
||||
// Shift.
|
||||
positioningItem = y
|
||||
y = x
|
||||
x = window
|
||||
window = null
|
||||
if (window !== null) {
|
||||
// shift over values
|
||||
if (typeof window !== 'object' || window.constructor !== BrowserWindow) {
|
||||
[newPosition, newY, newX, newWindow] = [y, x, window, null]
|
||||
}
|
||||
}
|
||||
|
||||
// menu.popup(window, {})
|
||||
if (x != null && typeof x === 'object') {
|
||||
const options = x
|
||||
x = options.x
|
||||
y = options.y
|
||||
positioningItem = options.positioningItem
|
||||
asyncPopup = options.async
|
||||
if (x !== null && typeof x === 'object') {
|
||||
const opts = x
|
||||
newX = opts.x
|
||||
newY = opts.y
|
||||
newPosition = opts.positioningItem
|
||||
asyncPopup = opts.async
|
||||
}
|
||||
|
||||
// Default to showing in focused window.
|
||||
if (window == null) window = BrowserWindow.getFocusedWindow()
|
||||
|
||||
// Default to showing under mouse location.
|
||||
if (typeof x !== 'number') x = -1
|
||||
if (typeof y !== 'number') y = -1
|
||||
|
||||
// Default to not highlighting any item.
|
||||
if (typeof positioningItem !== 'number') positioningItem = -1
|
||||
|
||||
// Default to synchronous for backwards compatibility.
|
||||
// set defaults
|
||||
if (typeof x !== 'number') newX = -1
|
||||
if (typeof y !== 'number') newY = -1
|
||||
if (typeof positioningItem !== 'number') newPosition = -1
|
||||
if (window === null) newWindow = BrowserWindow.getFocusedWindow()
|
||||
if (typeof asyncPopup !== 'boolean') asyncPopup = false
|
||||
|
||||
this.popupAt(window, x, y, positioningItem, asyncPopup)
|
||||
this.popupAt(newWindow, newX, newY, newPosition, asyncPopup)
|
||||
}
|
||||
|
||||
// close an existing popup
|
||||
|
@ -138,6 +133,8 @@ Menu.prototype._callMenuWillShow = function () {
|
|||
})
|
||||
}
|
||||
|
||||
/* Static Methods */
|
||||
|
||||
// return application menu
|
||||
Menu.getApplicationMenu = () => applicationMenu
|
||||
|
||||
|
@ -187,7 +184,7 @@ Menu.buildFromTemplate = function (template) {
|
|||
return menu
|
||||
}
|
||||
|
||||
/* Helper Methods */
|
||||
/* Helper Functions */
|
||||
|
||||
// Search between separators to find a radio menu item and return its group id
|
||||
function generateGroupId (items, pos) {
|
||||
|
@ -253,11 +250,11 @@ function indexToInsertByPosition (items, position) {
|
|||
}
|
||||
|
||||
// insert a new MenuItem depending on its type
|
||||
function insertItemByType(item, pos) {
|
||||
function insertItemByType (item, pos) {
|
||||
const types = {
|
||||
'normal': () => this.insertItem(pos, item.commandId, item.label),
|
||||
'checkbox': () => this.insertCheckItem(pos, item.commandId, item.label),
|
||||
'separator':() => this.insertSeparator(pos),
|
||||
'separator': () => this.insertSeparator(pos),
|
||||
'submenu': () => this.insertSubMenu(pos, item.commandId, item.label, item.submenu),
|
||||
'radio': () => {
|
||||
// Grouping radio menu items
|
||||
|
|
Loading…
Add table
Reference in a new issue