diff options
author | Debarshi Ray <debarshir@gnome.org> | 2017-06-09 12:15:53 +0200 |
---|---|---|
committer | Debarshi Ray <debarshir@gnome.org> | 2017-06-13 21:59:36 +0200 |
commit | 33b3985440b2c264085928b639732bd044b1d522 (patch) | |
tree | 8d225128e836651999ffc32eebd690ae573c0406 /gtk/gtkactionhelper.c | |
parent | 1e47b9ea67a5eefc255ca2b9199df7e18dc783f8 (diff) | |
download | gtk+-33b3985440b2c264085928b639732bd044b1d522.tar.gz |
GtkActionHelper: Allow a NULL action-name to unset the previous GAction
https://bugzilla.gnome.org/show_bug.cgi?id=783587
Diffstat (limited to 'gtk/gtkactionhelper.c')
-rw-r--r-- | gtk/gtkactionhelper.c | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/gtk/gtkactionhelper.c b/gtk/gtkactionhelper.c index 6a77b03b02..242528c921 100644 --- a/gtk/gtkactionhelper.c +++ b/gtk/gtkactionhelper.c @@ -41,7 +41,8 @@ static void gtk_action_helper_action_added (GtkActi GVariant *state, gboolean should_emit_signals); -static void gtk_action_helper_action_removed (GtkActionHelper *helper); +static void gtk_action_helper_action_removed (GtkActionHelper *helper, + gboolean should_emit_signals); static void gtk_action_helper_action_enabled_changed (GtkActionHelper *helper, gboolean enabled); @@ -190,7 +191,8 @@ gtk_action_helper_action_added (GtkActionHelper *helper, } static void -gtk_action_helper_action_removed (GtkActionHelper *helper) +gtk_action_helper_action_removed (GtkActionHelper *helper, + gboolean should_emit_signals) { GTK_NOTE(ACTIONS, g_message ("%s: action %s was removed", "actionhelper", helper->action_name)); @@ -202,13 +204,17 @@ gtk_action_helper_action_removed (GtkActionHelper *helper) if (helper->enabled) { helper->enabled = FALSE; - gtk_action_helper_report_change (helper, PROP_ENABLED); + + if (should_emit_signals) + gtk_action_helper_report_change (helper, PROP_ENABLED); } if (helper->active) { helper->active = FALSE; - gtk_action_helper_report_change (helper, PROP_ACTIVE); + + if (should_emit_signals) + gtk_action_helper_report_change (helper, PROP_ACTIVE); } } @@ -327,7 +333,7 @@ gtk_action_helper_observer_action_removed (GtkActionObserver *observer, GtkActionObservable *observable, const gchar *action_name) { - gtk_action_helper_action_removed (GTK_ACTION_HELPER (observer)); + gtk_action_helper_action_removed (GTK_ACTION_HELPER (observer), TRUE); } static void @@ -421,40 +427,44 @@ gtk_action_helper_set_action_name (GtkActionHelper *helper, "it is unlikely to work", "actionhelper", action_name)); + /* Start by recording the current state of our properties so we know + * what notify signals we will need to send. + */ + was_enabled = helper->enabled; + was_active = helper->active; + if (helper->action_name) { + gtk_action_helper_action_removed (helper, FALSE); gtk_action_observable_unregister_observer (GTK_ACTION_OBSERVABLE (helper->action_context), helper->action_name, GTK_ACTION_OBSERVER (helper)); - g_free (helper->action_name); + g_clear_pointer (&helper->action_name, g_free); } - helper->action_name = g_strdup (action_name); - - gtk_action_observable_register_observer (GTK_ACTION_OBSERVABLE (helper->action_context), - helper->action_name, - GTK_ACTION_OBSERVER (helper)); + if (action_name) + { + helper->action_name = g_strdup (action_name); - /* Start by recording the current state of our properties so we know - * what notify signals we will need to send. - */ - was_enabled = helper->enabled; - was_active = helper->active; + gtk_action_observable_register_observer (GTK_ACTION_OBSERVABLE (helper->action_context), + helper->action_name, + GTK_ACTION_OBSERVER (helper)); - if (g_action_group_query_action (G_ACTION_GROUP (helper->action_context), helper->action_name, - &enabled, ¶meter_type, NULL, NULL, &state)) - { - GTK_NOTE(ACTIONS, g_message ("%s: action %s existed from the start", "actionhelper", helper->action_name)); + if (g_action_group_query_action (G_ACTION_GROUP (helper->action_context), helper->action_name, + &enabled, ¶meter_type, NULL, NULL, &state)) + { + GTK_NOTE(ACTIONS, g_message ("%s: action %s existed from the start", "actionhelper", helper->action_name)); - gtk_action_helper_action_added (helper, enabled, parameter_type, state, FALSE); + gtk_action_helper_action_added (helper, enabled, parameter_type, state, FALSE); - if (state) - g_variant_unref (state); - } - else - { - GTK_NOTE(ACTIONS, g_message ("%s: action %s missing from the start", "actionhelper", helper->action_name)); - helper->enabled = FALSE; + if (state) + g_variant_unref (state); + } + else + { + GTK_NOTE(ACTIONS, g_message ("%s: action %s missing from the start", "actionhelper", helper->action_name)); + helper->enabled = FALSE; + } } /* Send the notifies for the properties that changed. |