[aisleriot] Add an app menu
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aisleriot] Add an app menu
- Date: Mon, 4 Mar 2013 20:36:41 +0000 (UTC)
commit c6aa4addf24c29a99c4c2cf13186fd3db8730dbd
Author: William Jon McCann <william jon mccann gmail com>
Date: Sun Mar 3 23:09:07 2013 -0500
Add an app menu
https://bugzilla.gnome.org/show_bug.cgi?id=679715
src/application.c | 108 +++++++++++++++++++++++++++++++++++----------
src/window.c | 128 ++++++++++++++++++++++++++++++++---------------------
src/window.h | 4 ++
3 files changed, 166 insertions(+), 74 deletions(-)
---
diff --git a/src/application.c b/src/application.c
index 42a906e..b70d78f 100644
--- a/src/application.c
+++ b/src/application.c
@@ -77,7 +77,7 @@ add_main_options (AisleriotApplication *self,
}
static void
-about_activated (GSimpleAction *action,
+action_new_game (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
@@ -85,13 +85,66 @@ about_activated (GSimpleAction *action,
GtkWindow *window;
window = gtk_application_get_active_window (application);
+ aisleriot_window_new_game (AISLERIOT_WINDOW (window));
+}
+
+static void
+action_change_game (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GtkApplication *application = user_data;
+ GtkWindow *window;
+
+ window = gtk_application_get_active_window (application);
+ aisleriot_window_change_game (AISLERIOT_WINDOW (window));
+}
+
+static void
+action_fullscreen (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GtkApplication *application = user_data;
+ GtkWindow *window;
+ GdkWindowState state;
+
+ window = gtk_application_get_active_window (application);
+ state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window)));
+ if (state & GDK_WINDOW_STATE_FULLSCREEN)
+ gtk_window_unfullscreen (window);
+ else
+ gtk_window_fullscreen (window);
+}
+
+static void
+action_statistics (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GtkApplication *application = user_data;
+ GtkWindow *window;
+
+ window = gtk_application_get_active_window (application);
+ aisleriot_window_show_statistics_dialog (AISLERIOT_WINDOW (window));
+}
+
+static void
+action_about (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
+{
+ GtkApplication *application = user_data;
+ GtkWindow *window;
+
+ window = gtk_application_get_active_window (application);
aisleriot_window_show_about_dialog (AISLERIOT_WINDOW (window));
}
static void
-help_activated (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+action_help (GSimpleAction *action,
+ GVariant *parameter,
+ gpointer user_data)
{
GtkApplication *application = user_data;
GtkWindow *window;
@@ -103,9 +156,9 @@ help_activated (GSimpleAction *action,
}
static void
-aisleriot_application_quit (GSimpleAction *simple,
- GVariant *parameter,
- gpointer user_data)
+action_quit (GSimpleAction *simple,
+ GVariant *parameter,
+ gpointer user_data)
{
AisleriotApplication *self = AISLERIOT_APPLICATION (user_data);
@@ -181,7 +234,6 @@ aisleriot_application_command_line (GApplication *application,
return retval;
}
-
static void
aisleriot_application_activate (GApplication *application)
{
@@ -190,13 +242,22 @@ aisleriot_application_activate (GApplication *application)
gtk_window_present (GTK_WINDOW (self->priv->window));
}
+static GActionEntry app_entries[] = {
+ { "new-game", action_new_game, NULL, NULL, NULL },
+ { "change-game", action_change_game, NULL, NULL, NULL },
+ { "statistics", action_statistics, NULL, NULL, NULL },
+ { "fullscreen", action_fullscreen, NULL, NULL, NULL },
+ { "about", action_about, NULL, NULL, NULL },
+ { "help", action_help, NULL, NULL, NULL },
+ { "quit", action_quit, NULL, NULL, NULL },
+};
+
static void
aisleriot_application_startup (GApplication *application)
{
AisleriotApplication *self = AISLERIOT_APPLICATION (application);
GMenu *menu;
GMenu *section;
- GSimpleAction *action;
G_APPLICATION_CLASS (aisleriot_application_parent_class)->startup (application);
@@ -204,26 +265,25 @@ aisleriot_application_startup (GApplication *application)
ar_sound_enable (FALSE);
ar_stock_init ();
- action = g_simple_action_new ("help", NULL);
- g_action_map_add_action (G_ACTION_MAP (application), G_ACTION (action));
- g_signal_connect (action, "activate", G_CALLBACK (help_activated), self);
- g_object_unref (action);
+ g_action_map_add_action_entries (G_ACTION_MAP (self),
+ app_entries, G_N_ELEMENTS (app_entries),
+ self);
- action = g_simple_action_new ("about", NULL);
- g_action_map_add_action (G_ACTION_MAP (application), G_ACTION (action));
- g_signal_connect (action, "activate", G_CALLBACK (about_activated), self);
- g_object_unref (action);
+ menu = g_menu_new ();
- action = g_simple_action_new ("quit", NULL);
- g_action_map_add_action (G_ACTION_MAP (application), G_ACTION (action));
- g_signal_connect (action, "activate", G_CALLBACK (aisleriot_application_quit), self);
- g_object_unref (action);
+ section = g_menu_new ();
+ g_menu_append (section, _("New Game"), "app.new-game");
+ g_menu_append (section, _("Change Game"), "app.change-game");
+ g_menu_append_section (menu, NULL, G_MENU_MODEL (section));
- menu = g_menu_new ();
+ section = g_menu_new ();
+ g_menu_append (section, _("Statistics"), "app.statistics");
+ g_menu_append (section, _("Fullscreen"), "app.fullscreen");
+ g_menu_append_section (menu, NULL, G_MENU_MODEL (section));
section = g_menu_new ();
g_menu_append (section, _("Help"), "app.help");
- g_menu_append (section, _("About"), "app.about");
+ g_menu_append (section, _("About Aisleriot"), "app.about");
g_menu_append (section, _("Quit"), "app.quit");
g_menu_append_section (menu, NULL, G_MENU_MODEL (section));
@@ -232,6 +292,8 @@ aisleriot_application_startup (GApplication *application)
G_MENU_MODEL (menu));
gtk_application_add_accelerator (GTK_APPLICATION (application),
+ "F11", "app.fullscreen", NULL);
+ gtk_application_add_accelerator (GTK_APPLICATION (application),
"F1", "app.help", NULL);
gtk_window_set_default_icon_name ("gnome-aisleriot");
diff --git a/src/window.c b/src/window.c
index 8d89916..56b3ccc 100644
--- a/src/window.c
+++ b/src/window.c
@@ -307,11 +307,10 @@ stats_dialog_response_cb (GtkWidget *widget,
gtk_widget_destroy (widget);
}
-/* action callbacks */
+/* action methods */
-static void
-new_game_cb (GtkAction *action,
- AisleriotWindow *window)
+void
+aisleriot_window_new_game (AisleriotWindow *window)
{
AisleriotWindowPrivate *priv = window->priv;
@@ -320,35 +319,48 @@ new_game_cb (GtkAction *action,
gtk_widget_grab_focus (GTK_WIDGET (priv->board));
}
-static void
-undo_cb (GtkAction *action,
- AisleriotWindow *window)
+void
+aisleriot_window_change_game (AisleriotWindow *window)
{
AisleriotWindowPrivate *priv = window->priv;
- /* If a move is in progress, cancel it before changing the game! */
-#ifdef HAVE_CLUTTER
- aisleriot_board_abort_move (AISLERIOT_BOARD (priv->board_actor));
-#else
- aisleriot_board_abort_move (priv->board);
-#endif
+ if (priv->game_choice_dialog) {
+ gtk_window_present (GTK_WINDOW (priv->game_choice_dialog));
+ return;
+ }
- aisleriot_game_undo_move (priv->game);
+ priv->game_choice_dialog = ar_game_chooser_new (window);
+ g_signal_connect (priv->game_choice_dialog, "destroy",
+ G_CALLBACK (gtk_widget_destroyed), &priv->game_choice_dialog);
+
+ gtk_window_present (GTK_WINDOW (priv->game_choice_dialog));
}
-static void
-redo_cb (GtkAction *action,
- AisleriotWindow *window)
+void
+aisleriot_window_show_set_fullscreen (AisleriotWindow *window,
+ gboolean active)
+{
+}
+
+void
+aisleriot_window_show_statistics_dialog (AisleriotWindow *window)
{
AisleriotWindowPrivate *priv = window->priv;
-#ifdef HAVE_CLUTTER
- aisleriot_board_abort_move (AISLERIOT_BOARD (priv->board_actor));
-#else
- aisleriot_board_abort_move (priv->board);
-#endif
+ if (!priv->stats_dialog) {
+ priv->stats_dialog = aisleriot_stats_dialog_new ();
+ gtk_window_set_transient_for (GTK_WINDOW (priv->stats_dialog),
+ GTK_WINDOW (window));
- aisleriot_game_redo_move (priv->game);
+ g_signal_connect (priv->stats_dialog, "response",
+ G_CALLBACK (stats_dialog_response_cb), window);
+ g_signal_connect (priv->stats_dialog, "destroy",
+ G_CALLBACK (gtk_widget_destroyed), &priv->stats_dialog);
+ }
+
+ update_statistics_display (window);
+
+ gtk_window_present (GTK_WINDOW (priv->stats_dialog));
}
void
@@ -425,6 +437,46 @@ aisleriot_window_show_about_dialog (AisleriotWindow * window)
g_free (licence);
}
+/* action callbacks */
+
+static void
+new_game_cb (GtkAction *action,
+ AisleriotWindow *window)
+{
+ aisleriot_window_new_game (window);
+}
+
+static void
+undo_cb (GtkAction *action,
+ AisleriotWindow *window)
+{
+ AisleriotWindowPrivate *priv = window->priv;
+
+ /* If a move is in progress, cancel it before changing the game! */
+#ifdef HAVE_CLUTTER
+ aisleriot_board_abort_move (AISLERIOT_BOARD (priv->board_actor));
+#else
+ aisleriot_board_abort_move (priv->board);
+#endif
+
+ aisleriot_game_undo_move (priv->game);
+}
+
+static void
+redo_cb (GtkAction *action,
+ AisleriotWindow *window)
+{
+ AisleriotWindowPrivate *priv = window->priv;
+
+#ifdef HAVE_CLUTTER
+ aisleriot_board_abort_move (AISLERIOT_BOARD (priv->board_actor));
+#else
+ aisleriot_board_abort_move (priv->board);
+#endif
+
+ aisleriot_game_redo_move (priv->game);
+}
+
static void
help_about_cb (GtkAction *action,
AisleriotWindow *window)
@@ -445,18 +497,7 @@ static void
select_game_cb (GtkAction *action,
AisleriotWindow *window)
{
- AisleriotWindowPrivate *priv = window->priv;
-
- if (priv->game_choice_dialog) {
- gtk_window_present (GTK_WINDOW (priv->game_choice_dialog));
- return;
- }
-
- priv->game_choice_dialog = ar_game_chooser_new (window);
- g_signal_connect (priv->game_choice_dialog, "destroy",
- G_CALLBACK (gtk_widget_destroyed), &priv->game_choice_dialog);
-
- gtk_window_present (GTK_WINDOW (priv->game_choice_dialog));
+ aisleriot_window_change_game (window);
}
static void
@@ -488,22 +529,7 @@ static void
statistics_cb (GtkAction *action,
AisleriotWindow *window)
{
- AisleriotWindowPrivate *priv = window->priv;
-
- if (!priv->stats_dialog) {
- priv->stats_dialog = aisleriot_stats_dialog_new ();
- gtk_window_set_transient_for (GTK_WINDOW (priv->stats_dialog),
- GTK_WINDOW (window));
-
- g_signal_connect (priv->stats_dialog, "response",
- G_CALLBACK (stats_dialog_response_cb), window);
- g_signal_connect (priv->stats_dialog, "destroy",
- G_CALLBACK (gtk_widget_destroyed), &priv->stats_dialog);
- }
-
- update_statistics_display (window);
-
- gtk_window_present (GTK_WINDOW (priv->stats_dialog));
+ aisleriot_window_show_statistics_dialog (window);
}
static void
diff --git a/src/window.h b/src/window.h
index 5a26b2e..407ca21 100644
--- a/src/window.h
+++ b/src/window.h
@@ -61,8 +61,12 @@ void aisleriot_window_set_game_module (AisleriotWindow * window,
const char *aisleriot_window_get_game_module (AisleriotWindow *window);
+void aisleriot_window_new_game (AisleriotWindow * window);
+void aisleriot_window_change_game (AisleriotWindow * window);
+void aisleriot_window_show_statistics_dialog (AisleriotWindow * window);
void aisleriot_window_show_about_dialog (AisleriotWindow * window);
+
G_END_DECLS
#endif /* !AISLERIOT_WINDOW_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]