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.
This commit is contained in:
parent
5bc304470c
commit
98f80c0eb6
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue