Commit f4cfa06a authored by Cédric Bellegarde's avatar Cédric Bellegarde

Present matching page to user while typing in Gtk.Entry. Fix #224

parent b0b416b1
......@@ -75,7 +75,7 @@ class Container(Gtk.Overlay):
# Notify user about new window
if window_type == Gdk.WindowType.OFFSCREEN and\
panel_mode == PanelMode.NONE:
GLib.idle_add(self.__add_overlay_view, view)
GLib.idle_add(self.add_overlay_view, view)
else:
webview.set_delayed_uri(uri)
webview.emit("title-changed", uri)
......@@ -119,6 +119,38 @@ class Container(Gtk.Overlay):
self.__window.toolbar.actions.count_label.set_text(count)
return view
def add_overlay_view(self, view, static=True):
"""
Add an overlay view
@param view as View
@param static as bool
"""
from eolie.pages_overlay import PagesOverlay
if self.__pages_overlay is None:
self.__pages_overlay = PagesOverlay(self.__window)
self.add_overlay(self.__pages_overlay)
# Destroy previous non static views
already_exists = False
for child in self.__pages_overlay.children:
if view == child.view:
already_exists = True
elif not child.static:
self.__pages_overlay.destroy_child(child.view)
if not already_exists:
self.__pages_overlay.show()
self.__pages_overlay.add_child(view, static)
def remove_overlay_views(self):
"""
Remove all overlay views (only static ones)
@param static as bool
"""
if self.__pages_overlay is None:
return
for child in self.__pages_overlay.children:
if not child.static:
self.__pages_overlay.destroy_child(child.view)
def load_uri(self, uri):
"""
Load uri in current view
......@@ -252,15 +284,3 @@ class Container(Gtk.Overlay):
view = View(webview, parent, self.__window)
view.show()
return view
def __add_overlay_view(self, view):
"""
Add an overlay view
@param view as View
"""
from eolie.pages_overlay import PagesOverlay
if self.__pages_overlay is None:
self.__pages_overlay = PagesOverlay(self.__window)
self.add_overlay(self.__pages_overlay)
self.__pages_overlay.show()
self.__pages_overlay.add_child(view)
......@@ -59,7 +59,7 @@ class PagesManager(Gtk.EventBox):
@param view as View
@return child
"""
child = self._CHILD_CLASS(view, self._window)
child = self._CHILD_CLASS(view, self._window, False)
child.show()
# We want to insert child next to its parent and brothers
......
......@@ -22,12 +22,17 @@ class PagesManagerChild:
Need to be inherited by a Gtk.*BoxRow
"""
def __init__(self, view, window):
def __init__(self, view, window, static):
"""
Init child
@param view as View
@param window as Window
@param static as bool,
if view is static, will not be auto destroyed
"""
self._view = view
self._window = window
self.__static = static
self.__connected_ids = []
self.__scroll_timeout_id = None
builder = Gtk.Builder()
......@@ -122,6 +127,14 @@ class PagesManagerChild:
"""
return self._view
@property
def static(self):
"""
True if view is static
@return bool
"""
return self.__static
#######################
# PROTECTED #
#######################
......
......@@ -23,14 +23,15 @@ class PagesManagerFlowBoxChild(Gtk.FlowBoxChild, PagesManagerChild):
A stack box child
"""
def __init__(self, view, window):
def __init__(self, view, window, static):
"""
Init child
@param view as View
@param window as Window
@param static as bool
"""
Gtk.FlowBoxChild.__init__(self)
PagesManagerChild.__init__(self, view, window)
PagesManagerChild.__init__(self, view, window, static)
self.set_property("halign", Gtk.Align.START)
self.set_margin_start(20)
self.set_margin_end(20)
......@@ -41,6 +42,13 @@ class PagesManagerFlowBoxChild(Gtk.FlowBoxChild, PagesManagerChild):
# TODO: 12?
self.set_property("height-request", ArtSize.START_HEIGHT + 12)
def update(self):
"""
Update child title, favicon and snapshot
"""
PagesManagerChild.update(self)
self.set_snapshot(self._view.webview.get_uri(), False)
def set_snapshot(self, uri, save):
"""
Set webpage preview
......
......@@ -35,7 +35,7 @@ class PagesManagerListBoxChild(Gtk.ListBoxRow, PagesManagerChild):
@param window as Window
"""
Gtk.ListBoxRow.__init__(self)
PagesManagerChild.__init__(self, view, window)
PagesManagerChild.__init__(self, view, window, False)
self.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, [],
Gdk.DragAction.MOVE)
self.drag_source_add_text_targets()
......
......@@ -146,16 +146,19 @@ class PagesOverlay(Gtk.EventBox):
self.connect("leave-notify-event", self.__on_leave_notify_event)
self.add(overlay)
def add_child(self, view):
def add_child(self, view, static):
"""
Add child to sidebar
@param view as View
@param static as bool
@return child
"""
child = PagesManagerFlowBoxChild(view, self.__window)
child = PagesManagerFlowBoxChild(view, self.__window, static)
child.get_style_context().add_class("box-dark-shadow")
child.connect("destroy", self.__on_child_destroy)
child.show()
if not static:
child.update()
self.__pages_manager.add_child(child)
self.__pages_manager.show()
self.__pages_manager.hide_next()
......@@ -169,6 +172,15 @@ class PagesOverlay(Gtk.EventBox):
if child.view == view:
child.destroy()
break
@property
def children(self):
"""
Get views ordered
@return [PagesManagerChild]
"""
return self.__pages_manager.children
#######################
# PROTECTED #
#######################
......
......@@ -834,6 +834,7 @@ class ToolbarTitle(Gtk.Bin):
self.__cancellable.cancel()
self.__cancellable.reset()
parsed = urlparse(value)
self.__show_related_view(value)
network = Gio.NetworkMonitor.get_default().get_network_available()
is_uri = parsed.scheme in ["about, http", "file", "https", "populars"]
if is_uri:
......@@ -852,6 +853,23 @@ class ToolbarTitle(Gtk.Bin):
self.__entry.set_icon_tooltip_text(Gtk.EntryIconPosition.PRIMARY,
"")
def __show_related_view(self, value):
"""
Walk all available views and show it if related to current uri
@param value as str
"""
if not value:
self.__window.container.remove_overlay_views()
return
panel_mode = El().settings.get_enum("panel-mode")
if panel_mode != PanelMode.NONE:
return
for view in self.__window.container.views:
view_parsed = urlparse(view.webview.get_uri())
if view_parsed.netloc.find(value) != -1:
self.__window.container.add_overlay_view(view, False)
return
def __search_suggestion(self, uri, status, content, encoding, value):
"""
Add suggestions
......
......@@ -296,6 +296,7 @@ class WebViewSignalsHandler:
parsed = urlparse(uri)
wanted_scheme = parsed.scheme in ["http", "https", "file"]
if event == WebKit2.LoadEvent.STARTED:
self._window.container.remove_overlay_views()
self._window.toolbar.title.set_title(uri)
if wanted_scheme:
self._window.toolbar.title.show_spinner(True)
......
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