diff --git a/deluge/ui/gtkui/listview.py b/deluge/ui/gtkui/listview.py index 9a2aed9a6..4185c1445 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 46d9dbcc3..bd0d970c6 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)