diff --git a/ChangeLog b/ChangeLog index 8cc63a225..1844c3e7c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,7 @@ Deluge 0.9.07 - "1.0.0_RC7" (18 August 2008) * Fix hiding the bottom pane when disabling all the tabs * Fix not showing new torrents if you don't use the All label first * Fix size units to be more accurate + * Fix torrentview sorting to be persistent Null: * Fix #415 crash when using 'config-set' with no parameters diff --git a/deluge/ui/gtkui/listview.py b/deluge/ui/gtkui/listview.py index 0f6ffdcef..d560d03ab 100644 --- a/deluge/ui/gtkui/listview.py +++ b/deluge/ui/gtkui/listview.py @@ -160,10 +160,15 @@ class ListView: treeview_columns = self.treeview.get_columns() counter = 0 for column in treeview_columns: + sort = None + id, order = self.treeview.get_model().get_sort_column_id() + + if self.get_column_name(id) == column.get_title(): + sort = id # Append a new column state to the state list state.append(ListViewColumnState(column.get_title(), counter, column.get_width(), column.get_visible(), - column.get_sort_indicator(), int(column.get_sort_order()))) + sort, int(column.get_sort_order()))) # Increase the counter because this is how we determine position counter += 1 @@ -211,6 +216,12 @@ class ListView: else: return self.columns[name].column_indices[0] + def get_column_name(self, index): + """Get the header name for a liststore column index""" + for key, value in self.columns.items(): + if index in value.column_indices: + return key + def get_state_field_column(self, field): """Returns the column number for the state field""" for column in self.columns.keys(): @@ -285,9 +296,16 @@ class ListView: if self.liststore is not None: self.liststore.foreach(copy_row, (new_list, self.columns)) + sort_column = None + if self.treeview.get_model(): + # Save the liststore filter column + sort_column = self.treeview.get_model().get_sort_column_id() + self.liststore = new_list self.treeview.set_model(self.liststore) - + + if sort_column and sort_column != (None, None): + self.treeview.get_model().set_sort_column_id(*sort_column) return def remove_column(self, header): @@ -384,7 +402,7 @@ class ListView: self.columns[header].column_indices[text]) elif column_type == None: return - + column.set_sort_column_id(self.columns[header].column_indices[sortid]) column.set_clickable(True) column.set_resizable(True) @@ -401,8 +419,9 @@ class ListView: if column_state.width > 0: column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) column.set_fixed_width(column_state.width) - column.set_sort_indicator(column_state.sort) - column.set_sort_order(column_state.sort_order) + + if column_state.sort is not None and column_state.sort > -1: + self.treeview.get_model().set_sort_column_id(column_state.sort, column_state.sort_order) column.set_visible(column_state.visible) position = column_state.position diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py index 30ec58eee..e776cd647 100644 --- a/deluge/ui/gtkui/torrentview.py +++ b/deluge/ui/gtkui/torrentview.py @@ -164,13 +164,10 @@ class TorrentView(listview.ListView, component.Component): listview.cell_data_ratio, [float], status_field=["distributed_copies"]) - - # Set default sort column to # - self.liststore.set_sort_column_id(self.get_column_index("#"), gtk.SORT_ASCENDING) # Set filter to None for now self.filter = (None, None) - + self.create_model_filter() ### Connect Signals ### @@ -195,13 +192,18 @@ class TorrentView(listview.ListView, component.Component): """create new filter-model must be called after listview.create_new_liststore """ + sort_column = None + if self.treeview.get_model(): + # Save the liststore filter column + sort_column = self.treeview.get_model().get_sort_column_id() # Set the liststore filter column model_filter = self.liststore.filter_new() model_filter.set_visible_column( self.columns["filter"].column_indices[0]) self.model_filter = gtk.TreeModelSort(model_filter) self.treeview.set_model(self.model_filter) - + if sort_column and sort_column != (None, None): + self.treeview.get_model().set_sort_column_id(*sort_column) def _on_session_state(self, state): for torrent_id in state: