GNOME Bugzilla – Bug 54529
make AccelGroup and AccelLabel work with GObjects rather than GtkObjects/GtkWidgets
Last modified: 2011-02-04 16:09:25 UTC
First a bit of rationale for this patch: I was thinking about what would be needed to do an action based menuing system where the menu items in the menu activate action objects. For accelerators to work properly in a system like this, the accelerators should be attached to the action objects rather than menu items. This is so that two menu items associated with the same action would display the same accelerator (the GtkAccelLabel for the menu items would point at the action object). The attached patch is the first try at the changes to gtk+ necessary to do a menu system like this. It still has a few issues. The first part is a patch to GtkAccelGroup that allows accelerators to be set on arbitrary GObjects rather than just GtkObjects. It has one issue at the moment though. In two places it connects to the "destroy" signal of the object. In the second case, it connects gtk_accel_group_delete_entries to clean up the list of entries associated with an object. This could probably be changed to use g_object_set_qdata_full so we can set a GDestroyNotify. Some of the g_object_get_qdata calls would need to be changed to g_object_steal_qdata for this to work. In the first case, the function is gtk_accel_group_object_destroy which actually uses the object passed as an argument, which makes it more difficult to use as a GDestroyNotify. The one idea I came up with was to traverse the attach_objects GSList of the first accel group in free_list to find the object with ref_count==0 (which will be the object being finalized). But this seems very hackish. The second part of the patch is to allow GtkAccelLabel to watch accelerators on arbitrary GObjects rather than just GtkWidgets. It changes the accel_widget property to accel_object, and the gtk_accel_label_set_accel_widget function to gtk_accel_label_set_accel_object (a compatibility macro was also added). I also converted GtkAccelLabel over to properties rather than gtk 1.2 style args. If the issues in the AccelGroup part of the patch can't be resolved, I can put together a patch that only contains the AccelLabel parts.
Created attachment 531 [details] [review] first go at AccelGroup/AccelLabel patch
Another useful feature would be to delegate which object accelerator changes go to in gtk_menu_key_press(). This would be needed for dynamic accelerator changing to work correctly if the menu item was just acting as a proxy for an action object. I haven't done a patch for this yet.
Created attachment 742 [details] [review] revised patch that also converts GtkAccelGroup to a GObject
attached update patch. This one doesn't rely on the accel object having a destroy signal (it uses weak refs and destroy notifiers). It also converts GtkAccelGroup to a GObject which fixes bug #55799.
patch applied to CVS