Fix menu bug with atom-i18n

"Check for Update" and "Reopen Project" menu dose not work.
This commit is contained in:
juggernautjp
2021-06-13 00:39:35 +09:00
parent 526ad5b8f2
commit 954d51ce88
3 changed files with 26 additions and 9 deletions

View File

@@ -115,16 +115,20 @@ module.exports = class ApplicationMenu {
showUpdateMenuItem(state) {
const items = this.flattenMenuItems(this.menu);
const checkForUpdateItem = items.find(
({ label }) => label === 'Check for Update'
// ({ label }) => label === 'Check for Update'
({ id }) => id === 'Check for Update'
);
const checkingForUpdateItem = items.find(
({ label }) => label === 'Checking for Update'
// ({ label }) => label === 'Checking for Update'
({ id }) => id === 'Checking for Update'
);
const downloadingUpdateItem = items.find(
({ label }) => label === 'Downloading Update'
// ({ label }) => label === 'Downloading Update'
({ id }) => id === 'Downloading Update'
);
const installUpdateItem = items.find(
({ label }) => label === 'Restart and Install Update'
// ({ label }) => label === 'Restart and Install Update'
({ id }) => id === 'Restart and Install Update'
);
if (
@@ -165,13 +169,16 @@ module.exports = class ApplicationMenu {
return [
{
label: 'Atom',
id: 'Atom',
submenu: [
{
label: 'Check for Update',
id: 'Check for Update',
metadata: { autoUpdate: true }
},
{
label: 'Reload',
id: 'Reload',
accelerator: 'Command+R',
click: () => {
const window = this.focusedWindow();
@@ -180,6 +187,7 @@ module.exports = class ApplicationMenu {
},
{
label: 'Close Window',
id: 'Close Window',
accelerator: 'Command+Shift+W',
click: () => {
const window = this.focusedWindow();
@@ -188,6 +196,7 @@ module.exports = class ApplicationMenu {
},
{
label: 'Toggle Dev Tools',
id: 'Toggle Dev Tools',
accelerator: 'Command+Alt+I',
click: () => {
const window = this.focusedWindow();
@@ -196,6 +205,7 @@ module.exports = class ApplicationMenu {
},
{
label: 'Quit',
id: 'Quit',
accelerator: 'Command+Q',
click: () => app.quit()
}

View File

@@ -53,14 +53,16 @@ function unmerge(menu, item) {
}
}
function findMatchingItemIndex(menu, { type, label, submenu }) {
// function findMatchingItemIndex(menu, { type, label, submenu }) {
function findMatchingItemIndex(menu, { type, id, submenu }) {
if (type === 'separator') {
return -1;
}
for (let index = 0; index < menu.length; index++) {
const item = menu[index];
if (
normalizeLabel(item.label) === normalizeLabel(label) &&
// normalizeLabel(item.label) === normalizeLabel(label) &&
item.id === id &&
(item.submenu != null) === (submenu != null)
) {
return index;
@@ -93,6 +95,7 @@ function cloneMenuItem(item) {
'beforeGroupContaining',
'afterGroupContaining'
);
if (item.id === null || item.id === undefined) { item.id = normalizeLabel(item.label) }
if (item.submenu != null) {
item.submenu = item.submenu.map(submenuItem => cloneMenuItem(submenuItem));
}

View File

@@ -78,17 +78,20 @@ class MenuManager
# atom.menu.add [
# {
# label: 'Hello'
# submenu : [{label: 'World!', command: 'hello:world'}]
# submenu : [{label: 'World!', id: 'World!', command: 'hello:world'}]
# }
# ]
# ```
#
# * `items` An {Array} of menu item {Object}s containing the keys:
# * `label` The {String} menu label.
# * `label` The {String} menu label, which is used for localiztion (in `atom-i18n` package).
# * `submenu` An optional {Array} of sub menu items.
# * `command` An optional {String} command to trigger when the item is
# clicked.
#
# * `id` (internal) The {String} menu id, which is used only in javascript code, is not used in menu template.
# For further information on the above args, see [Electron MenuItem](https://www.electronjs.org/docs/api/menu-item#class-menuitem)).
#
# Returns a {Disposable} on which `.dispose()` can be called to remove the
# added menu items.
add: (items) ->
@@ -201,7 +204,8 @@ class MenuManager
[]
sortPackagesMenu: ->
packagesMenu = _.find @template, ({label}) -> MenuHelpers.normalizeLabel(label) is 'Packages'
# packagesMenu = _.find @template, ({label}) -> MenuHelpers.normalizeLabel(label) is 'Packages'
packagesMenu = _.find @template, ({id}) -> MenuHelpers.normalizeLabel(id) is 'Packages'
return unless packagesMenu?.submenu?
packagesMenu.submenu.sort (item1, item2) ->