зеркало из https://github.com/electron/electron.git
Correctly translate WebInspector menu to native menu.
This commit is contained in:
Родитель
03e6d564d7
Коммит
d4e7fe3eb8
|
@ -10,21 +10,33 @@ window.onload = ->
|
|||
convertToMenuTemplate = (items) ->
|
||||
template = []
|
||||
for item in items
|
||||
if item.type is 'subMenu'
|
||||
template.push
|
||||
type: 'submenu'
|
||||
label: item.label
|
||||
submenu: convertToMenuTemplate item.subItems
|
||||
else
|
||||
template.push
|
||||
type: 'normal'
|
||||
label: item.label
|
||||
do (item) ->
|
||||
transformed =
|
||||
if item.type is 'subMenu'
|
||||
type: 'submenu'
|
||||
label: item.label
|
||||
enabled: item.enabled
|
||||
submenu: convertToMenuTemplate item.subItems
|
||||
else if item.type is 'separator'
|
||||
type: 'separator'
|
||||
else if item.type is 'checkbox'
|
||||
type: 'checkbox'
|
||||
label: item.label
|
||||
enabled: item.enabled
|
||||
checked: item.checked
|
||||
else
|
||||
type: 'normal'
|
||||
label: item.label
|
||||
enabled: item.enabled
|
||||
if item.id?
|
||||
transformed.click = -> WebInspector.contextMenuItemSelected item.id
|
||||
template.push transformed
|
||||
template
|
||||
|
||||
createMenu = (items, event) ->
|
||||
remote = require 'remote'
|
||||
Menu = remote.require 'menu'
|
||||
|
||||
menu = Menu.buildFromTemplate convertToMenuTemplate(items.subItems)
|
||||
menu.popup()
|
||||
menu = Menu.buildFromTemplate convertToMenuTemplate(items)
|
||||
menu.popup remote.getCurrentWindow()
|
||||
event.consume true
|
||||
|
|
Загрузка…
Ссылка в новой задаче