From e8c93d56a0c0fb7a4776c54ab9441f3f9a4834db Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 6 Sep 2003 23:52:00 +0000 Subject: [PATCH] Fix a C99ism. (#121640, Josh Beam) 2003-09-07 Matthias Clasen * gtk/gtkuimanager.c (update_node): Fix a C99ism. (#121640, Josh Beam) Fixes for accelerator handling during (un)merging: * gtk/gtkuimanager.c (update_node): Move setting info-action after the switch, since the old action is needed in some cases. In cases of proxy type mismatch, disconnect the old proxy from the old action. * gtk/gtkaction.c (remove_proxy): Renamed from gtk_action_remove_proxy(). Move unsetting of the accelerator here from disconnect_proxy() in order to catch all cases of removing a proxy. (gtk_action_disconnect_proxy): Fix logic in g_return_if_fail() to fail if proxy isn't a proxy of action. --- ChangeLog | 19 +++++++++++++ ChangeLog.pre-2-10 | 19 +++++++++++++ ChangeLog.pre-2-4 | 19 +++++++++++++ ChangeLog.pre-2-6 | 19 +++++++++++++ ChangeLog.pre-2-8 | 19 +++++++++++++ gtk/gtkaction.c | 20 +++++++------- gtk/gtkuimanager.c | 69 +++++++++++++++++++++++++++------------------- 7 files changed, 145 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index b0653f15ef..318b16d878 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2003-09-07 Matthias Clasen + + * gtk/gtkuimanager.c (update_node): Fix a C99ism. (#121640, + Josh Beam) + + Fixes for accelerator handling during (un)merging: + + * gtk/gtkuimanager.c (update_node): Move setting info-action + after the switch, since the old action is needed in some cases. + In cases of proxy type mismatch, disconnect the old proxy from + the old action. + + * gtk/gtkaction.c (remove_proxy): Renamed from + gtk_action_remove_proxy(). Move unsetting of the accelerator + here from disconnect_proxy() in order to catch all cases of + removing a proxy. + (gtk_action_disconnect_proxy): Fix logic in g_return_if_fail() + to fail if proxy isn't a proxy of action. + 2003-09-07 Pablo Saratxaga * configure.in: Added Uzbek latin (uz) and cyrillic (uz@Cyrl) to diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index b0653f15ef..318b16d878 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,22 @@ +2003-09-07 Matthias Clasen + + * gtk/gtkuimanager.c (update_node): Fix a C99ism. (#121640, + Josh Beam) + + Fixes for accelerator handling during (un)merging: + + * gtk/gtkuimanager.c (update_node): Move setting info-action + after the switch, since the old action is needed in some cases. + In cases of proxy type mismatch, disconnect the old proxy from + the old action. + + * gtk/gtkaction.c (remove_proxy): Renamed from + gtk_action_remove_proxy(). Move unsetting of the accelerator + here from disconnect_proxy() in order to catch all cases of + removing a proxy. + (gtk_action_disconnect_proxy): Fix logic in g_return_if_fail() + to fail if proxy isn't a proxy of action. + 2003-09-07 Pablo Saratxaga * configure.in: Added Uzbek latin (uz) and cyrillic (uz@Cyrl) to diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index b0653f15ef..318b16d878 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,22 @@ +2003-09-07 Matthias Clasen + + * gtk/gtkuimanager.c (update_node): Fix a C99ism. (#121640, + Josh Beam) + + Fixes for accelerator handling during (un)merging: + + * gtk/gtkuimanager.c (update_node): Move setting info-action + after the switch, since the old action is needed in some cases. + In cases of proxy type mismatch, disconnect the old proxy from + the old action. + + * gtk/gtkaction.c (remove_proxy): Renamed from + gtk_action_remove_proxy(). Move unsetting of the accelerator + here from disconnect_proxy() in order to catch all cases of + removing a proxy. + (gtk_action_disconnect_proxy): Fix logic in g_return_if_fail() + to fail if proxy isn't a proxy of action. + 2003-09-07 Pablo Saratxaga * configure.in: Added Uzbek latin (uz) and cyrillic (uz@Cyrl) to diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index b0653f15ef..318b16d878 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,22 @@ +2003-09-07 Matthias Clasen + + * gtk/gtkuimanager.c (update_node): Fix a C99ism. (#121640, + Josh Beam) + + Fixes for accelerator handling during (un)merging: + + * gtk/gtkuimanager.c (update_node): Move setting info-action + after the switch, since the old action is needed in some cases. + In cases of proxy type mismatch, disconnect the old proxy from + the old action. + + * gtk/gtkaction.c (remove_proxy): Renamed from + gtk_action_remove_proxy(). Move unsetting of the accelerator + here from disconnect_proxy() in order to catch all cases of + removing a proxy. + (gtk_action_disconnect_proxy): Fix logic in g_return_if_fail() + to fail if proxy isn't a proxy of action. + 2003-09-07 Pablo Saratxaga * configure.in: Added Uzbek latin (uz) and cyrillic (uz@Cyrl) to diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index b0653f15ef..318b16d878 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,22 @@ +2003-09-07 Matthias Clasen + + * gtk/gtkuimanager.c (update_node): Fix a C99ism. (#121640, + Josh Beam) + + Fixes for accelerator handling during (un)merging: + + * gtk/gtkuimanager.c (update_node): Move setting info-action + after the switch, since the old action is needed in some cases. + In cases of proxy type mismatch, disconnect the old proxy from + the old action. + + * gtk/gtkaction.c (remove_proxy): Renamed from + gtk_action_remove_proxy(). Move unsetting of the accelerator + here from disconnect_proxy() in order to catch all cases of + removing a proxy. + (gtk_action_disconnect_proxy): Fix logic in g_return_if_fail() + to fail if proxy isn't a proxy of action. + 2003-09-07 Pablo Saratxaga * configure.in: Added Uzbek latin (uz) and cyrillic (uz@Cyrl) to diff --git a/gtk/gtkaction.c b/gtk/gtkaction.c index ff5a718036..df4301450b 100644 --- a/gtk/gtkaction.c +++ b/gtk/gtkaction.c @@ -437,10 +437,13 @@ create_tool_item (GtkAction *action) } static void -gtk_action_remove_proxy (GtkWidget *widget, - GtkAction *action) +remove_proxy (GtkWidget *proxy, + GtkAction *action) { - action->private_data->proxies = g_slist_remove (action->private_data->proxies, widget); + if (GTK_IS_MENU_ITEM (proxy)) + gtk_menu_item_set_accel_path (GTK_MENU_ITEM (proxy), NULL); + + action->private_data->proxies = g_slist_remove (action->private_data->proxies, proxy); } static void @@ -531,7 +534,7 @@ connect_proxy (GtkAction *action, /* add this widget to the list of proxies */ action->private_data->proxies = g_slist_prepend (action->private_data->proxies, proxy); g_signal_connect (proxy, "destroy", - G_CALLBACK (gtk_action_remove_proxy), action); + G_CALLBACK (remove_proxy), action); g_signal_connect_object (action, "notify::sensitive", G_CALLBACK (gtk_action_sync_property), proxy, 0); @@ -661,9 +664,9 @@ disconnect_proxy (GtkAction *action, /* remove proxy from list of proxies */ g_signal_handlers_disconnect_by_func (proxy, - G_CALLBACK (gtk_action_remove_proxy), + G_CALLBACK (remove_proxy), action); - gtk_action_remove_proxy (proxy, action); + remove_proxy (proxy, action); /* disconnect the activate handler */ g_signal_handlers_disconnect_by_func (proxy, @@ -683,9 +686,6 @@ disconnect_proxy (GtkAction *action, G_CALLBACK (gtk_action_sync_label), proxy); - if (GTK_IS_MENU_ITEM (widget)) - gtk_menu_item_set_accel_path (GTK_MENU_ITEM (widget), NULL); - /* toolbar button specific synchronisers ... */ g_signal_handlers_disconnect_by_func (action, G_CALLBACK (gtk_action_sync_short_label), @@ -833,7 +833,7 @@ gtk_action_disconnect_proxy (GtkAction *action, g_return_if_fail (GTK_IS_ACTION (action)); g_return_if_fail (GTK_IS_WIDGET (proxy)); - g_return_if_fail (g_object_get_data (G_OBJECT (proxy), "gtk-action") != action); + g_return_if_fail (g_object_get_data (G_OBJECT (proxy), "gtk-action") == action); (* GTK_ACTION_GET_CLASS (action)->disconnect_proxy) (action, proxy); } diff --git a/gtk/gtkuimanager.c b/gtk/gtkuimanager.c index ddef61075c..d03f3006e8 100644 --- a/gtk/gtkuimanager.c +++ b/gtk/gtkuimanager.c @@ -1616,12 +1616,6 @@ update_node (GtkUIManager *self, goto recurse_children; } - if (info->action) - g_object_unref (info->action); - info->action = action; - if (info->action) - g_object_ref (info->action); - switch (info->type) { case NODE_TYPE_MENUBAR: @@ -1647,7 +1641,7 @@ update_node (GtkUIManager *self, GList *siblings; /* remove the proxy if it is of the wrong type ... */ if (info->proxy && G_OBJECT_TYPE (info->proxy) != - GTK_ACTION_GET_CLASS (info->action)->menu_item_type) + GTK_ACTION_GET_CLASS (action)->menu_item_type) { prev_submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (info->proxy)); if (prev_submenu) @@ -1655,6 +1649,7 @@ update_node (GtkUIManager *self, g_object_ref (prev_submenu); gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy), NULL); } + gtk_action_disconnect_proxy (info->action, info->proxy); gtk_container_remove (GTK_CONTAINER (info->proxy->parent), info->proxy); info->proxy = NULL; @@ -1667,9 +1662,11 @@ update_node (GtkUIManager *self, if (find_menu_position (node, &menushell, &pos)) { - info->proxy = gtk_action_create_menu_item (info->action); + GtkWidget *tearoff; + + info->proxy = gtk_action_create_menu_item (action); menu = gtk_menu_new (); - GtkWidget *tearoff = gtk_tearoff_menu_item_new (); + tearoff = gtk_tearoff_menu_item_new (); gtk_menu_shell_append (GTK_MENU_SHELL (menu), tearoff); gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy), menu); gtk_menu_set_accel_group (GTK_MENU (menu), self->private_data->accel_group); @@ -1677,7 +1674,7 @@ update_node (GtkUIManager *self, } } else - gtk_action_connect_proxy (info->action, info->proxy); + gtk_action_connect_proxy (action, info->proxy); if (prev_submenu) { gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy), @@ -1709,13 +1706,17 @@ update_node (GtkUIManager *self, !GTK_IS_SEPARATOR_MENU_ITEM (info->extra)) { if (info->proxy) - gtk_container_remove (GTK_CONTAINER (info->proxy->parent), - info->proxy); + { + gtk_container_remove (GTK_CONTAINER (info->proxy->parent), + info->proxy); + info->proxy = NULL; + } if (info->extra) - gtk_container_remove (GTK_CONTAINER (info->extra->parent), - info->extra); - info->proxy = NULL; - info->extra = NULL; + { + gtk_container_remove (GTK_CONTAINER (info->extra->parent), + info->extra); + info->extra = NULL; + } } if (info->proxy == NULL) { @@ -1740,13 +1741,17 @@ update_node (GtkUIManager *self, !GTK_IS_SEPARATOR_TOOL_ITEM (info->extra)) { if (info->proxy) - gtk_container_remove (GTK_CONTAINER (info->proxy->parent), - info->proxy); + { + gtk_container_remove (GTK_CONTAINER (info->proxy->parent), + info->proxy); + info->proxy = NULL; + } if (info->extra) - gtk_container_remove (GTK_CONTAINER (info->extra->parent), - info->extra); - info->proxy = NULL; - info->extra = NULL; + { + gtk_container_remove (GTK_CONTAINER (info->extra->parent), + info->extra); + info->extra = NULL; + } } if (info->proxy == NULL) { @@ -1770,8 +1775,9 @@ update_node (GtkUIManager *self, case NODE_TYPE_MENUITEM: /* remove the proxy if it is of the wrong type ... */ if (info->proxy && G_OBJECT_TYPE (info->proxy) != - GTK_ACTION_GET_CLASS (info->action)->menu_item_type) + GTK_ACTION_GET_CLASS (action)->menu_item_type) { + gtk_action_disconnect_proxy (info->action, info->proxy); gtk_container_remove (GTK_CONTAINER (info->proxy->parent), info->proxy); info->proxy = NULL; @@ -1784,7 +1790,7 @@ update_node (GtkUIManager *self, if (find_menu_position (node, &menushell, &pos)) { - info->proxy = gtk_action_create_menu_item (info->action); + info->proxy = gtk_action_create_menu_item (action); gtk_menu_shell_insert (GTK_MENU_SHELL (menushell), info->proxy, pos); @@ -1793,14 +1799,15 @@ update_node (GtkUIManager *self, else { gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy), NULL); - gtk_action_connect_proxy (info->action, info->proxy); + gtk_action_connect_proxy (action, info->proxy); } break; case NODE_TYPE_TOOLITEM: /* remove the proxy if it is of the wrong type ... */ if (info->proxy && G_OBJECT_TYPE (info->proxy) != - GTK_ACTION_GET_CLASS (info->action)->toolbar_item_type) + GTK_ACTION_GET_CLASS (action)->toolbar_item_type) { + gtk_action_disconnect_proxy (info->action, info->proxy); gtk_container_remove (GTK_CONTAINER (info->proxy->parent), info->proxy); info->proxy = NULL; @@ -1813,7 +1820,7 @@ update_node (GtkUIManager *self, if (find_toolbar_position (node, &toolbar, &pos)) { - info->proxy = gtk_action_create_tool_item (info->action); + info->proxy = gtk_action_create_tool_item (action); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (info->proxy), pos); @@ -1821,7 +1828,7 @@ update_node (GtkUIManager *self, } else { - gtk_action_connect_proxy (info->action, info->proxy); + gtk_action_connect_proxy (action, info->proxy); } break; case NODE_TYPE_SEPARATOR: @@ -1869,7 +1876,11 @@ update_node (GtkUIManager *self, break; } - /* if this node has a widget, but it is the wrong type, remove it */ + if (action) + g_object_ref (action); + if (info->action) + g_object_unref (info->action); + info->action = action; } recurse_children: