refactor menuWillShow
This commit is contained in:
parent
9038987e1d
commit
9b364d5be3
1 changed files with 16 additions and 38 deletions
|
@ -7,7 +7,7 @@ const bindings = process.atomBinding('menu')
|
||||||
|
|
||||||
const {Menu} = bindings
|
const {Menu} = bindings
|
||||||
let applicationMenu = null
|
let applicationMenu = null
|
||||||
let nextGroupId = 0
|
let groupIdIndex = 0
|
||||||
|
|
||||||
Object.setPrototypeOf(Menu.prototype, EventEmitter.prototype)
|
Object.setPrototypeOf(Menu.prototype, EventEmitter.prototype)
|
||||||
|
|
||||||
|
@ -44,23 +44,10 @@ Menu.prototype._init = function () {
|
||||||
command.click(event, BrowserWindow.getFocusedWindow(), webContents.getFocusedWebContents())
|
command.click(event, BrowserWindow.getFocusedWindow(), webContents.getFocusedWebContents())
|
||||||
},
|
},
|
||||||
menuWillShow: () => {
|
menuWillShow: () => {
|
||||||
// Make sure radio groups have at least one menu item seleted.
|
// Ensure radio groups have at least one menu item seleted
|
||||||
var checked, group, id, j, len, radioItem, ref1
|
for (let id in this.groupsMap) {
|
||||||
ref1 = this.groupsMap
|
let found = this.groupsMap[id].find(item => item.checked) || null
|
||||||
for (id in ref1) {
|
if (!found) v8Util.setHiddenValue(this.groupsMap[id][0], 'checked', true)
|
||||||
group = ref1[id]
|
|
||||||
checked = false
|
|
||||||
for (j = 0, len = group.length; j < len; j++) {
|
|
||||||
radioItem = group[j]
|
|
||||||
if (!radioItem.checked) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
checked = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if (!checked) {
|
|
||||||
v8Util.setHiddenValue(group[0], 'checked', true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,29 +238,23 @@ Menu.buildFromTemplate = function (template) {
|
||||||
|
|
||||||
// Search between separators to find a radio menu item and return its group id,
|
// Search between separators to find a radio menu item and return its group id,
|
||||||
function generateGroupId (items, pos) {
|
function generateGroupId (items, pos) {
|
||||||
var i, item, j, k, ref1, ref2, ref3
|
let i, item
|
||||||
if (pos > 0) {
|
if (pos > 0) {
|
||||||
for (i = j = ref1 = pos - 1; ref1 <= 0 ? j <= 0 : j >= 0; i = ref1 <= 0 ? ++j : --j) {
|
let asc, start
|
||||||
|
for (start = pos - 1, i = start, asc = start <= 0; asc ? i <= 0 : i >= 0; asc ? i++ : i--) {
|
||||||
item = items[i]
|
item = items[i]
|
||||||
if (item.type === 'radio') {
|
if (item.type === 'radio') { return item.groupId }
|
||||||
return item.groupId
|
if (item.type === 'separator') { break }
|
||||||
}
|
|
||||||
if (item.type === 'separator') {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (pos < items.length) {
|
} else if (pos < items.length) {
|
||||||
for (i = k = ref2 = pos, ref3 = items.length - 1; ref2 <= ref3 ? k <= ref3 : k >= ref3; i = ref2 <= ref3 ? ++k : --k) {
|
let asc1, end
|
||||||
|
for (i = pos, end = items.length - 1, asc1 = pos <= end; asc1 ? i <= end : i >= end; asc1 ? i++ : i--) {
|
||||||
item = items[i]
|
item = items[i]
|
||||||
if (item.type === 'radio') {
|
if (item.type === 'radio') { return item.groupId }
|
||||||
return item.groupId
|
if (item.type === 'separator') { break }
|
||||||
}
|
|
||||||
if (item.type === 'separator') {
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return ++groupIdIndex
|
||||||
return ++nextGroupId
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the index of item according to |id|.
|
// Returns the index of item according to |id|.
|
||||||
|
@ -284,6 +265,7 @@ function indexOfItemById (items, id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the index of where to insert the item according to |position|
|
// Returns the index of where to insert the item according to |position|
|
||||||
|
// cleaned up
|
||||||
function indexToInsertByPosition (items, position) {
|
function indexToInsertByPosition (items, position) {
|
||||||
if (!position) return items.length
|
if (!position) return items.length
|
||||||
|
|
||||||
|
@ -315,8 +297,4 @@ function indexToInsertByPosition (items, position) {
|
||||||
return (query in queries) ? queries[query](idx) : idx
|
return (query in queries) ? queries[query](idx) : idx
|
||||||
}
|
}
|
||||||
|
|
||||||
function computeNewIndexOnQuery(idx, query) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = Menu
|
module.exports = Menu
|
Loading…
Add table
Add a link
Reference in a new issue