=?utf-8?q?Bug=20507683=20=E2=80=93=20Store=20application=20UI=20state
authorPaweł Paprota <ppawel@fastmail.fm>
Sun, 16 Mar 2008 11:22:00 +0000 (16 12:22 +0100)
committerPaweł Paprota <ppawel@fastmail.fm>
Sun, 20 Apr 2008 16:45:48 +0000 (20 18:45 +0200)
=20Added=20storing=20last=20expanded=20nodes=20in=20the=20feed=20list.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

straw/Constants.py
straw/FeedListView.py

index c15b839..2b6054a 100644 (file)
@@ -28,6 +28,7 @@ OPTION_OFFLINE = "/general/offline"
 OPTION_POLL_FREQUENCY = "/general/poll_frequency"
 
 OPTION_LAST_SELECTED_NODE = "/ui/last_selected_node"
+OPTION_LAST_EXPANDED_NODES = "/ui/last_expanded_nodes"
 
 OPTION_PROXY_TYPE = "/network/proxy_type"
 OPTION_PROXY_SERVER = "/network/proxy_server"
@@ -59,6 +60,7 @@ config_options_defaults = \
     OPTION_POLL_FREQUENCY:    1800,
 
     OPTION_LAST_SELECTED_NODE: -1,
+    OPTION_LAST_EXPANDED_NODES: "",
 
     OPTION_PROXY_TYPE:        "none",
     OPTION_PROXY_SERVER:      "http://example.server/",
index 1d8d87e..3b04c2a 100644 (file)
@@ -427,12 +427,29 @@ class FeedsView(MVP.WidgetView):
 
     def get_selected_node(self):
         nodes = [node for node in self.selected()]
-        
+
         if len(nodes) > 0:
             return nodes[0].node
         else:
             return None
-    
+
+    def get_expanded_nodes(self):
+        expanded = []
+
+        def add(treeview, path, expanded):
+            node = treeview.get_model()[path][Column.object].node
+            expanded.append(node)
+
+        self._widget.map_expanded_rows(add, expanded)
+
+        return expanded
+
+    def expand_nodes(self, nodes):
+        for node_id in nodes:
+            if node_id in self.model.tv_nodes:
+                path = self.model.tv_nodes[node_id].path
+                self._widget.expand_row(path, False)
+
     def select_node(self, id):
         path = self.model.tv_nodes[id].path
 
@@ -644,13 +661,24 @@ class FeedsPresenter(MVP.BasicPresenter):
             id = node.id
 
         Config.set(OPTION_LAST_SELECTED_NODE, id)
+        Config.set(OPTION_LAST_EXPANDED_NODES, ",".join([str(node.id) for node in self.view.get_expanded_nodes()]))
 
     def restore_state(self):
         id = Config.get(OPTION_LAST_SELECTED_NODE)
-        
+
         if id != -1:
             self.view.select_node(id)
 
+        expanded = Config.get(OPTION_LAST_EXPANDED_NODES)
+
+        if expanded:
+            try:
+                expanded = map(int, expanded.split(","))
+            except ValueError:
+                expanded = []
+
+        self.view.expand_nodes(expanded)
+
     def add_category(self):
         self.view.add_category()
 
@@ -663,26 +691,6 @@ class FeedsPresenter(MVP.BasicPresenter):
     def select_previous_feed(self):
         return self.view.select_previous_feed()
 
-    def _sort_func(self, model, a, b):
-        """
-        Sorts the feeds lexically.
-
-        From the gtk.TreeSortable.set_sort_func doc:
-
-        The comparison callback should return -1 if the iter1 row should come before
-        the iter2 row, 0 if the rows are equal, or 1 if the iter1 row should come
-        after the iter2 row.
-        """
-        retval = 0
-        fa = model.get_value(a, Column.OBJECT)
-        fb = model.get_value(b, Column.OBJECT)
-
-        if fa and fb:
-            retval = locale.strcoll(fa.title, fb.title)
-        elif fa is not None: retval = -1
-        elif fb is not None: retval = 1
-        return retval
-
     def show_feed_information(self, node):
         if node.type == "C":
             properties = categoryproperties