[gtk+] example: Port to gtk_application_set_accels_for_action



commit b718b95aabf5484f7ea5f1679706a50f67bd0271
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Apr 17 11:36:33 2014 -0700

    example: Port to gtk_application_set_accels_for_action
    
    Instead of hardcoding an accelerator in the ui file, use
    gtk_application_set_accels_for_action.

 docs/reference/gtk/getting_started.xml |    6 +++++-
 examples/application10/app-menu.ui     |    1 -
 examples/application10/exampleapp.c    |    4 ++++
 examples/application4/app-menu.ui      |    1 -
 examples/application4/exampleapp.c     |    4 ++++
 examples/application5/app-menu.ui      |    1 -
 examples/application5/exampleapp.c     |    4 ++++
 examples/application6/app-menu.ui      |    1 -
 examples/application6/exampleapp.c     |    4 ++++
 examples/application7/app-menu.ui      |    1 -
 examples/application7/exampleapp.c     |    4 ++++
 examples/application8/app-menu.ui      |    1 -
 examples/application8/exampleapp.c     |    4 ++++
 examples/application9/app-menu.ui      |    1 -
 examples/application9/exampleapp.c     |    4 ++++
 15 files changed, 33 insertions(+), 8 deletions(-)
---
diff --git a/docs/reference/gtk/getting_started.xml b/docs/reference/gtk/getting_started.xml
index f271e66..5ac4ca5 100644
--- a/docs/reference/gtk/getting_started.xml
+++ b/docs/reference/gtk/getting_started.xml
@@ -605,12 +605,16 @@ example_app_startup (GApplication *app)
 {
   GtkBuilder *builder;
   GMenuModel *app_menu;
+  const gchar *quit_accels[2] = { "&lt;Ctrl&gt;Q", NULL };
 
   G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
 
   g_action_map_add_action_entries (G_ACTION_MAP (app),
                                    app_entries, G_N_ELEMENTS (app_entries),
                                    app);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+                                         "app.quit",
+                                         quit_accels);
 
   builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
   app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
@@ -633,7 +637,7 @@ example_app_class_init (ExampleAppClass *class)
       <para>Our preferences menu item does not do anything yet,
       but the Quit menu item is fully functional. Note that it
       can also be activated by the usual Ctrl-Q shortcut. The
-      shortcut was specified in the ui file.
+      shortcut was added with gtk_application_set_accels_for_action().
       </para>
 
       <para>The application menu looks like this:</para>
diff --git a/examples/application10/app-menu.ui b/examples/application10/app-menu.ui
index b0eddb6..e1e131c 100644
--- a/examples/application10/app-menu.ui
+++ b/examples/application10/app-menu.ui
@@ -12,7 +12,6 @@
       <item>
         <attribute name="label" translatable="yes">_Quit</attribute>
         <attribute name="action">app.quit</attribute>
-        <attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
       </item>
     </section>
   </menu>
diff --git a/examples/application10/exampleapp.c b/examples/application10/exampleapp.c
index 1bc6ce8..66e8579 100644
--- a/examples/application10/exampleapp.c
+++ b/examples/application10/exampleapp.c
@@ -53,12 +53,16 @@ example_app_startup (GApplication *app)
 {
   GtkBuilder *builder;
   GMenuModel *app_menu;
+  const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
 
   G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
 
   g_action_map_add_action_entries (G_ACTION_MAP (app),
                                    app_entries, G_N_ELEMENTS (app_entries),
                                    app);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+                                         "app.quit",
+                                         quit_accels);
 
   builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
   app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
diff --git a/examples/application4/app-menu.ui b/examples/application4/app-menu.ui
index b0eddb6..e1e131c 100644
--- a/examples/application4/app-menu.ui
+++ b/examples/application4/app-menu.ui
@@ -12,7 +12,6 @@
       <item>
         <attribute name="label" translatable="yes">_Quit</attribute>
         <attribute name="action">app.quit</attribute>
-        <attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
       </item>
     </section>
   </menu>
diff --git a/examples/application4/exampleapp.c b/examples/application4/exampleapp.c
index ea24557..e83f139 100644
--- a/examples/application4/exampleapp.c
+++ b/examples/application4/exampleapp.c
@@ -46,12 +46,16 @@ example_app_startup (GApplication *app)
 {
   GtkBuilder *builder;
   GMenuModel *app_menu;
+  const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
 
   G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
 
   g_action_map_add_action_entries (G_ACTION_MAP (app),
                                    app_entries, G_N_ELEMENTS (app_entries),
                                    app);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+                                         "app.quit",
+                                         quit_accels);
 
   builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
   app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
diff --git a/examples/application5/app-menu.ui b/examples/application5/app-menu.ui
index b0eddb6..e1e131c 100644
--- a/examples/application5/app-menu.ui
+++ b/examples/application5/app-menu.ui
@@ -12,7 +12,6 @@
       <item>
         <attribute name="label" translatable="yes">_Quit</attribute>
         <attribute name="action">app.quit</attribute>
-        <attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
       </item>
     </section>
   </menu>
