GNOME Bugzilla – Bug 568334
Constructor properties for GtkAction
Last modified: 2009-01-22 18:01:42 UTC
It would be convenient if, at a minimum, GtkAction's "label", "stock-id", and "tooltip" properties were flagged as G_PARAM_CONSTRUCT so they are initialized before the constructed() method is called. They are, after all, required by gtk_action_new(). I don't think this would cause any backward compatibility issues. The constructed() method isn't widely used in GTK+ yet. Use Case: I'm writing a GtkAction subclass for Evolution called EPopupAction. The idea is for the actions controlling popup menu items to be proxies for equivalent actions in the main menu. By "proxy" I mean the GObject properties are kept in sync by way of ExoBindings [1], with two differences: 1) The popup action is invisible when the main menu action is insensitive. 2) EPopupAction can optionally override the label and tooltip of the equivalent main menu action that it proxies. Part (2) is where I'm having problems. In the GObject constructed() method I'd like to do this: if popup_action.label is NULL: exo_binding_new (main_menu_action, "label", popup_action, "label") if popup_action.tooltip is NULL: exo_binding_new (main_menu_action, "tooltip", popup_action, "tooltip") But because "label" and "tooltip" are no constructor properties, they don't get initialized until after constructed() is called. So I'm having to work around the problem by creating the bindings -after- returning from g_object_new(). [1] http://www.xfce.org/documentation/api/exo/exo-Binding-Properties-Functions.html
Created attachment 126809 [details] [review] Proposed patch Patch is trivial. Question is whether to do this and whether any other properties should be flagged as G_PARAM_CONSTRUCT.
I tend to use g_object_new with properties, not gtk_action_new. And from a quick look at code I've written, the third of three actions has no label. This is perfectly reasonable because stock ID's can contain labels. I would not really like to see my existing code to break apart during initialization. Is it that much more effort to work with notifications like everyone else does? :)
Ooooh, wait a second. This is G_PARAM_CONSTRUCT, but *not* G_PARAM_CONSTRUCT_ONLY. So you are not breaking API, you are only enhancing it. After having this realized, I would think this change should not matter to API users at all.
Right. I'm just asking for the properties to be initialized before constructed() gets called.
I don't see a reason not to do this. But I don't have a good answer for the 'what properties ?' question...
I'd say everything but "action-group" -could- be a constructor property. "action-group" is an implementation detail, not meant to be set by users.
Created attachment 127015 [details] [review] Make them all constructor properties As described in comment #6. Matthias told me to go ahead and commit this. 2009-01-22 Matthew Barnes <mbarnes@redhat.com> Bug 568334 – Constructor properties for GtkAction * gtk/gtkaction.c (gtk_action_class_init): Make all properties G_PARAM_CONSTRUCT except "action-group". Revision 22175.