From 7597ba9343c1f6a18a536a0e3b9350d1c8d2cfad Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Thu, 21 Apr 2011 00:42:36 +0100 Subject: [PATCH] [#2372] [GTKUI] 'Ratio' column will not retain position This is a backport of restore_columns_order_from_state applied to develop code. --- deluge/ui/gtkui/listview.py | 42 ++++++++++++++++++++++++++++++++++ deluge/ui/gtkui/torrentview.py | 6 +++++ 2 files changed, 48 insertions(+) diff --git a/deluge/ui/gtkui/listview.py b/deluge/ui/gtkui/listview.py index 110e58e30..747c7002a 100644 --- a/deluge/ui/gtkui/listview.py +++ b/deluge/ui/gtkui/listview.py @@ -630,3 +630,45 @@ 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): + if self.state is None: + # No state file exists, so, no reordering can be done + return + columns = self.treeview.get_columns() + def find_column(header): + for column in columns: + if column.get_title() == header: + return column + + restored_columns = [] + for col_state in self.state: + if col_state.name in restored_columns: + # Duplicate column in state!?!?!? + continue + elif not col_state.visible: + # Column is not visible, no need to reposition + continue + + try: + column_at_position = columns[col_state.position] + except IndexError: + # Extra columns in loaded state, likely from plugins, so just skip them. + continue + if col_state.name == column_at_position.get_title(): + # It's in the right position + continue + column = find_column(col_state.name) + if not column: + log.debug("Could not find column matching \"%s\" on state." % + col_state.name) + # The cases where I've found that the column could not be found + # is when not using the english locale, ie, the default one, or + # when changing locales between runs. + # On the next load, all should be fine + continue + self.treeview.move_column_after(column, column_at_position) + # Get columns again to keep reordering since positions have changed + columns = self.treeview.get_columns() + restored_columns.append(col_state.name) + self.create_new_liststore() diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py index a6dba6cdb..97a68b662 100644 --- a/deluge/ui/gtkui/torrentview.py +++ b/deluge/ui/gtkui/torrentview.py @@ -286,6 +286,7 @@ class TorrentView(listview.ListView, component.Component): function=cell_data_trackericon, default=False) self.add_text_column(_("Save Path"), status_field=["save_path"], default=False) + self.restore_columns_order_from_state() # Set filter to None for now self.filter = None @@ -306,6 +307,7 @@ class TorrentView(listview.ListView, component.Component): self.treeview.connect("drag-drop", self.on_drag_drop) self.treeview.connect("drag_data_received", self.on_drag_data_received) 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) @@ -574,6 +576,10 @@ class TorrentView(listview.ListView, component.Component): def on_drag_data_received(self, widget, drag_context, x, y, selection_data, info, timestamp): widget.stop_emission("drag_data_received") + def on_columns_changed_event(self, treeview): + log.debug("Treeview Columns Changed") + self.save_state() + def on_torrentadded_event(self, torrent_id): self.add_row(torrent_id) self.mark_dirty(torrent_id)