[gnome-devel-docs/wip/develguide-gtkapp: 5/6] Add actions example to GtkApplication guide
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-devel-docs/wip/develguide-gtkapp: 5/6] Add actions example to GtkApplication guide
- Date: Thu, 1 May 2014 18:14:09 +0000 (UTC)
commit ce553cc542a07b2b81664134238e0de209cef164
Author: David King <amigadave amigadave com>
Date: Thu May 1 17:59:53 2014 +0200
Add actions example to GtkApplication guide
devel-guide/C/examples/gtkapp-actions.c | 50 +++++++++++++++++++++++++++++
devel-guide/C/gtkapplication-actions.page | 49 ++++++++++++++++++++++++++++
devel-guide/Makefile.am | 1 +
3 files changed, 100 insertions(+), 0 deletions(-)
---
diff --git a/devel-guide/C/examples/gtkapp-actions.c b/devel-guide/C/examples/gtkapp-actions.c
new file mode 100644
index 0000000..dce1cdb
--- /dev/null
+++ b/devel-guide/C/examples/gtkapp-actions.c
@@ -0,0 +1,50 @@
+#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 }:
+ 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);
+
+ 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-actions.page b/devel-guide/C/gtkapplication-actions.page
new file mode 100644
index 0000000..82bd0a0
--- /dev/null
+++ b/devel-guide/C/gtkapplication-actions.page
@@ -0,0 +1,49 @@
+<page xmlns="http://projectmallard.org/1.0/"
+ xmlns:its="http://www.w3.org/2005/11/its"
+ type="topic" style="task"
+ id="gtkapplication-actions">
+
+ <info>
+ <link type="next" xref="gtkapplication-menu"/>
+ <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>User actions</title>
+
+ <links type="series" style="floatend">
+ <title>GtkApplication</title>
+ </links>
+
+ <p>Handle user actions.</p>
+
+ <!-- Link to HowDoI/GAction? -->
+ <p>When discussing GTK+, an action is a user-interesting action, such as
+ "open file" or "show preferences", which could be triggered by clicking a
+ button or selecting a menu item.</p>
+
+ <p>A simple GtkApplication using GAction is as follows:</p>
+ <example>
+ <listing>
+ <title><file>gtkapp-actions.c</file></title>
+<code mime="text/x-csrc">
+<include href="examples/gtkapp-actions.c" parse="text" xmlns="http://www.w3.org/2001/XInclude"/>
+</code>
+ </listing>
+ </example>
+
+ <p>The example creates an application, adds an application window to it,
+ shows the window and runs the application. The application terminates as soon
+ as the last window has been closed. When the user presses
+ <keyseq><key>Ctrl</key><key>H</key></keyseq>, "Hello world!" is printed to
+ the terminal.</p>
+
+</page>
diff --git a/devel-guide/Makefile.am b/devel-guide/Makefile.am
index 5308ea7..1c8075b 100644
--- a/devel-guide/Makefile.am
+++ b/devel-guide/Makefile.am
@@ -29,6 +29,7 @@ HELP_FILES = \
legal.xml
HELP_EXTRA = \
+ examples/gtkapp-actions.c \
examples/gtkapp-helloworld.c \
examples/gtkapp-window.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]