Add addon: contextMenu
This commit is contained in:
parent
28c0e0582b
commit
317b00178a
|
@ -0,0 +1,37 @@
|
|||
import gi
|
||||
gi.require_version("WebKit2","4.0")
|
||||
from gi.repository import WebKit2,Gio
|
||||
|
||||
browser = mfp.require("browser")
|
||||
|
||||
def addItem(status,name,func):
|
||||
action = simpleAction(status,name,func)
|
||||
item = WebKit2.ContextMenuItem.new_from_gaction(action,name,None)
|
||||
status.contextMenu.prepend(item)
|
||||
|
||||
def simpleAction(status,name,func):
|
||||
action = Gio.SimpleAction.new(name,None)
|
||||
action.cStatus = status
|
||||
action.cFunc = func
|
||||
action.connect("activate",runAction)
|
||||
return action
|
||||
|
||||
def runAction(action,_):
|
||||
action.cFunc(action.cStatus)
|
||||
|
||||
def onMenu(*args):
|
||||
status = mfp.Bunch()
|
||||
status.webView = args[0]
|
||||
status.contextMenu = args[1]
|
||||
status.event = args[2]
|
||||
status.hit = args[3]
|
||||
status.addon = mfpl.g
|
||||
|
||||
status.contextMenu.prepend(WebKit2.ContextMenuItem.new_separator())
|
||||
browser.event.trigger("contextMenu:created",status)
|
||||
|
||||
def onWebviewCreated(webView):
|
||||
webView.connect("context-menu",onMenu)
|
||||
|
||||
eventHandler = mfp.Bunch()
|
||||
eventHandler["webview:created"] = onWebviewCreated
|
Loading…
Reference in New Issue