Module: deluge
Branch: master
Commit: 98f80c0eb6f2a83baee860d22bd2517af2b232a4

Author: Pedro Algarvio <[email protected]>
Date:   Thu Apr 21 00:42:36 2011 +0100

Restore column order from state.

On the TorrentView's treeview, the column's position stored on state was being 
ignored, but event if that info was not being ignored and passed to the several 
`add_column`'s the order could not be added because the order the columns are 
added does not(might not) match what was stored in state. So, we now restore 
the ordering once all columns are added.

---

 deluge/ui/gtkui/listview.py    |   18 ++++++++++++++++++
 deluge/ui/gtkui/torrentview.py |    6 ++++++
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/deluge/ui/gtkui/listview.py b/deluge/ui/gtkui/listview.py
index 9a2aed9..4185c14 100644
--- a/deluge/ui/gtkui/listview.py
+++ b/deluge/ui/gtkui/listview.py
@@ -607,3 +607,21 @@ class ListView:
     def on_keypress_search_by_name(self, model, columnn, key, iter):
         TORRENT_NAME_COL = 5
         return not 
model[iter][TORRENT_NAME_COL].lower().startswith(key.lower())
+
+    def restore_columns_order_from_state(self):
+        columns = self.treeview.get_columns()
+        def find_column(header):
+            for column in columns:
+                if column.get_title() == header:
+                    return column
+
+        for col_state in self.state:
+            column_at_position = columns[col_state.position]
+            if col_state.name == column_at_position.get_title():
+                # It's in the right position
+                continue
+            column = find_column(col_state.name)
+            self.treeview.move_column_after(column, column_at_position)
+            # Get columns again to keep reordering since positions have changed
+            columns = self.treeview.get_columns()
+        self.create_new_liststore()
diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py
index 46d9dbc..bd0d970 100644
--- a/deluge/ui/gtkui/torrentview.py
+++ b/deluge/ui/gtkui/torrentview.py
@@ -245,6 +245,7 @@ class TorrentView(listview.ListView, component.Component):
         self.add_text_column(_("Save Path"), status_field=["save_path"])
         self.add_text_column(_("Owner"), status_field=["owner"])
         self.add_bool_column(_("Public"), status_field=["public"])
+        self.restore_columns_order_from_state()
 
         # Set filter to None for now
         self.filter = None
@@ -264,6 +265,7 @@ class TorrentView(listview.ListView, component.Component):
 
         self.treeview.connect("drag-drop", self.on_drag_drop)
         self.treeview.connect("key-press-event", self.on_key_press_event)
+        self.treeview.connect("columns-changed", self.on_columns_changed_event)
 
         client.register_event_handler("TorrentStateChangedEvent", 
self.on_torrentstatechanged_event)
         client.register_event_handler("TorrentAddedEvent", 
self.on_torrentadded_event)
@@ -521,6 +523,10 @@ class TorrentView(listview.ListView, component.Component):
     def on_drag_drop(self, widget, drag_context, x, y, timestamp):
         widget.stop_emission("drag-drop")
 
+    def on_columns_changed_event(self, treeview):
+        log.debug("Treeview Columns Changed")
+        self.save_state()
+
     def on_torrentadded_event(self, torrent_id, from_state):
         self.add_row(torrent_id)
         self.mark_dirty(torrent_id)

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to