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 647806 - gtk_combo_box_set_active_id() nit picks
gtk_combo_box_set_active_id() nit picks
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkComboBox
3.0.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2011-04-14 18:56 UTC by Matthew Barnes
Modified: 2011-04-26 12:02 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed patch (2.69 KB, patch)
2011-04-14 19:14 UTC, Matthew Barnes
reviewed Details | Review
Revised patch (3.89 KB, patch)
2011-04-15 11:18 UTC, Matthew Barnes
reviewed Details | Review
Revised patch (4.03 KB, patch)
2011-04-16 16:39 UTC, Matthew Barnes
accepted-commit_now Details | Review

Description Matthew Barnes 2011-04-14 18:56:54 UTC
The new "active-id" feature in GtkComboBox is really handy, but I have a few nit picks about how gtk_combo_box_set_active_id() is written currently.

1. Passing a NULL ID string should be equivalent to
   gtk_combo_box_set_active (combo_box, -1).

   Currently, passing a NULL ID string isn't even guarded against and will
   cause a crash.  See (2).

2. I have a use case for Evolution where one of the rows has a NULL value in
   the ID column.  Please use g_strcmp0() instead of strcmp() when comparing
   ID strings to avoid a crash.

3. Return a boolean indicating if the ID was found or not, so I can write
   things like:

      if (!gtk_combo_box_set_active_id (combo_box, desired_id))
          gtk_combo_box_set_active (combo_box, 0);  /* fallback */
Comment 1 Matthew Barnes 2011-04-14 19:14:34 UTC
Created attachment 185978 [details] [review]
Proposed patch
Comment 2 Matthias Clasen 2011-04-15 00:29:14 UTC
Review of attachment 185978 [details] [review]:

::: gtk/gtkcombobox.c
@@ +5645,3 @@
  * gtk_combo_box_set_active_id:
  * @combo_box: a #GtkComboBox
+ * @active_id: the ID of the row to select, or %NULL

Needs an allow-none annotation

@@ +5653,3 @@
  * the given ID then nothing happens.
  *
+ * Returns: %TRUE if a row with a matching ID was found

Maybe mention the 'debatable' case below in the return value docs ?

@@ +5689,2 @@
       gtk_tree_model_get (model, &iter, column, &id, -1);
+      match = g_strcmp0 (id, active_id) == 0;

This one seems 'debatable' to me. We could just as well mandate that the id column must not contain NULLs. Changing this strcmp here doesn't really hurt, but once we officially allow NULL as an id, wouldn't you expect gtk_combo_box_set_active_id (..., NULL) to activate the row with that id ? It seems that if we allow this, we should document NULL ids as non-activatable.
Comment 3 Matthew Barnes 2011-04-15 01:36:08 UTC
(In reply to comment #2)
> Review of attachment 185978 [details] [review]:
> This one seems 'debatable' to me. We could just as well mandate that the id
> column must not contain NULLs. Changing this strcmp here doesn't really hurt,
> but once we officially allow NULL as an id, wouldn't you expect
> gtk_combo_box_set_active_id (..., NULL) to activate the row with that id ? It
> seems that if we allow this, we should document NULL ids as non-activatable.

It seems most intuitive to me to say that rows having no ID string simply can't be selected by this function.  The function should just ignore such rows.  For consistency with the rest of the API, I would expect passing NULL to set_active_id() to behave exactly the same as passing NULL to set_active_iter(), which the patch does.

If that sounds reasonable I'll try to make the docs clearer about this.
Comment 4 Christian Persch 2011-04-15 10:52:16 UTC
I'd say it's quite natural to have NULLs in the ID column, e.g. for separator rows.
Comment 5 Matthew Barnes 2011-04-15 11:18:53 UTC
Created attachment 186017 [details] [review]
Revised patch

Updated the documentation as suggested, and tried to clarify how rows with NULL IDs strings are handled -- or at least how I think they should be handled.
Comment 6 Matthias Clasen 2011-04-15 14:46:09 UTC
Ok, I think thats fine. Lets see if Ryan wants to chime in, since this is his baby...
Comment 7 Allison Karlitskaya (desrt) 2011-04-15 15:36:08 UTC
Seems quite sane from the description (haven't looked at the patch).  I pretty much agree.
Comment 8 Allison Karlitskaya (desrt) 2011-04-15 15:40:56 UTC
Review of attachment 186017 [details] [review]:

Looks pretty fine overall, with some very small nit-picks.  I'd actually be happy enough if you merged the patch as-is, but maybe you agree with some of the suggestions.

::: gtk/gtkcombobox.c
@@ +5674,3 @@
+    {
+      gtk_combo_box_set_active (combo_box, -1);
+      return FALSE;  /* debatable, but TRUE seems less correct */

In terms of the common convention of returning "did the thing that I just requested work out the way I wanted?" I'd go for TRUE here.

Either way, I think it should be documented.  Just pick one -- it's not too important.

@@ +5692,2 @@
       gtk_tree_model_get (model, &iter, column, &id, -1);
+      match = g_strcmp0 (id, active_id) == 0;

maybe it is a bit more clear if this is written instead:

if (id == NULL)
  continue;

match = strcmp (...)


because it looks like maybe we consider the possibility of active_id == NULL here, which is not the case.
Comment 9 Matthew Barnes 2011-04-15 16:19:17 UTC
Both suggestions are fine with me.  Makes sense to fall back to the "TRUE means success" convention.
Comment 10 Matthew Barnes 2011-04-16 16:39:09 UTC
Created attachment 186083 [details] [review]
Revised patch

Hopefully the final patch with Ryan's suggestions.
Comment 11 Allison Karlitskaya (desrt) 2011-04-16 17:58:43 UTC
I'm happy.
Comment 12 Matthew Barnes 2011-04-22 19:54:08 UTC
Is this okay to commit then?
Comment 13 Matthias Clasen 2011-04-25 11:44:07 UTC
Review of attachment 186083 [details] [review]:

Yes, fine to commit