[gnome-robots] Replace menubar and toolbar with app menu
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-robots] Replace menubar and toolbar with app menu
- Date: Sat, 21 Jun 2014 14:59:58 +0000 (UTC)
commit d57741e94896f101b99a42dce5e903a72e542a65
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Fri Jun 20 18:42:49 2014 -0500
Replace menubar and toolbar with app menu
configure.ac | 2 +-
data/Makefile.am | 5 +-
data/app-menu.ui | 32 +++++
po/POTFILES.in | 2 +-
src/Makefile.am | 2 -
src/game.c | 8 +-
src/gnobots.c | 159 ++++++++++++++++++++----
src/gnobots.h | 6 +
src/menu.c | 367 ------------------------------------------------------
src/menu.h | 16 ---
10 files changed, 182 insertions(+), 417 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 912c8d8..5e19ddd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,7 +16,7 @@ dnl Dependencies
dnl ###########################################################################
GTK_REQUIRED=3.12.0
-GLIB_REQUIRED=2.28
+GLIB_REQUIRED=2.32
RSVG_REQUIRED=2.32.0
CANBERRA_GTK_REQUIRED=0.26
diff --git a/data/Makefile.am b/data/Makefile.am
index a9cbd69..ca77129 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -59,6 +59,8 @@ appdata_in_files = gnome-robots.appdata.xml.in
appdata_DATA = $(appdata_in_files:.xml.in=.xml)
@INTLTOOL_XML_RULE@
+pkgdata_DATA = app-menu.ui
+
EXTRA_DIST = $(cursor_files) \
$(appdata_in_files) \
$(pixmap_DATA) \
@@ -67,7 +69,8 @@ EXTRA_DIST = $(cursor_files) \
$(desktop_in_files) \
$(config_DATA) \
$(gsettings_SCHEMAS) \
- $(man_MANS)
+ $(man_MANS) \
+ $(pkgdata_DATA)
CLEANFILES = \
$(appdata_DATA) \
diff --git a/data/app-menu.ui b/data/app-menu.ui
new file mode 100644
index 0000000..a0df8bf
--- /dev/null
+++ b/data/app-menu.ui
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<interface>
+ <!-- interface-requires gtk+ 3.4 -->
+ <menu id="appmenu">
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">Preferences</attribute>
+ <attribute name="action">app.preferences</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Scores</attribute>
+ <attribute name="action">app.scores</attribute>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">Help</attribute>
+ <attribute name="action">app.help</attribute>
+ <attribute name="accel">F1</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">About</attribute>
+ <attribute name="action">app.about</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Quit</attribute>
+ <attribute name="action">app.quit</attribute>
+ <attribute name="accel"><Primary>q</attribute>
+ </item>
+ </section>
+ </menu>
+</interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index e5f2680..70b6068 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,6 +1,7 @@
# List of source files containing translatable strings.
# Please keep this file in alphabetical order.
[encoding: UTF-8]
+data/app-menu.ui
data/gnome-robots.appdata.xml.in
data/gnome-robots.desktop.in
data/org.gnome.robots.gschema.xml
@@ -10,6 +11,5 @@ src/games-scores-dialog.c
src/games-stock.c
src/gnobots.c
src/graphics.c
-src/menu.c
src/properties.c
src/statusbar.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 0de6d9b..d2cd248 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,8 +7,6 @@ gnome_robots_SOURCES = \
statusbar.h \
gameconfig.c \
gameconfig.h \
- menu.c \
- menu.h \
properties.c \
properties.h \
graphics.c \
diff --git a/src/game.c b/src/game.c
index 6b730a2..b568e49 100644
--- a/src/game.c
+++ b/src/game.c
@@ -255,7 +255,7 @@ kill_player (void)
endlev_counter = 0;
add_aieee_bubble (player_xpos, player_ypos);
player_animation_dead ();
- set_move_menu_sensitivity (FALSE);
+ set_move_action_sensitivity (FALSE);
}
/**
@@ -514,7 +514,7 @@ update_arena (void)
endlev_counter = 0;
add_yahoo_bubble (player_xpos, player_ypos);
reset_player_animation ();
- set_move_menu_sensitivity (FALSE);
+ set_move_action_sensitivity (FALSE);
}
}
@@ -560,7 +560,7 @@ timeout_cb (void *data)
clear_game_area ();
generate_level ();
game_state = STATE_PLAYING;
- set_move_menu_sensitivity (TRUE);
+ set_move_action_sensitivity (TRUE);
gnobots_statusbar_set (score, current_level + 1, safe_teleports,
num_robots1, num_robots2);
}
@@ -670,7 +670,7 @@ start_new_game (void)
gnobots_statusbar_set (score, current_level + 1, safe_teleports,
num_robots1, num_robots2);
- set_move_menu_sensitivity (TRUE);
+ set_move_action_sensitivity (TRUE);
}
diff --git a/src/gnobots.c b/src/gnobots.c
index 495ec66..65b6a57 100644
--- a/src/gnobots.c
+++ b/src/gnobots.c
@@ -33,7 +33,6 @@
#include "statusbar.h"
#include "gameconfig.h"
#include "graphics.h"
-#include "menu.h"
#include "sound.h"
#include "properties.h"
#include "game.h"
@@ -61,8 +60,39 @@ GSettings *settings;
/**********************************************************************/
/**********************************************************************/
+/* Function Prototypes */
+/**********************************************************************/
+/**********************************************************************/
+
+static void preferences_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
+static void scores_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
+static void help_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
+static void about_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
+static void quit_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
+static void new_game_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
+static void random_teleport_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
+static void safe_teleport_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
+static void wait_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data);
+
+/**********************************************************************/
/* File Static Variables */
/**********************************************************************/
+
+static const GActionEntry app_entries[] = {
+ { "preferences", preferences_cb, NULL, NULL, NULL },
+ { "scores", scores_cb, NULL, NULL, NULL },
+ { "help", help_cb, NULL, NULL, NULL },
+ { "about", about_cb, NULL, NULL, NULL },
+ { "quit", quit_cb, NULL, NULL, NULL },
+};
+
+static const GActionEntry win_entries[] = {
+ { "new-game", new_game_cb, NULL, NULL, NULL },
+ { "random-teleport", random_teleport_cb, NULL, NULL, NULL },
+ { "safe-teleport", safe_teleport_cb, NULL, NULL, NULL },
+ { "wait", wait_cb, NULL, NULL, NULL },
+};
+
static const GamesScoresCategory scorecats[] = {
{"classic_robots", N_("Classic robots")},
{"classic_robots-safe", N_("Classic robots with safe moves")},
@@ -83,16 +113,103 @@ static const GamesScoresCategory scorecats[] = {
/**********************************************************************/
-
-/**********************************************************************/
-/* Function Prototypes */
/**********************************************************************/
+/* Function Definitions */
/**********************************************************************/
+void
+set_move_action_sensitivity (gboolean state)
+{
+ GAction *action;
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), "random-teleport");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), state);
-/**********************************************************************/
-/* Function Definitions */
-/**********************************************************************/
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), "safe-teleport");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), state);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), "wait");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), state);
+}
+
+static void
+preferences_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data)
+{
+ show_properties_dialog ();
+}
+
+static void
+scores_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data)
+{
+ show_scores (0, FALSE);
+}
+
+static void
+help_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data)
+{
+ GError *error = NULL;
+
+ gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (window)), "help:gnome-robots", gtk_get_current_event_time
(), &error);
+ if (error)
+ g_warning ("Failed to show help: %s", error->message);
+ g_clear_error (&error);
+}
+
+static void
+about_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data)
+{
+ const gchar *authors[] = { "Mark Rae <m rae inpharmatica co uk>", NULL };
+
+ const gchar *artists[] = { "Kirstie Opstad <K Opstad ed ac uk>", NULL };
+
+ const gchar *documenters[] =
+ { "Aruna Sankaranarayanan", NULL };
+
+ gtk_show_about_dialog (GTK_WINDOW (window),
+ "name", _("Robots"),
+ "version", VERSION,
+ "copyright", "Copyright © 1998–2008 Mark Rae",
+ "license-type", GTK_LICENSE_GPL_2_0,
+ "comments", _("Based on classic BSD Robots\n\nRobots is a part of GNOME Games."),
+ "authors", authors,
+ "artists", artists,
+ "documenters", documenters,
+ "translator-credits", _("translator-credits"),
+ "logo-icon-name", "gnome-robots",
+ "website",
+ "https://wiki.gnome.org/Apps/Robots",
+ NULL);
+}
+
+static void
+quit_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data)
+{
+ quit_game ();
+}
+
+static void
+new_game_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data)
+{
+ start_new_game ();
+}
+
+static void
+random_teleport_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data)
+{
+ game_keypress (KBD_RTEL);
+}
+
+static void
+safe_teleport_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data)
+{
+ game_keypress (KBD_TELE);
+}
+
+static void
+wait_cb (GSimpleAction *action, GVariant *parameter, gpointer user_data)
+{
+ game_keypress (KBD_WAIT);
+}
static gboolean
window_configure_event_cb (GtkWidget *widget, GdkEventConfigure *event)
@@ -162,9 +279,9 @@ shutdown (GtkApplication *app, gpointer user_data)
static void
activate (GtkApplication *app, gpointer user_data)
{
- GtkWidget *errordialog;
- GtkWidget *vbox, *menubar, *toolbar, *statusbar, *gridframe;
- GtkUIManager *ui_manager;
+ GtkWidget *errordialog, *vbox, *statusbar, *gridframe;
+ GtkBuilder *builder;
+ GMenuModel *appmenu;
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), _("Robots"));
@@ -176,19 +293,15 @@ activate (GtkApplication *app, gpointer user_data)
if (g_settings_get_boolean (settings, "window-is-maximized"))
gtk_window_maximize (GTK_WINDOW (window));
- statusbar = gnobots_statusbar_new ();
- ui_manager = gtk_ui_manager_new ();
-
- games_stock_prepare_for_statusbar_tooltips (ui_manager, statusbar);
- create_game_menus (ui_manager);
- gtk_window_add_accel_group (GTK_WINDOW (window),
- gtk_ui_manager_get_accel_group (ui_manager));
+ g_action_map_add_action_entries (G_ACTION_MAP (app), app_entries, G_N_ELEMENTS (app_entries), app);
+ g_action_map_add_action_entries (G_ACTION_MAP (window), win_entries, G_N_ELEMENTS (win_entries), app);
- menubar = gtk_ui_manager_get_widget (ui_manager, "/MainMenu");
+ builder = gtk_builder_new_from_file (g_build_filename (DATA_DIRECTORY, "app-menu.ui", NULL));
+ appmenu = G_MENU_MODEL (gtk_builder_get_object (builder, "appmenu"));
+ gtk_application_set_app_menu (app, appmenu);
+ g_object_unref (builder);
- toolbar = gtk_ui_manager_get_widget (ui_manager, "/Toolbar");
- gtk_style_context_add_class (gtk_widget_get_style_context (toolbar),
- GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
+ statusbar = gnobots_statusbar_new ();
make_cursors ();
@@ -208,8 +321,6 @@ activate (GtkApplication *app, gpointer user_data)
gtk_container_add (GTK_CONTAINER (gridframe), game_area);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_box_pack_start (GTK_BOX (vbox), menubar, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), gridframe, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 0);
@@ -251,8 +362,6 @@ activate (GtkApplication *app, gpointer user_data)
exit (1);
}
- connect_toolbar_toggle (toolbar);
-
init_sound ();
init_game ();
diff --git a/src/gnobots.h b/src/gnobots.h
index e5f46b6..5afad15 100644
--- a/src/gnobots.h
+++ b/src/gnobots.h
@@ -14,5 +14,11 @@ extern GamesScores *highscores;
extern GSettings *settings;
/**********************************************************************/
+/**********************************************************************/
+/* Exported functions */
+/**********************************************************************/
+void set_move_action_sensitivity (gboolean state);
+void quit_game (void);
+/**********************************************************************/
#endif /* GNOBOTS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]