mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-02 22:48:40 +00:00
Store removed columns' state so that plugin's columns are restored properly
This commit is contained in:
parent
9238fab360
commit
c2e3f3d228
1 changed files with 27 additions and 7 deletions
|
@ -165,6 +165,10 @@ class ListView:
|
||||||
# created.
|
# created.
|
||||||
self.checklist_menus = []
|
self.checklist_menus = []
|
||||||
|
|
||||||
|
# Store removed columns state. This is needed for plugins that remove
|
||||||
|
# their columns prior to having the state list saved on shutdown.
|
||||||
|
self.removed_columns_state = []
|
||||||
|
|
||||||
# Create the model filter and column
|
# Create the model filter and column
|
||||||
self.add_bool_column("filter", hidden=True)
|
self.add_bool_column("filter", hidden=True)
|
||||||
|
|
||||||
|
@ -193,6 +197,22 @@ class ListView:
|
||||||
column.sort_func,
|
column.sort_func,
|
||||||
column.sort_id)
|
column.sort_id)
|
||||||
|
|
||||||
|
def create_column_state(self, column, position=None):
|
||||||
|
if not position:
|
||||||
|
# Find the position
|
||||||
|
for index, c in enumerate(self.treeview.get_columns()):
|
||||||
|
if column.get_title() == c.get_title():
|
||||||
|
position = index
|
||||||
|
break
|
||||||
|
sort = None
|
||||||
|
sort_id, order = self.model_filter.get_sort_column_id()
|
||||||
|
if self.get_column_name(sort_id) == column.get_title():
|
||||||
|
sort = sort_id
|
||||||
|
|
||||||
|
return ListViewColumnState(column.get_title(), position,
|
||||||
|
column.get_width(), column.get_visible(),
|
||||||
|
sort, int(column.get_sort_order()))
|
||||||
|
|
||||||
def save_state(self, filename):
|
def save_state(self, filename):
|
||||||
"""Saves the listview state (column positions and visibility) to
|
"""Saves the listview state (column positions and visibility) to
|
||||||
filename."""
|
filename."""
|
||||||
|
@ -201,14 +221,10 @@ class ListView:
|
||||||
|
|
||||||
# Get the list of TreeViewColumns from the TreeView
|
# Get the list of TreeViewColumns from the TreeView
|
||||||
for counter, column in enumerate(self.treeview.get_columns()):
|
for counter, column in enumerate(self.treeview.get_columns()):
|
||||||
sort = None
|
|
||||||
id, order = self.model_filter.get_sort_column_id()
|
|
||||||
if self.get_column_name(id) == column.get_title():
|
|
||||||
sort = id
|
|
||||||
# Append a new column state to the state list
|
# Append a new column state to the state list
|
||||||
state.append(ListViewColumnState(column.get_title(), counter,
|
state.append(self.create_column_state(column, counter))
|
||||||
column.get_width(), column.get_visible(),
|
|
||||||
sort, int(column.get_sort_order())))
|
state += self.removed_columns_state
|
||||||
|
|
||||||
# Get the config location for saving the state file
|
# Get the config location for saving the state file
|
||||||
config_location = deluge.configmanager.get_config_dir()
|
config_location = deluge.configmanager.get_config_dir()
|
||||||
|
@ -338,6 +354,10 @@ class ListView:
|
||||||
|
|
||||||
def remove_column(self, header):
|
def remove_column(self, header):
|
||||||
"""Removes the column with the name 'header' from the listview"""
|
"""Removes the column with the name 'header' from the listview"""
|
||||||
|
# Store a copy of this columns state in case it's re-added
|
||||||
|
state = self.create_column_state(self.columns[header].column)
|
||||||
|
self.removed_columns_state.append(state)
|
||||||
|
|
||||||
# Start by removing this column from the treeview
|
# Start by removing this column from the treeview
|
||||||
self.treeview.remove_column(self.columns[header].column)
|
self.treeview.remove_column(self.columns[header].column)
|
||||||
# Get the column indices
|
# Get the column indices
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue