Wednesday, June 16, 2010

How to change hildon context menu content depending on context

Mainly as a reminder to myself, but if you need to change the content of a context menu set with gtk_widget_tap_and_hold_setup() connect the "show" signal and do you show/hide in the signal handler.

Create your menu, connect signal and setup tap-and-hold:
menu=GTK_MENU(hildon_gtk_menu_new());
g_signal_connect(G_OBJECT (menu), "show", G_CALLBACK(menu_items_visibility_cb), NULL);
gtk_widget_tap_and_hold_setup(widget, menu, NULL, 0);

Then in your handler, check what you need and hide/show menu items:
static void
menu_items_visibility_cb(GtkWidget *menu, gpointer data)
{
if (foo) gtk_widget_show(menu_item_foo); else gtk_widget_hide(menu_item_foo);
}

No comments: