summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2011-11-30 12:07:25 -0500
committerRyan Lortie <desrt@desrt.ca>2011-12-19 12:51:08 -0500
commit906475860f36129f3a67f2287f7add2ea18d054b (patch)
tree236e30c04c4d64a3c138a13b80c4f32bec1e4857 /examples
parent1a97f4b9ef98df2da9ed2d5ee394c5ca5659fd7b (diff)
downloadgtk+-906475860f36129f3a67f2287f7add2ea18d054b.tar.gz
bloatpad: make "about" a window action
By making "about" a per-window action, we can pop the about dialog up on top of the correct window instead of trying to guess from the application list of windows.
Diffstat (limited to 'examples')
-rw-r--r--examples/bloatpad.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/examples/bloatpad.c b/examples/bloatpad.c
index a5ffd96764..4ba807f437 100644
--- a/examples/bloatpad.c
+++ b/examples/bloatpad.c
@@ -8,6 +8,24 @@ clicked (GtkButton *button, GtkMenu *menu)
}
static void
+show_about (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GtkWindow *window = user_data;
+
+ gtk_show_about_dialog (window,
+ "program-name", "Bloatpad",
+ "title", "About Bloatpad",
+ "comments", "Not much to say, really.",
+ NULL);
+}
+
+static GActionEntry win_entries[] = {
+ { "about", show_about }
+};
+
+static void
new_window (GApplication *app,
GFile *file)
{
@@ -15,6 +33,7 @@ new_window (GApplication *app,
GtkWidget *menu;
window = gtk_application_window_new (GTK_APPLICATION (app));
+ g_action_map_add_action_entries (G_ACTION_MAP (window), win_entries, G_N_ELEMENTS (win_entries), window);
gtk_application_window_set_show_app_menu (GTK_APPLICATION_WINDOW (window), TRUE);
gtk_window_set_title (GTK_WINDOW (window), "Bloatpad");
@@ -98,24 +117,6 @@ show_help (GSimpleAction *action,
}
static void
-show_about (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
-{
- GList *list;
- GtkWindow *win;
-
- list = gtk_application_get_windows (GTK_APPLICATION (g_application_get_default ()));
- win = list->data;
-
- gtk_show_about_dialog (win,
- "program-name", "Bloatpad",
- "title", "About Bloatpad",
- "comments", "Not much to say, really.",
- NULL);
-}
-
-static void
quit_app (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
@@ -166,9 +167,8 @@ add_action (GSimpleAction *action,
g_simple_action_set_enabled (G_SIMPLE_ACTION (remove), TRUE);
}
-static GActionEntry entries[] = {
+static GActionEntry app_entries[] = {
{ "help", show_help, NULL, NULL, NULL },
- { "about", show_about, NULL, NULL, NULL },
{ "quit", quit_app, NULL, NULL, NULL },
{ "add", add_action, NULL, NULL, NULL },
{ "remove", remove_action, NULL, NULL, NULL }
@@ -179,7 +179,7 @@ get_actions (void)
{
actions = g_simple_action_group_new ();
g_simple_action_group_add_entries (actions,
- entries, G_N_ELEMENTS (entries),
+ app_entries, G_N_ELEMENTS (app_entries),
NULL);
return G_ACTION_GROUP (actions);
@@ -190,7 +190,7 @@ get_menu (void)
{
menu = g_menu_new ();
g_menu_append (menu, "Help", "app.help");
- g_menu_append (menu, "About Bloatpad", "app.about");
+ g_menu_append (menu, "About Bloatpad", "win.about");
g_menu_append (menu, "Quit", "app.quit");
g_menu_append (menu, "Add", "app.add");