glib/gio/tests/gapplication-example-menu.c
Ryan Lortie 3821627366 GApplication: make distinction about menus
Rename g_application_set_menu to g_application_set_app_menu and make a
couple of fixups.  Clarify the documentation about exactly what this
menu is meant to be.

Add g_application_set_menubar and document that as well.
2011-12-08 18:05:14 -05:00

96 lines
1.9 KiB
C

#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_app_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;
}