After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 568334 - Constructor properties for GtkAction
Constructor properties for GtkAction
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Class: UIManager / Actions
2.14.x
Other Linux
: Normal trivial
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on: 568742
Blocks:
 
 
Reported: 2009-01-19 19:51 UTC by Matthew Barnes
Modified: 2009-01-22 18:01 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed patch (1.16 KB, patch)
2009-01-19 23:56 UTC, Matthew Barnes
none Details | Review
Make them all constructor properties (4.35 KB, patch)
2009-01-22 18:01 UTC, Matthew Barnes
none Details | Review

Description Matthew Barnes 2009-01-19 19:51:39 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
Comment 1 Matthew Barnes 2009-01-19 23:56:13 UTC
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.
Comment 2 Christian Dywan 2009-01-20 16:51:51 UTC
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? :)
Comment 3 Christian Dywan 2009-01-20 16:55:18 UTC
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.
Comment 4 Matthew Barnes 2009-01-20 21:43:23 UTC
Right.  I'm just asking for the properties to be initialized before constructed() gets called.
Comment 5 Matthias Clasen 2009-01-22 06:34:15 UTC
I don't see a reason not to do this.
But I don't have a good answer for the 'what properties ?' question...
Comment 6 Matthew Barnes 2009-01-22 13:20:18 UTC
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.
Comment 7 Matthew Barnes 2009-01-22 18:01:00 UTC
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.