|
@@ -6,12 +6,9 @@ window.onload = function () {
|
|
|
window.WebInspector.createFileSelectorElement = createFileSelectorElement
|
|
|
}
|
|
|
|
|
|
-var convertToMenuTemplate = function (items) {
|
|
|
- var fn, i, item, len, template
|
|
|
- template = []
|
|
|
- fn = function (item) {
|
|
|
- var transformed
|
|
|
- transformed = item.type === 'subMenu' ? {
|
|
|
+const convertToMenuTemplate = function (items) {
|
|
|
+ return items.map(function (item) {
|
|
|
+ const transformed = item.type === 'subMenu' ? {
|
|
|
type: 'submenu',
|
|
|
label: item.label,
|
|
|
enabled: item.enabled,
|
|
@@ -28,53 +25,46 @@ var convertToMenuTemplate = function (items) {
|
|
|
label: item.label,
|
|
|
enabled: item.enabled
|
|
|
}
|
|
|
+
|
|
|
if (item.id != null) {
|
|
|
transformed.click = function () {
|
|
|
window.DevToolsAPI.contextMenuItemSelected(item.id)
|
|
|
return window.DevToolsAPI.contextMenuCleared()
|
|
|
}
|
|
|
}
|
|
|
- return template.push(transformed)
|
|
|
- }
|
|
|
- for (i = 0, len = items.length; i < len; i++) {
|
|
|
- item = items[i]
|
|
|
- fn(item)
|
|
|
- }
|
|
|
- return template
|
|
|
+
|
|
|
+ return transformed
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
-var createMenu = function (x, y, items) {
|
|
|
- const remote = require('electron').remote
|
|
|
- const Menu = remote.Menu
|
|
|
+const createMenu = function (x, y, items) {
|
|
|
+ const {remote} = require('electron')
|
|
|
+ const {Menu} = remote
|
|
|
const menu = Menu.buildFromTemplate(convertToMenuTemplate(items))
|
|
|
|
|
|
// The menu is expected to show asynchronously.
|
|
|
- return setTimeout(function () {
|
|
|
- return menu.popup(remote.getCurrentWindow())
|
|
|
+ setTimeout(function () {
|
|
|
+ menu.popup(remote.getCurrentWindow())
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-var showFileChooserDialog = function (callback) {
|
|
|
- var dialog, files, remote
|
|
|
- remote = require('electron').remote
|
|
|
- dialog = remote.dialog
|
|
|
- files = dialog.showOpenDialog({})
|
|
|
+const showFileChooserDialog = function (callback) {
|
|
|
+ const {dialog} = require('electron').remote
|
|
|
+ const files = dialog.showOpenDialog({})
|
|
|
if (files != null) {
|
|
|
- return callback(pathToHtml5FileObject(files[0]))
|
|
|
+ callback(pathToHtml5FileObject(files[0]))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-var pathToHtml5FileObject = function (path) {
|
|
|
- var blob, fs
|
|
|
- fs = require('fs')
|
|
|
- blob = new Blob([fs.readFileSync(path)])
|
|
|
+const pathToHtml5FileObject = function (path) {
|
|
|
+ const fs = require('fs')
|
|
|
+ const blob = new Blob([fs.readFileSync(path)])
|
|
|
blob.name = path
|
|
|
return blob
|
|
|
}
|
|
|
|
|
|
-var createFileSelectorElement = function (callback) {
|
|
|
- var fileSelectorElement
|
|
|
- fileSelectorElement = document.createElement('span')
|
|
|
+const createFileSelectorElement = function (callback) {
|
|
|
+ const fileSelectorElement = document.createElement('span')
|
|
|
fileSelectorElement.style.display = 'none'
|
|
|
fileSelectorElement.click = showFileChooserDialog.bind(this, callback)
|
|
|
return fileSelectorElement
|