Update the columns menu when new columns are added.

This commit is contained in:
Andrew Resch 2007-09-05 17:26:52 +00:00
parent b4ad65ab9b
commit 02874799f2
2 changed files with 20 additions and 3 deletions

View file

@ -128,6 +128,9 @@ class ListView:
self.liststore_columns = []
# The GtkMenu that is created after every addition, removal or reorder
self.menu = None
# A list of menus that self.menu will be a submenu of everytime it is
# created.
self.checklist_menus = []
def set_treeview(self, treeview_widget):
"""Set the treeview widget that this listview uses."""
@ -153,7 +156,13 @@ class ListView:
# Set the column's visibility based on the widgets active state
self.columns[name].column.set_visible(widget.get_active())
return
def register_checklist_menu(self, menu):
"""Register a checklist menu with the listview. It will automatically
attach any new checklist menu it makes to this menu.
"""
self.checklist_menus.append(menu)
def create_checklist_menu(self):
"""Creates a menu used for toggling the display of columns."""
self.menu = gtk.Menu()
@ -173,6 +182,11 @@ class ListView:
menuitem.connect("toggled", self.on_menuitem_toggled)
# Add the new checkmenuitem to the menu
self.menu.append(menuitem)
# Attach this new menu to all the checklist_menus
for menu in self.checklist_menus:
menu.set_submenu(self.menu)
return self.menu
def create_new_liststore(self):

View file

@ -51,6 +51,11 @@ class TorrentView(listview.ListView):
self.window.main_glade.get_widget("torrent_view"))
log.debug("TorrentView Init..")
self.core = functions.get_core()
# Register the columns menu with the listview so it gets updated
# accordingly.
self.register_checklist_menu(
self.window.main_glade.get_widget("menu_columns"))
# Add the columns to the listview
self.add_text_column("torrent_id", hidden=True)
@ -87,8 +92,6 @@ class TorrentView(listview.ListView):
[float],
status_field=["ratio"])
self.window.main_glade.get_widget("menu_columns").set_submenu(
self.menu)
### Connect Signals ###
# Connect to the 'button-press-event' to know when to bring up the