[gnome-news/wip/gbsneto/improvements: 12/12] feeds-view: always sync the listbox and viewed feed



commit 9e00ebffcac282e7eaaf6bd64ceca38b7dc7664d
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sun Mar 6 13:07:30 2016 -0300

    feeds-view: always sync the listbox and viewed feed

 gnomenews/view.py |   30 +++++++++++++++++++++---------
 1 files changed, 21 insertions(+), 9 deletions(-)
---
diff --git a/gnomenews/view.py b/gnomenews/view.py
index 9761140..13087d9 100644
--- a/gnomenews/view.py
+++ b/gnomenews/view.py
@@ -236,6 +236,16 @@ class FeedsView(GenericFeedsView):
         if feed['url'] in self.feeds:
             return
 
+        # Add a row to the listbox
+        row = Gtk.ListBoxRow()
+        row.add(Gtk.Label(label=feed['title'], margin=10, xalign=0))
+        row.set_tooltip_text(feed['url'])
+        row.feed = feed
+        row.show_all()
+
+        self.listbox.add(row)
+
+        # Add a flowbox with the items
         flowbox = Gtk.FlowBox(
             min_children_per_line=2,
             activate_on_single_click=True,
@@ -246,6 +256,10 @@ class FeedsView(GenericFeedsView):
         flowbox.get_style_context().add_class('feeds-list')
         flowbox.connect('child-activated', self._post_activated)
         flowbox.show()
+
+        flowbox.row = row
+        flowbox.feed = feed
+
         posts = self.tracker.get_posts_for_channel(feed['url'])
         [self._add_a_new_preview(post, flowbox) for post in posts]
 
@@ -253,15 +267,6 @@ class FeedsView(GenericFeedsView):
             feed['title'] = _("Unknown feed")
         self.feed_stack.add_titled(flowbox, feed['url'], feed['title'])
 
-        # Add a row to the listbox
-        row = Gtk.ListBoxRow()
-        row.add(Gtk.Label(label=feed['title'], margin=10, xalign=0))
-        row.set_tooltip_text(feed['url'])
-        row.feed = feed
-        row.show_all()
-
-        self.listbox.add(row)
-
         self.feeds[feed['url']] = (feed, row)
 
     @log
@@ -281,6 +286,7 @@ class FeedsView(GenericFeedsView):
             transition_duration=100,
             visible=True,
             can_focus=False)
+        self.feed_stack.connect('notify::visible-child-name', self.visible_feed_changed)
 
         feedstackScrolledWindow = Gtk.ScrolledWindow(expand=True)
         feedstackScrolledWindow.add(self.feed_stack)
@@ -303,6 +309,12 @@ class FeedsView(GenericFeedsView):
         self._box.show_all()
 
     @log
+    def visible_feed_changed(self, stack, property_name):
+        if stack.get_visible_child():
+            row = stack.get_visible_child().row
+            self.listbox.select_row(row)
+
+    @log
     def _on_row_selected(self, listbox, row, _=None):
         if row:
             self.feed_stack.set_visible_child_name(row.feed['url'])


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]