[gnome-devel-docs/wip/develguide: 18/18] Add menu example to GtkApplication guide
- From: Sindhu Sundar <sindhus src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-devel-docs/wip/develguide: 18/18] Add menu example to GtkApplication guide
- Date: Fri, 2 May 2014 14:17:33 +0000 (UTC)
commit c12c0b8c784926c18ff16b3c697efbe4e0493d11
Author: David King <amigadave amigadave com>
Date: Thu May 1 19:21:06 2014 +0200
Add menu example to GtkApplication guide
devel-guide/C/examples/gtkapp-menu.c | 56 ++++++++++++++++++++++++++++++++
devel-guide/C/gtkapplication-menu.page | 46 ++++++++++++++++++++++++++
2 files changed, 102 insertions(+), 0 deletions(-)
---
diff --git a/devel-guide/C/examples/gtkapp-menu.c b/devel-guide/C/examples/gtkapp-menu.c
new file mode 100644
index 0000000..22614f3
--- /dev/null
+++ b/devel-guide/C/examples/gtkapp-menu.c
@@ -0,0 +1,56 @@
+#include <gtk/gtk.h>
+
+static void
+on_activate (GApplication *app,
+ gpointer user_data)
+{
+ GtkWidget *window;
+
+ /* Application windows are associated with a GtkApplication. */
+ window = gtk_application_window_new (GTK_APPLICATION (app));
+ gtk_widget_show (window);
+}
+
+static void
+on_hello_world (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ g_print ("%s", "Hello world!");
+}
+
+static GActionEntry actions[] = {
+ { "hello-world", on_hello_world }
+};
+
+int
+main (int argc, char **argv)
+{
+ GApplication *app;
+ GtkWidget *window;
+ const gchar * const accels[] = { "<Primary>H", NULL }:
+ GMenu *menu;
+ int result;
+
+ /* com.example.MyApp is a unique application identifier. */
+ app = gtk_application_new ("com.example.MyApp", G_APPLICATION_FLAGS_NONE);
+
+ /* Add the actions to the application. */
+ g_action_map_add_action_entries (G_ACTION_MAP (app), actions,
+ G_N_ELEMENTS (actions), app);
+
+ gtk_application_set_accels_for_action (app, "app.hello-world", accels);
+
+ /* Add an item to the application menu. */
+ menu = g_menu_new ();
+ g_menu_append (menu, "Hello world!", "app.hello-world");
+ gtk_application_set_app_menu (app, menu);
+
+ g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL);
+
+ result = g_application_run (app, argc, argv);
+
+ g_object_unref (app);
+
+ return result;
+}
diff --git a/devel-guide/C/gtkapplication-menu.page b/devel-guide/C/gtkapplication-menu.page
new file mode 100644
index 0000000..7039238
--- /dev/null
+++ b/devel-guide/C/gtkapplication-menu.page
@@ -0,0 +1,46 @@
+<page xmlns="http://projectmallard.org/1.0/"
+ xmlns:its="http://www.w3.org/2005/11/its"
+ type="topic" style="task"
+ id="gtkapplication-menu">
+
+ <info>
+ <link type="next" xref="gtkapplication-"/>
+ <revision pkgversion="3.14" date="2014-05-01" status="draft"/>
+
+ <credit type="author">
+ <name>David King</name>
+ <email its:translate="no">davidk gnome org</email>
+ <years>2014</years>
+ </credit>
+
+ <include href="legal.xml" xmlns="http://www.w3.org/2001/XInclude"/>
+
+ </info>
+
+ <title>Application menus</title>
+
+ <links type="series" style="floatend">
+ <title>GtkApplication</title>
+ </links>
+
+ <p>Add an application-wide menu.</p>
+
+ <!-- Link to HowDoI/ApplicationMenu? -->
+ <p>GNOME Shell shows menus from applications in the top bar. Using this
+ technique, you can improve consistency with other GNOME applications.</p>
+
+ <p>A simple GtkApplication with an app menu is as follows:</p>
+ <example>
+ <listing>
+ <title><file>gtkapp-menu.c</file></title>
+<code mime="text/x-csrc">
+<include href="examples/gtkapp-menu.c" parse="text" xmlns="http://www.w3.org/2001/XInclude"/>
+</code>
+ </listing>
+ </example>
+
+ <p>The example creates an application with a window. When the user presses
+ <keyseq><key>Ctrl</key><key>H</key></keyseq>, or selects "Hello world!" from
+ the app menu, "Hello world!" is printed to the terminal.</p>
+
+</page>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]