Re: dynamic accelerators
- From: Mark Leisher <mleisher math nmsu edu>
- To: Wesley Smith <wesley hoke gmail com>
- Cc: "'gtk-list gnome org'" <gtk-list gnome org>
- Subject: Re: dynamic accelerators
- Date: Tue, 29 Jul 2008 13:43:21 -0600
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]