[gtk+/wip/action-helper] GtkActionHelper: don't query NULL action groups



commit 3bed77577cc20634c35ba3bf2ba0e6a9bb3990f3
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Jun 21 10:14:30 2012 -0400

    GtkActionHelper: don't query NULL action groups
    
    Don't try to query the action group if our action name is NULL.
    
    Add some comments to the function that had the error in order to explain
    what's happening.

 gtk/gtkactionhelper.c |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkactionhelper.c b/gtk/gtkactionhelper.c
index b5dff1c..4c79f92 100644
--- a/gtk/gtkactionhelper.c
+++ b/gtk/gtkactionhelper.c
@@ -428,10 +428,23 @@ gtk_action_helper_actions_changed (GtkWidget   *widget,
   GtkActionHelperRole old_role;
   GActionGroup *group;
 
-  if (action_group_name && !g_str_equal (action_group_name, helper->action_group_name))
+  /* We are interested in two cases:
+   *
+   *   - the group name that we were watching has changed
+   *
+   *   - NULL means potentially all groups have changed
+   *
+   * Note: helper->action_group_name could be NULL.
+   */
+  if (action_group_name && g_strcmp0 (action_group_name, helper->action_group_name) != 0)
     return;
 
-  if (helper->widget)
+  /* If either the widget is NULL or the group name is NULL then we
+   * should not be tracking any action group.  This function is called
+   * in those two cases in order to clean up any existing group, so we
+   * take group = NULL for those and continue normally.
+   */
+  if (helper->widget && helper->action_group_name)
     group = gtk_widget_get_action_group_by_name (GTK_WIDGET (helper->widget), helper->action_group_name);
   else
     group = NULL;
@@ -441,7 +454,7 @@ gtk_action_helper_actions_changed (GtkWidget   *widget,
     return;
 
   /* We already had the group and we still have the same one. */
-  if (group != NULL && helper->group != NULL && helper->group->group == group)
+  if (helper->group->group == group)
     return;
 
   /* At this point we know that a change of some kind will happen.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]