Commit 8da1e8bd authored by Cédric Bellegarde's avatar Cédric Bellegarde

Do not recalculate shown/unshown and count everytime

parent a44a76ea
......@@ -27,14 +27,36 @@ class LabelIndicator(Gtk.Label):
Gtk.Label.__init__(self)
self.set_xalign(0.0)
self.set_yalign(0.80)
self.__show = True
self.__count = 0
self.__unshown = []
def shown(self, shown):
def update_count(self, add):
"""
Show indicator if not shown
@param show as bool
Update view count
@param add as bool
"""
self.__show = not shown
if add:
self.__count += 1
else:
self.__count -= 1
self.set_text(str(max(1, self.__count)))
def mark_unshown(self, webview):
"""
Mark view as unshown and redraw
@param webview as WebView
"""
if webview not in self.__unshown:
self.__unshown.append(webview)
self.queue_draw()
def mark_shown(self, webview):
"""
Mark view as shown and redraw
@param view as WebView
"""
if webview in self.__unshown:
self.__unshown.remove(webview)
self.queue_draw()
def do_get_preferred_width(self):
......@@ -50,7 +72,7 @@ class LabelIndicator(Gtk.Label):
@param cr as cairo.Context
"""
Gtk.Label.do_draw(self, cr)
if self.__show:
if self.__unshown:
w = self.get_allocated_width()
cr.stroke()
cr.translate(w - 5, 5)
......
......@@ -38,6 +38,7 @@ class PagesManagerChild(Gtk.FlowBoxChild):
builder.add_from_resource("/org/gnome/Eolie/PagesManagerChild.ui")
builder.connect_signals(self)
self.__indicator_label = LabelIndicator()
self.__indicator_label.mark_unshown(view.webview)
self.__indicator_label.set_hexpand(True)
self.__indicator_label.set_margin_right(4)
self.__indicator_label.set_property("halign", Gtk.Align.CENTER)
......@@ -330,4 +331,4 @@ class PagesManagerChild(Gtk.FlowBoxChild):
"""
Remove indicator
"""
self.__indicator_label.shown(True)
self.__indicator_label.mark_shown(webview)
......@@ -86,10 +86,10 @@ class SitesManagerChild(Gtk.ListBoxRow):
view.webview.connect("shown", self.__on_webview_shown)
view.webview.connect("favicon-changed",
self.__on_webview_favicon_changed)
self.__indicator_label.shown(view.webview.shown)
self.__update_count()
self.__update_indicator()
self.update_label()
self.update_label()
self.__indicator_label.update_count(True)
if not view.webview.shown:
self.__indicator_label.mark_unshown(view.webview)
def remove_view(self, view):
"""
......@@ -100,9 +100,10 @@ class SitesManagerChild(Gtk.ListBoxRow):
self.__views.remove(view)
view.webview.disconnect_by_func(self.__on_webview_shown)
view.webview.disconnect_by_func(self.__on_webview_favicon_changed)
self.__update_count()
self.__update_indicator()
self.update_label()
self.update_label()
self.__indicator_label.update_count(False)
if not view.webview.shown:
self.__indicator_label.mark_shown(view.webview)
def set_minimal(self, minimal):
"""
......@@ -226,23 +227,6 @@ class SitesManagerChild(Gtk.ListBoxRow):
#######################
# PRIVATE #
#######################
def __update_count(self):
"""
Update count
"""
count = len(self.__views)
self.__indicator_label.set_text(str(max(1, count)))
def __update_indicator(self):
"""
Update indicator
"""
shown = True
for view in self.__views:
if not view.webview.shown:
shown = False
self.__indicator_label.shown(shown)
def __update_popover_internals(self, widget):
"""
Little hack to manage Gtk.ModelButton text
......@@ -382,4 +366,4 @@ class SitesManagerChild(Gtk.ListBoxRow):
"""
Update indicataor
"""
self.__update_indicator()
self.__indicator_label.mark_shown(webview)
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