diff --git a/examples/application5/exampleapp.c b/examples/application5/exampleapp.c
index ea24557..e83f139 100644
--- a/examples/application5/exampleapp.c
+++ b/examples/application5/exampleapp.c
@@ -46,12 +46,16 @@ example_app_startup (GApplication *app)
 {
   GtkBuilder *builder;
   GMenuModel *app_menu;
+  const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
 
   G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
 
   g_action_map_add_action_entries (G_ACTION_MAP (app),
                                    app_entries, G_N_ELEMENTS (app_entries),
                                    app);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+                                         "app.quit",
+                                         quit_accels);
 
   builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
   app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
diff --git a/examples/application6/app-menu.ui b/examples/application6/app-menu.ui
index b0eddb6..e1e131c 100644
--- a/examples/application6/app-menu.ui
+++ b/examples/application6/app-menu.ui
@@ -12,7 +12,6 @@
       <item>
         <attribute name="label" translatable="yes">_Quit</attribute>
         <attribute name="action">app.quit</attribute>
-        <attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
       </item>
     </section>
   </menu>
diff --git a/examples/application6/exampleapp.c b/examples/application6/exampleapp.c
index 36ef152..d0e0774 100644
--- a/examples/application6/exampleapp.c
+++ b/examples/application6/exampleapp.c
@@ -53,12 +53,16 @@ example_app_startup (GApplication *app)
 {
   GtkBuilder *builder;
   GMenuModel *app_menu;
+  const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
 
   G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
 
   g_action_map_add_action_entries (G_ACTION_MAP (app),
                                    app_entries, G_N_ELEMENTS (app_entries),
                                    app);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+                                         "app.quit",
+                                         quit_accels);
 
   builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
   app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
diff --git a/examples/application7/app-menu.ui b/examples/application7/app-menu.ui
index b0eddb6..e1e131c 100644
--- a/examples/application7/app-menu.ui
+++ b/examples/application7/app-menu.ui
@@ -12,7 +12,6 @@
       <item>
         <attribute name="label" translatable="yes">_Quit</attribute>
         <attribute name="action">app.quit</attribute>
-        <attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
       </item>
     </section>
   </menu>
diff --git a/examples/application7/exampleapp.c b/examples/application7/exampleapp.c
index 1bc6ce8..66e8579 100644
--- a/examples/application7/exampleapp.c
+++ b/examples/application7/exampleapp.c
@@ -53,12 +53,16 @@ example_app_startup (GApplication *app)
 {
   GtkBuilder *builder;
   GMenuModel *app_menu;
+  const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
 
   G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
 
   g_action_map_add_action_entries (G_ACTION_MAP (app),
                                    app_entries, G_N_ELEMENTS (app_entries),
                                    app);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+                                         "app.quit",
+                                         quit_accels);
 
   builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
   app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
diff --git a/examples/application8/app-menu.ui b/examples/application8/app-menu.ui
index b0eddb6..e1e131c 100644
--- a/examples/application8/app-menu.ui
+++ b/examples/application8/app-menu.ui
@@ -12,7 +12,6 @@
       <item>
         <attribute name="label" translatable="yes">_Quit</attribute>
         <attribute name="action">app.quit</attribute>
-        <attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
       </item>
     </section>
   </menu>
diff --git a/examples/application8/exampleapp.c b/examples/application8/exampleapp.c
index 1bc6ce8..66e8579 100644
--- a/examples/application8/exampleapp.c
+++ b/examples/application8/exampleapp.c
@@ -53,12 +53,16 @@ example_app_startup (GApplication *app)
 {
   GtkBuilder *builder;
   GMenuModel *app_menu;
+  const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
 
   G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
 
   g_action_map_add_action_entries (G_ACTION_MAP (app),
                                    app_entries, G_N_ELEMENTS (app_entries),
                                    app);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+                                         "app.quit",
+                                         quit_accels);
 
   builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
   app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
diff --git a/examples/application9/app-menu.ui b/examples/application9/app-menu.ui
index b0eddb6..e1e131c 100644
--- a/examples/application9/app-menu.ui
+++ b/examples/application9/app-menu.ui
@@ -12,7 +12,6 @@
       <item>
         <attribute name="label" translatable="yes">_Quit</attribute>
         <attribute name="action">app.quit</attribute>
-        <attribute name="accel"><![CDATA[<Ctrl>Q]]></attribute>
       </item>
     </section>
   </menu>
diff --git a/examples/application9/exampleapp.c b/examples/application9/exampleapp.c
index 1bc6ce8..66e8579 100644
--- a/examples/application9/exampleapp.c
+++ b/examples/application9/exampleapp.c
@@ -53,12 +53,16 @@ example_app_startup (GApplication *app)
 {
   GtkBuilder *builder;
   GMenuModel *app_menu;
+  const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
 
   G_APPLICATION_CLASS (example_app_parent_class)->startup (app);
 
   g_action_map_add_action_entries (G_ACTION_MAP (app),
                                    app_entries, G_N_ELEMENTS (app_entries),
                                    app);
+  gtk_application_set_accels_for_action (GTK_APPLICATION (app),
+                                         "app.quit",
+                                         quit_accels);
 
   builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/app-menu.ui");
   app_menu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));


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