Following Hildon HIG on HildonAppMenu

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!

2009-10-28 19:49 UTC with score 1
VN:F [1.7.0_948]
Rating: 0 (from 0 votes)
  • Share/Bookmark

Related Posts

  1. PySide tutorial: model view programming, part two
  2. Updates on Hildon and Vagalume
  3. Video of Maemo summit talk
  4. Extras-testing Marathon – Next Saturday (Oct 31)
  5. Maemo Summit 2009 video

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

Spam Protection by WP-SpamFree