Commit af5c5156 authored by Cédric Bellegarde's avatar Cédric Bellegarde
Browse files

Fix #135

parent 5d0ad908
......@@ -408,8 +408,30 @@ class ProxyExtension(Server):
Server.__init__(self, self.__bus, PROXY_PATH)
webpage.connect("document-loaded", self.__on_document_loaded)
webpage.connect("send-request", self.__on_send_request)
webpage.connect("context-menu", self.__on_context_menu)
self.__extension = extension
def __on_context_menu(self, webpage, context_menu, hit):
"""
Add selection to context menu user data
@param webpage as WebKit2WebExtension.WebPage
@param context_menu as WebKit2WebExtension.ContextMenu
@param hit as WebKit2.HitTestResult
"""
document = webpage.get_dom_document()
if document is None:
return
window = document.get_default_view()
if window is None:
return
selection = window.get_selection()
if selection is None:
return
dom_range = selection.get_range_at(0)
if dom_range is not None:
value = dom_range.to_string()
context_menu.set_user_data(GLib.Variant("s", value))
def __on_send_request(self, webpage, request, redirect):
"""
Search for video in page
......
......@@ -24,6 +24,7 @@ from eolie.view_web_navigation import WebViewNavigation
from eolie.context import Context
from eolie.helper_passwords import PasswordsHelper
from eolie.list import LinkedList
from eolie.search import Search
from eolie.menu_form import FormMenu
......@@ -291,7 +292,7 @@ class WebView(WebKit2.WebView):
WebViewNavigation.__init__(self)
self.__window = window
# WebKitGTK doesn't provide an API to get selection, so try to guess
# it from clipboard
# it from clipboard FIXME Get it from extensions
self.__selection = ""
self._readable_content = ""
self.__last_click_event = {}
......@@ -448,23 +449,37 @@ class WebView(WebKit2.WebView):
hit.get_link_uri())
item = WebKit2.ContextMenuItem.new(action)
context_menu.insert(item, 1)
# Add an item for open all images
if view.is_loading() or parsed.scheme not in ["http", "https"]:
return
# FIXME https://bugs.webkit.org/show_bug.cgi?id=159631
# Introspection missing, Gtk.Action deprecated
action = Gtk.Action.new("save_imgs",
_("Save images"),
None,
None)
action.connect("activate", self.__on_save_images_activate,)
item = WebKit2.ContextMenuItem.new(action)
n_items = context_menu.get_n_items()
if El().settings.get_value("developer-extras"):
context_menu.insert(item, n_items - 2)
elif hit.context_is_selection():
search_term = context_menu.get_user_data().get_string()
# Add an item for open words in search
# FIXME https://bugs.webkit.org/show_bug.cgi?id=159631
# Introspection missing, Gtk.Action deprecated
action = Gtk.Action.new("search_words",
_("Search on the Web"),
None,
None)
action.connect("activate",
self.__on_search_words_activate,
search_term)
item = WebKit2.ContextMenuItem.new(action)
context_menu.insert(item, 1)
else:
context_menu.insert(item, n_items)
# Add an item for open all images
if view.is_loading() or parsed.scheme not in ["http", "https"]:
return
# FIXME https://bugs.webkit.org/show_bug.cgi?id=159631
# Introspection missing, Gtk.Action deprecated
action = Gtk.Action.new("save_imgs",
_("Save images"),
None,
None)
action.connect("activate", self.__on_save_images_activate,)
item = WebKit2.ContextMenuItem.new(action)
n_items = context_menu.get_n_items()
if El().settings.get_value("developer-extras"):
context_menu.insert(item, n_items - 2)
else:
context_menu.insert(item, n_items)
def __on_open_new_page_activate(self, action, uri):
"""
......@@ -474,6 +489,16 @@ class WebView(WebKit2.WebView):
"""
self.__window.container.add_webview(uri, Gdk.WindowType.CHILD)
def __on_search_words_activate(self, action, search_term):
"""
Open link in a new page
@param action as Gtk.Action
@param search_term as str
"""
search = Search()
uri = search.get_search_uri(search_term)
self.__window.container.add_webview(uri, Gdk.WindowType.CHILD)
def __on_save_images_activate(self, action):
"""
Show images filtering popover
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment