2014-04-03 12:54:42 +00:00
|
|
|
window.onload = ->
|
2014-04-05 02:24:46 +00:00
|
|
|
# Use menu API to show context menu.
|
2015-09-02 10:28:40 +00:00
|
|
|
InspectorFrontendHost.showContextMenuAtPoint = createMenu
|
2014-04-03 12:54:42 +00:00
|
|
|
|
2014-04-05 02:24:46 +00:00
|
|
|
# Use dialog API to override file chooser dialog.
|
2015-09-02 10:28:40 +00:00
|
|
|
WebInspector.createFileSelectorElement = createFileSelectorElement
|
2014-04-05 02:24:46 +00:00
|
|
|
|
2014-04-03 12:54:42 +00:00
|
|
|
convertToMenuTemplate = (items) ->
|
|
|
|
template = []
|
|
|
|
for item in items
|
2014-04-04 14:37:34 +00:00
|
|
|
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?
|
2015-03-11 22:55:40 +00:00
|
|
|
transformed.click = -> DevToolsAPI.contextMenuItemSelected item.id
|
2014-04-04 14:37:34 +00:00
|
|
|
template.push transformed
|
2014-04-03 12:54:42 +00:00
|
|
|
template
|
|
|
|
|
2015-03-11 22:55:40 +00:00
|
|
|
createMenu = (x, y, items, document) ->
|
2014-04-03 12:54:42 +00:00
|
|
|
remote = require 'remote'
|
|
|
|
Menu = remote.require 'menu'
|
|
|
|
|
2014-04-04 14:37:34 +00:00
|
|
|
menu = Menu.buildFromTemplate convertToMenuTemplate(items)
|
2014-11-16 14:34:29 +00:00
|
|
|
# The menu is expected to show asynchronously.
|
|
|
|
setImmediate ->
|
|
|
|
menu.popup remote.getCurrentWindow()
|
2015-03-11 22:55:40 +00:00
|
|
|
DevToolsAPI.contextMenuCleared()
|
2014-04-05 02:24:46 +00:00
|
|
|
|
|
|
|
showFileChooserDialog = (callback) ->
|
|
|
|
remote = require 'remote'
|
|
|
|
dialog = remote.require 'dialog'
|
2015-10-01 06:46:33 +00:00
|
|
|
files = dialog.showOpenDialog {}
|
2014-04-24 04:07:03 +00:00
|
|
|
callback pathToHtml5FileObject files[0] if files?
|
2014-04-05 02:24:46 +00:00
|
|
|
|
|
|
|
pathToHtml5FileObject = (path) ->
|
|
|
|
fs = require 'fs'
|
|
|
|
blob = new Blob([fs.readFileSync(path)])
|
|
|
|
blob.name = path
|
|
|
|
blob
|
2015-03-11 22:55:40 +00:00
|
|
|
|
|
|
|
createFileSelectorElement = (callback) ->
|
|
|
|
fileSelectorElement = document.createElement 'span'
|
|
|
|
fileSelectorElement.style.display = 'none'
|
|
|
|
fileSelectorElement.click = showFileChooserDialog.bind this, callback
|
|
|
|
return fileSelectorElement
|