[gtk+] widget-factory: Show accelerators



commit 2cb1052987621c596ebfa55475ca38e66a6d346e
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jul 20 00:40:11 2014 -0400

    widget-factory: Show accelerators
    
    We set this up manually here. This could be automated by
    constructing the menubar from a menu model.

 demos/widget-factory/widget-factory.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
---
diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c
index e666f08..d992402 100644
--- a/demos/widget-factory/widget-factory.c
+++ b/demos/widget-factory/widget-factory.c
@@ -547,6 +547,27 @@ row_activated (GtkListBox *box, GtkListBoxRow *row)
 }
 
 static void
+set_accel (GtkApplication *app, GtkWidget *widget)
+{
+  GtkWidget *accel_label;
+  const gchar *action;
+  gchar **accels;
+  guint key;
+  GdkModifierType mods;
+
+  accel_label = gtk_bin_get_child (GTK_BIN (widget));
+  g_assert (GTK_IS_ACCEL_LABEL (accel_label));
+
+  action = gtk_actionable_get_action_name (GTK_ACTIONABLE (widget));
+  accels = gtk_application_get_accels_for_action (app, action);
+
+  gtk_accelerator_parse (accels[0], &key, &mods);
+  gtk_accel_label_set_accel (GTK_ACCEL_LABEL (accel_label), key, mods);
+
+  g_strfreev (accels);
+}
+
+static void
 activate (GApplication *app)
 {
   GtkBuilder *builder;
@@ -658,6 +679,12 @@ activate (GApplication *app)
 
   populate_colors ((GtkWidget *)gtk_builder_get_object (builder, "munsell"));
 
+  set_accel (GTK_APPLICATION (app), GTK_WIDGET (gtk_builder_get_object (builder, "quitmenuitem")));
+  set_accel (GTK_APPLICATION (app), GTK_WIDGET (gtk_builder_get_object (builder, "deletemenuitem")));
+  set_accel (GTK_APPLICATION (app), GTK_WIDGET (gtk_builder_get_object (builder, "searchmenuitem")));
+  set_accel (GTK_APPLICATION (app), GTK_WIDGET (gtk_builder_get_object (builder, "darkmenuitem")));
+  set_accel (GTK_APPLICATION (app), GTK_WIDGET (gtk_builder_get_object (builder, "aboutmenuitem")));
+
   gtk_widget_show_all (GTK_WIDGET (window));
 
   g_object_unref (builder);


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