Override web inspector's context menu.
This commit is contained in:
parent
ac794c8085
commit
b1f0c2d174
3 changed files with 38 additions and 2 deletions
1
atom.gyp
1
atom.gyp
|
@ -32,6 +32,7 @@
|
||||||
'atom/common/api/lib/shell.coffee',
|
'atom/common/api/lib/shell.coffee',
|
||||||
'atom/common/lib/init.coffee',
|
'atom/common/lib/init.coffee',
|
||||||
'atom/renderer/lib/init.coffee',
|
'atom/renderer/lib/init.coffee',
|
||||||
|
'atom/renderer/lib/inspector.coffee',
|
||||||
'atom/renderer/lib/override.coffee',
|
'atom/renderer/lib/override.coffee',
|
||||||
'atom/renderer/api/lib/ipc.coffee',
|
'atom/renderer/api/lib/ipc.coffee',
|
||||||
'atom/renderer/api/lib/remote.coffee',
|
'atom/renderer/api/lib/remote.coffee',
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
path = require 'path'
|
path = require 'path'
|
||||||
|
url = require 'url'
|
||||||
Module = require 'module'
|
Module = require 'module'
|
||||||
|
|
||||||
# Expose information of current process.
|
# Expose information of current process.
|
||||||
|
@ -42,5 +43,9 @@ else
|
||||||
global.__filename = __filename
|
global.__filename = __filename
|
||||||
global.__dirname = __dirname
|
global.__dirname = __dirname
|
||||||
|
|
||||||
|
if location.protocol is 'chrome-devtools:'
|
||||||
|
# Override some inspector APIs.
|
||||||
|
require path.join(__dirname, 'inspector')
|
||||||
|
else
|
||||||
# Override default web functions.
|
# Override default web functions.
|
||||||
require path.join(__dirname, 'override')
|
require path.join(__dirname, 'override')
|
||||||
|
|
30
atom/renderer/lib/inspector.coffee
Normal file
30
atom/renderer/lib/inspector.coffee
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# Use menu API to show context menu.
|
||||||
|
window.onload = ->
|
||||||
|
WebInspector.ContextMenu.prototype.show = ->
|
||||||
|
menuObject = @_buildDescriptor()
|
||||||
|
if menuObject.length
|
||||||
|
WebInspector._contextMenu = this
|
||||||
|
createMenu(menuObject, @_event)
|
||||||
|
@_event.consume()
|
||||||
|
|
||||||
|
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
|
||||||
|
template
|
||||||
|
|
||||||
|
createMenu = (items, event) ->
|
||||||
|
remote = require 'remote'
|
||||||
|
Menu = remote.require 'menu'
|
||||||
|
|
||||||
|
menu = Menu.buildFromTemplate convertToMenuTemplate(items.subItems)
|
||||||
|
menu.popup()
|
||||||
|
event.consume true
|
Loading…
Reference in a new issue