mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-16 20:38:48 +02:00
GApplication: Add a menu example to the docs
This commit is contained in:
parent
8d96e68eeb
commit
41c19c7df8
@ -146,6 +146,14 @@
|
|||||||
* </xi:include>
|
* </xi:include>
|
||||||
* </programlisting>
|
* </programlisting>
|
||||||
* </example>
|
* </example>
|
||||||
|
*
|
||||||
|
* <example id="gapplication-example-menu"><title>A GApplication with menus</title>
|
||||||
|
* <programlisting>
|
||||||
|
* <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../gio/tests/gapplication-example-menu.c">
|
||||||
|
* <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
|
||||||
|
* </xi:include>
|
||||||
|
* </programlisting>
|
||||||
|
* </example>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct _GApplicationPrivate
|
struct _GApplicationPrivate
|
||||||
|
@ -111,6 +111,7 @@ SAMPLE_PROGS = \
|
|||||||
gapplication-example-cmdline2 \
|
gapplication-example-cmdline2 \
|
||||||
gapplication-example-cmdline3 \
|
gapplication-example-cmdline3 \
|
||||||
gapplication-example-actions \
|
gapplication-example-actions \
|
||||||
|
gapplication-example-menu \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
|
||||||
@ -427,6 +428,9 @@ gapplication_example_cmdline3_LDADD = $(progs_ldadd)
|
|||||||
gapplication_example_actions_SOURCES = gapplication-example-actions.c
|
gapplication_example_actions_SOURCES = gapplication-example-actions.c
|
||||||
gapplication_example_actions_LDADD = $(progs_ldadd)
|
gapplication_example_actions_LDADD = $(progs_ldadd)
|
||||||
|
|
||||||
|
gapplication_example_menu_SOURCES = gapplication-example-menu.c
|
||||||
|
gapplication_example_menu_LDADD = $(progs_ldadd)
|
||||||
|
|
||||||
gmenumodel_LDADD = $(progs_ldadd)
|
gmenumodel_LDADD = $(progs_ldadd)
|
||||||
|
|
||||||
schema_tests = \
|
schema_tests = \
|
||||||
|
95
gio/tests/gapplication-example-menu.c
Normal file
95
gio/tests/gapplication-example-menu.c
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
#include <gio/gio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static void
|
||||||
|
activate (GApplication *application)
|
||||||
|
{
|
||||||
|
g_application_hold (application);
|
||||||
|
g_print ("activated\n");
|
||||||
|
g_application_release (application);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
show_help (GSimpleAction *action,
|
||||||
|
GVariant *parameter,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
g_print ("Want help, eh ?!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
show_about (GSimpleAction *action,
|
||||||
|
GVariant *parameter,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
g_print ("Not much to say, really.\nJust a stupid example\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
quit_app (GSimpleAction *action,
|
||||||
|
GVariant *parameter,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
g_print ("Quitting...\n");
|
||||||
|
g_application_release (g_application_get_default ());
|
||||||
|
}
|
||||||
|
|
||||||
|
static GActionEntry entries[] = {
|
||||||
|
{ "help", show_help, NULL, NULL, NULL },
|
||||||
|
{ "about", show_about, NULL, NULL, NULL },
|
||||||
|
{ "quit", quit_app, NULL, NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
add_actions (GApplication *app)
|
||||||
|
{
|
||||||
|
GSimpleActionGroup *actions;
|
||||||
|
|
||||||
|
actions = g_simple_action_group_new ();
|
||||||
|
|
||||||
|
g_simple_action_group_add_entries (actions,
|
||||||
|
entries, G_N_ELEMENTS (entries),
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
g_application_set_action_group (app, G_ACTION_GROUP (actions));
|
||||||
|
|
||||||
|
g_object_unref (actions);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
add_menu (GApplication *app)
|
||||||
|
{
|
||||||
|
GMenu *menu;
|
||||||
|
|
||||||
|
menu = g_menu_new ();
|
||||||
|
|
||||||
|
g_menu_append (menu, "Help", "help");
|
||||||
|
g_menu_append (menu, "About Example", "about");
|
||||||
|
g_menu_append (menu, "Quit", "quit");
|
||||||
|
|
||||||
|
g_application_set_menu (app, G_MENU_MODEL (menu));
|
||||||
|
|
||||||
|
g_object_unref (menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
GApplication *app;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
app = g_application_new ("org.gtk.TestApplication", 0);
|
||||||
|
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
||||||
|
|
||||||
|
add_actions (app);
|
||||||
|
add_menu (app);
|
||||||
|
|
||||||
|
g_application_hold (app);
|
||||||
|
|
||||||
|
status = g_application_run (app, argc, argv);
|
||||||
|
|
||||||
|
g_object_unref (app);
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user