Use dialog API to override file chooser dialog in web inspector.
This commit is contained in:
parent
877277d837
commit
7a38307d1f
1 changed files with 20 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
|||
# Use menu API to show context menu.
|
||||
window.onload = ->
|
||||
# Use menu API to show context menu.
|
||||
WebInspector.ContextMenu.prototype.show = ->
|
||||
menuObject = @_buildDescriptor()
|
||||
if menuObject.length
|
||||
|
@ -7,6 +7,13 @@ window.onload = ->
|
|||
createMenu(menuObject, @_event)
|
||||
@_event.consume()
|
||||
|
||||
# Use dialog API to override file chooser dialog.
|
||||
WebInspector.createFileSelectorElement = (callback) ->
|
||||
fileSelectorElement = document.createElement 'span'
|
||||
fileSelectorElement.style.display = 'none'
|
||||
fileSelectorElement.click = showFileChooserDialog.bind this, callback
|
||||
return fileSelectorElement
|
||||
|
||||
convertToMenuTemplate = (items) ->
|
||||
template = []
|
||||
for item in items
|
||||
|
@ -40,3 +47,15 @@ createMenu = (items, event) ->
|
|||
menu = Menu.buildFromTemplate convertToMenuTemplate(items)
|
||||
menu.popup remote.getCurrentWindow()
|
||||
event.consume true
|
||||
|
||||
showFileChooserDialog = (callback) ->
|
||||
remote = require 'remote'
|
||||
dialog = remote.require 'dialog'
|
||||
dialog.showOpenDialog remote.getCurrentWindow(), null, (files) ->
|
||||
callback pathToHtml5FileObject(files[0]) if files?
|
||||
|
||||
pathToHtml5FileObject = (path) ->
|
||||
fs = require 'fs'
|
||||
blob = new Blob([fs.readFileSync(path)])
|
||||
blob.name = path
|
||||
blob
|
||||
|
|
Loading…
Reference in a new issue