[#2372] [GTKUI] 'Ratio' column will not retain position

This is a backport of restore_columns_order_from_state applied to develop code.
This commit is contained in:
Pedro Algarvio 2011-04-21 00:42:36 +01:00 committed by Calum Lind
parent 41f1ad9f5f
commit 7597ba9343
2 changed files with 48 additions and 0 deletions

View File

@ -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()

View File

@ -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)