From 7e53295ae7e67c8473aca2974e519aa0a593788e Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sun, 10 Oct 2010 21:42:43 +0000 Subject: Introduced menu item accelerators. git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@183 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a --- ChangeLog | 7 +++++++ src/editor.c | 10 ++++++++++ src/gtkext/easygtk.c | 27 +++++++++++++++++++++++++++ src/gtkext/easygtk.h | 3 +++ 4 files changed, 47 insertions(+) diff --git a/ChangeLog b/ChangeLog index 53706d8..e98e720 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +10-10-10 Cyrille Bagard + + * src/editor.c: + * src/gtkext/easygtk.c: + * src/gtkext/easygtk.h: + Introduce menu item accelerators. + 10-08-19 Cyrille Bagard * src/arch/x86/instruction.c: diff --git a/src/editor.c b/src/editor.c index c446234..59401d9 100644 --- a/src/editor.c +++ b/src/editor.c @@ -228,6 +228,9 @@ GtkWidget *create_editor(void) GtkWidget *button; /* Btn. de commande inférieur */ + GtkAccelGroup *accgroup; + + result = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_set_size_request(result, 800, 600); @@ -240,6 +243,10 @@ GtkWidget *create_editor(void) ref = G_OBJECT(result); + accgroup = gtk_accel_group_new(); + gtk_window_add_accel_group(GTK_WINDOW(result), accgroup); + + vbox1 = gtk_vbox_new (FALSE, 0); gtk_widget_show (vbox1); @@ -260,6 +267,7 @@ GtkWidget *create_editor(void) gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), menubar); submenuitem = qck_create_menu_item(NULL, NULL, _("New project"), G_CALLBACK(mcb_file_new_project), result); + add_accelerator_to_menu_item(submenuitem, "N", accgroup); gtk_container_add(GTK_CONTAINER(menubar), submenuitem); submenuitem = qck_create_menu_item(NULL, NULL, _("Open project"), G_CALLBACK(mcb_file_open_project), result); @@ -291,12 +299,14 @@ GtkWidget *create_editor(void) gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), menubar); submenuitem = qck_create_radio_menu_item(ref, "textview", NULL, _("Text view"), G_CALLBACK(mcb_view_change_support), result); + add_accelerator_to_menu_item(submenuitem, "F2", accgroup); g_object_set_data(G_OBJECT(submenuitem), "kind_of_view", GUINT_TO_POINTER(BVW_BLOCK)); gtk_container_add(GTK_CONTAINER(menubar), submenuitem); rgroup = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(submenuitem)); submenuitem = qck_create_radio_menu_item(ref, "graphview", rgroup, _("Graph view"), G_CALLBACK(mcb_view_change_support), result); + add_accelerator_to_menu_item(submenuitem, "F3", accgroup); g_object_set_data(G_OBJECT(submenuitem), "kind_of_view", GUINT_TO_POINTER(BVW_GRAPH)); gtk_container_add(GTK_CONTAINER(menubar), submenuitem); diff --git a/src/gtkext/easygtk.c b/src/gtkext/easygtk.c index c14042c..15071e0 100644 --- a/src/gtkext/easygtk.c +++ b/src/gtkext/easygtk.c @@ -591,6 +591,33 @@ GtkWidget *qck_create_radio_menu_item(GObject *object, const char *name, GSList /****************************************************************************** * * +* Paramètres : item = élément d'un menu à mettre à jour. * +* accelerator = description sous forme de chaîne de caractères.* +* group = groupe d'appartenance du raccourci. * +* * +* Description : Ajoute un accélérateur à un élément de menu existant. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void add_accelerator_to_menu_item(GtkWidget *item, const char *accelerator, GtkAccelGroup *group) +{ + guint key; /* Touche concernée */ + GdkModifierType mods; /* Eventuels modificateurs */ + + gtk_accelerator_parse(accelerator, &key, &mods); + + gtk_widget_add_accelerator(item, "activate", group, + key, mods, GTK_ACCEL_VISIBLE); + +} + + +/****************************************************************************** +* * * Paramètres : - * * * * Description : Crée et enregistre un composant 'GtkSeparatorMenuItem'. * diff --git a/src/gtkext/easygtk.h b/src/gtkext/easygtk.h index 1dae530..13a415a 100644 --- a/src/gtkext/easygtk.h +++ b/src/gtkext/easygtk.h @@ -77,6 +77,9 @@ GtkWidget *qck_create_check_menu_item(GObject *, const char *, const char *, GCa /* Crée et enregistre un composant 'GtkRadioMenuItem'. */ GtkWidget *qck_create_radio_menu_item(GObject *, const char *, GSList *, const char *, GCallback, gpointer); +/* Ajoute un accélérateur à un élément de menu existant. */ +void add_accelerator_to_menu_item(GtkWidget *, const char *, GtkAccelGroup *); + /* Crée et enregistre un composant 'GtkSeparatorMenuItem'. */ GtkWidget *qck_create_menu_separator(void); -- cgit v0.11.2-87-g4458