- Published at
Following Hildon HIG on HildonAppMenu
- Authors
-
-
- Name
- Joaquim Rocha
-
In my talk in the Maemo Summit 09 I mentioned a way to follow the Hildon HIG in what comes to HildonAppMenu’s items’ availability. As written on it, the HildonAppMenu shouldn’t have insensitive items. Items that are supposed to be dimmed, should be hidden instead.
Now if you’re porting an exiting GTK+ application, these will likely use GtkActions as they are a great way not to repeat yourself while defining and sharing actions for widgets.
So, a nice way to keep using GtkActions while not showing the insensitive menu items is to hide these using a callback triggered by the “show” signal.
Here’s the callback:
static void update_menu_items_visibility_cb (GtkWidget *menu, gpointer data) { GList *items = hildon_app_menu_get_items (HILDON_APP_MENU (menu)); for (; items != NULL; items = g_list_next (items)) { GtkWidget *item = GTK_WIDGET (items->data); gboolean item_sensitive = TRUE; g_object_get (G_OBJECT (item), "sensitive", &item_sensitive, NULL); if (item_sensitive) gtk_widget_show (item); else gtk_widget_hide (item); } }
Which should be connected this way:
g_signal_connect (G_OBJECT (menu), "show", G_CALLBACK (update_menu_items_visibility_cb), NULL);
Hope it’s useful to you!