Harden katze_array_action_generate_menu

Add assertions and increase consistency.
This commit is contained in:
Christian Dywan 2012-02-23 00:46:59 +01:00
parent bcc6711f27
commit 403d17400b

View file

@ -358,6 +358,13 @@ katze_array_action_generate_menu (KatzeArrayAction* array_action,
GtkWidget* image; GtkWidget* image;
GtkWidget* submenu; GtkWidget* submenu;
g_return_if_fail (KATZE_IS_ARRAY_ACTION (array_action));
g_return_if_fail (KATZE_IS_ITEM (array));
g_return_if_fail (GTK_IS_MENU_SHELL (menu));
g_return_if_fail (GTK_IS_TOOL_ITEM (proxy)
|| GTK_IS_MENU_ITEM (proxy)
|| GTK_IS_WINDOW (proxy));
if (!KATZE_IS_ARRAY (array)) if (!KATZE_IS_ARRAY (array))
return; return;
@ -393,8 +400,13 @@ katze_array_action_generate_menu (KatzeArrayAction* array_action,
{ {
submenu = gtk_menu_new (); submenu = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu); gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu);
/* Make sure menu appears to contain items */
gtk_menu_shell_append (GTK_MENU_SHELL (submenu),
gtk_separator_menu_item_new ());
g_signal_connect (menuitem, "select", g_signal_connect (menuitem, "select",
G_CALLBACK (katze_array_action_menu_item_select_cb), array_action); G_CALLBACK (katze_array_action_menu_item_select_cb), array_action);
g_signal_connect (menuitem, "activate",
G_CALLBACK (katze_array_action_menu_item_select_cb), array_action);
} }
else else
{ {
@ -463,14 +475,14 @@ katze_array_action_proxy_clicked_cb (GtkWidget* proxy,
KatzeArray* array; KatzeArray* array;
gboolean handled = FALSE; gboolean handled = FALSE;
array = (KatzeArray*)g_object_get_data (G_OBJECT (proxy), "KatzeItem");
if (GTK_IS_MENU_ITEM (proxy)) if (GTK_IS_MENU_ITEM (proxy))
{ {
g_object_set_data (G_OBJECT (proxy), "KatzeItem", array_action->array);
if (katze_array_action_menu_item_need_update (array_action, proxy)) if (katze_array_action_menu_item_need_update (array_action, proxy))
{ {
g_signal_emit (array_action, signals[POPULATE_FOLDER], 0, g_signal_emit (array_action, signals[POPULATE_FOLDER], 0,
gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy)), gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy)),
array_action->array, &handled); array, &handled);
if (!handled) if (!handled)
g_signal_emit (array_action, signals[POPULATE_POPUP], 0, g_signal_emit (array_action, signals[POPULATE_POPUP], 0,
gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy))); gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy)));
@ -478,7 +490,6 @@ katze_array_action_proxy_clicked_cb (GtkWidget* proxy,
return; return;
} }
array = (KatzeArray*)g_object_get_data (G_OBJECT (proxy), "KatzeArray");
if (KATZE_IS_ITEM (array) && katze_item_get_uri ((KatzeItem*)array)) if (KATZE_IS_ITEM (array) && katze_item_get_uri ((KatzeItem*)array))
{ {
katze_array_action_activate_item (array_action, KATZE_ITEM (array), 1); katze_array_action_activate_item (array_action, KATZE_ITEM (array), 1);
@ -720,6 +731,9 @@ static void
katze_array_action_connect_proxy (GtkAction* action, katze_array_action_connect_proxy (GtkAction* action,
GtkWidget* proxy) GtkWidget* proxy)
{ {
KatzeArrayAction* array_action = KATZE_ARRAY_ACTION (action);
g_object_set_data (G_OBJECT (proxy), "KatzeItem", array_action->array);
GTK_ACTION_CLASS (katze_array_action_parent_class)->connect_proxy ( GTK_ACTION_CLASS (katze_array_action_parent_class)->connect_proxy (
action, proxy); action, proxy);