Re: dynamic accelerators

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In one of my programs, I keep the accelerator group I created at the beginning. When I need a menu item with an accelerator, I call the make_accel_menu_item() function below like:

  mitem = make_accel_menu_item(menu, "_New", "<Control>N", editor->ag);

But you have to remember to set the accelerator group on the top-most parent window at some point early in the program like:

    gtk_window_add_accel_group(GTK_WINDOW(editor->shell), editor->ag);

where "editor->shell" in my case is a TOPLEVEL window.

static GtkWidget *
make_accel_menu_item(GtkWidget *menu, const gchar *text,
                     const gchar *accel, GtkAccelGroup *ag)
{
    GtkWidget *mi;
    guint key;
    GdkModifierType mods;

    mi = gtk_menu_item_new_with_mnemonic(text);

    gtk_accelerator_parse(accel, &key, &mods);
    gtk_widget_add_accelerator(mi, "activate", ag, key, mods,
                               GTK_ACCEL_VISIBLE|GTK_ACCEL_LOCKED);
    gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);

    return mi;
}


--
Mark Leisher
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux