[gnome-games] gnomine: Use GMenu



commit 7dd58b252b83ffbdeae4f480236c5048a646f656
Author: Robert Ancell <robert ancell canonical com>
Date:   Tue Feb 7 17:21:18 2012 +1100

    gnomine: Use GMenu

 configure.ac             |    2 +-
 gnomine/data/Makefile.am |    7 +++-
 gnomine/data/gnomine.ui  |   46 ++++++++++++++++++++
 gnomine/src/gnomine.vala |  107 +++++++++++++++++++++++++++------------------
 po/POTFILES.in           |    1 +
 5 files changed, 118 insertions(+), 45 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 4504ab3..7bf705b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -146,7 +146,7 @@ for game in $gamelist; do
     *) ;;
   esac
   case $game in
-    iagno|gnotravex) need_gmenu=yes ;;
+    iagno|gnomine|gnotravex) need_gmenu=yes ;;
     *) ;;
   esac
 done
diff --git a/gnomine/data/Makefile.am b/gnomine/data/Makefile.am
index 63368b9..eaf5658 100644
--- a/gnomine/data/Makefile.am
+++ b/gnomine/data/Makefile.am
@@ -1,5 +1,8 @@
 SUBDIRS = icons
 
+uidir = $(datadir)/gnomine
+ui_DATA = gnomine.ui
+
 gsettings_in_file = org.gnome.gnomine.gschema.xml.in
 gsettings_SCHEMAS = $(gsettings_in_file:.xml.in=.xml)
 @INTLTOOL_XML_NOMERGE_RULE@
@@ -17,7 +20,9 @@ desktop_in_files = gnomine.desktop.in.in
 desktop_DATA = $(desktop_in_files:.desktop.in.in=.desktop)
 @INTLTOOL_DESKTOP_RULE@
 
-EXTRA_DIST = $(gsettings_in_file) \
+EXTRA_DIST = \
+             $(ui_DATA) \
+             $(gsettings_in_file) \
              $(desktop_in_files) \
              $(man_MANS) \
              $(pixmap_DATA)
diff --git a/gnomine/data/gnomine.ui b/gnomine/data/gnomine.ui
new file mode 100644
index 0000000..51b9aec
--- /dev/null
+++ b/gnomine/data/gnomine.ui
@@ -0,0 +1,46 @@
+<interface>
+  <menu id="gnomine-menu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_New Game</attribute>
+        <attribute name="action">app.new-game</attribute>
+        <attribute name="accel">&lt;Primary&gt;n</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Hint</attribute>
+        <attribute name="action">app.hint</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Pause</attribute>
+        <attribute name="action">app.pause</attribute>
+        <attribute name="accel">p</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Fullscreen</attribute>
+        <attribute name="action">app.fullscreen</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>
+    </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Quit</attribute>
+        <attribute name="action">app.quit</attribute>
+        <attribute name="accel">&lt;Primary&gt;q</attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
diff --git a/gnomine/src/gnomine.vala b/gnomine/src/gnomine.vala
index da7a854..1d4b6f8 100644
--- a/gnomine/src/gnomine.vala
+++ b/gnomine/src/gnomine.vala
@@ -35,6 +35,8 @@ public class GnoMine : Gtk.Application
     private Gtk.Label flag_label;
     private Gtk.SpinButton n_mines_spin;
     private GnomeGamesSupport.Clock clock;
+    private SimpleAction pause;
+    private SimpleAction hint;
     private Gtk.Action hint_action;
     private GnomeGamesSupport.FullscreenAction fullscreen_action;
     private GnomeGamesSupport.PauseAction pause_action;
@@ -42,6 +44,19 @@ public class GnoMine : Gtk.Application
     private Gtk.AspectFrame custom_game_screen;
     private bool is_new_game_screen;
 
+    private const GLib.ActionEntry[] action_entries =
+    {
+        { "new-game",      new_game_cb                                            },
+        { "hint",          hint_cb                                                },
+        { "pause",         toggle_pause_cb                                        },
+        { "fullscreen",    fullscreen_cb                                          },
+        { "scores",        scores_cb                                              },
+        { "preferences",   preferences_cb                                         },
+        { "quit",          quit_cb                                                },
+        { "help",          help_cb                                                },
+        { "about",         about_cb                                               }
+    };
+
     private const GnomeGamesSupport.ScoresCategory scorecats[] =
     {
         {"Small",  NC_("board size", "Small") },
@@ -55,6 +70,13 @@ public class GnoMine : Gtk.Application
     public GnoMine ()
     {
         Object (application_id: "org.gnome.gnomine", flags: ApplicationFlags.FLAGS_NONE);
+    }
+
+    protected override void startup ()
+    {
+        base.startup ();
+
+        Environment.set_application_name (_("Mines"));
 
         settings = new Settings ("org.gnome.gnomine");
 
@@ -62,7 +84,24 @@ public class GnoMine : Gtk.Application
 
         Gtk.Window.set_default_icon_name ("gnome-mines");
 
-        window = new Gtk.Window (Gtk.WindowType.TOPLEVEL);
+        add_action_entries (action_entries, this);
+        hint = lookup_action ("hint") as SimpleAction;
+        hint.set_enabled (false);
+        pause = lookup_action ("pause") as SimpleAction;
+        pause.set_enabled (false);
+
+        var builder = new Gtk.Builder ();
+        try
+        {
+            builder.add_from_file (Path.build_filename (DATA_DIRECTORY, "gnomine.ui"));
+        }
+        catch (Error e)
+        {
+            error ("Unable to build menus: %s", e.message);
+        }
+        set_app_menu (builder.get_object ("gnomine-menu") as MenuModel);
+
+        window = new Gtk.ApplicationWindow (this);
         window.title = _("Mines");
 
         GnomeGamesSupport.settings_bind_window_state ("/org/gnome/gnomine/", window);
@@ -89,6 +128,7 @@ public class GnoMine : Gtk.Application
         }
         hint_action = action_group.get_action ("Hint");
         hint_action.is_important = true;
+        hint_action.set_sensitive (false);
 
         action_group.get_action ("NewGame").is_important = true;
 
@@ -96,13 +136,11 @@ public class GnoMine : Gtk.Application
         action_group.add_action_with_accel (fullscreen_action, null);
 
         pause_action = new GnomeGamesSupport.PauseAction ("PauseGame");
+        pause_action.set_sensitive (false);
         pause_action.state_changed.connect (pause_cb);
         action_group.add_action_with_accel (pause_action, null);
 
         window.add_accel_group (ui_manager.get_accel_group ());
-        var menubar = (Gtk.MenuBar) ui_manager.get_widget ("/MainMenu");
-        menubar.show ();
-        main_vbox.pack_start (menubar, false, true, 0);
 
         var status_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 10);
         status_box.show ();
@@ -284,39 +322,12 @@ public class GnoMine : Gtk.Application
 
     private const Gtk.ActionEntry actions[] =
     {
-        {"GameMenu", null, N_("_Game")},
-        {"SettingsMenu", null, N_("_Settings")},
-        {"HelpMenu", null, N_("_Help")},
         {"NewGame", GnomeGamesSupport.STOCK_NEW_GAME, null, null, N_("Start a new game"), new_game_cb},
-        {"Hint", GnomeGamesSupport.STOCK_HINT, null, null, N_("Show a hint"), hint_cb},
-        {"Scores", GnomeGamesSupport.STOCK_SCORES, null, null, null, scores_cb},
-        {"Quit", Gtk.Stock.QUIT, null, null, null, quit_game_cb},
-        {"Preferences", Gtk.Stock.PREFERENCES, null, null, null, preferences_cb},
-        {"Contents", GnomeGamesSupport.STOCK_CONTENTS, null, null, null, help_cb},
-        {"About", Gtk.Stock.ABOUT, null, null, null, about_cb}
+        {"Hint", GnomeGamesSupport.STOCK_HINT, null, null, N_("Show a hint"), hint_cb}
     };
 
     private const string ui_description =
         "<ui>" +
-        "    <menubar name='MainMenu'>" +
-        "        <menu action='GameMenu'>" +
-        "            <menuitem action='NewGame'/>" +
-        "            <menuitem action='Hint'/>" +
-        "            <menuitem action='PauseGame'/>" +
-        "            <separator/>" +
-        "            <menuitem action='Scores'/>" +
-        "            <separator/>" +
-        "            <menuitem action='Quit'/>" +
-        "        </menu>" +
-        "        <menu action='SettingsMenu'>" +
-        "            <menuitem action='Fullscreen'/>" +
-        "            <menuitem action='Preferences'/>" +
-        "        </menu>" +
-        "        <menu action='HelpMenu'>" +
-        "            <menuitem action='Contents'/>" +
-        "            <menuitem action='About'/>" +
-        "        </menu>" +
-        "    </menubar>" +
         "    <toolbar name='Toolbar'>" +
         "        <toolitem action='NewGame'/>" +
         "        <toolitem action='Hint'/>" +
@@ -367,7 +378,7 @@ public class GnoMine : Gtk.Application
         return false;
     }
 
-    private void quit_game_cb ()
+    private void quit_cb ()
     {
         window.destroy ();
     }
@@ -424,6 +435,11 @@ public class GnoMine : Gtk.Application
         }
     }
 
+    private void fullscreen_cb ()
+    {
+        fullscreen_action.set_is_fullscreen (!fullscreen_action.get_is_fullscreen ());
+    }
+
     private void scores_cb ()
     {
         show_scores (0, false);
@@ -465,7 +481,9 @@ public class GnoMine : Gtk.Application
         clock.reset ();
         set_face_image (smile_face_image);
 
+        hint.set_enabled (false);
         hint_action.set_sensitive (false);
+        pause.set_enabled (false);
         pause_action.set_sensitive (false);
 
         minefield_view.paused = false;
@@ -525,7 +543,9 @@ public class GnoMine : Gtk.Application
 
         update_flag_label ();
 
+        hint.set_enabled (true);
         hint_action.set_sensitive (true);
+        pause.set_enabled (true);
         pause_action.set_sensitive (true);
 
         minefield_view.paused = false;
@@ -550,17 +570,24 @@ public class GnoMine : Gtk.Application
             show_new_game_screen ();
     }
 
-    private void pause_cb (Gtk.Action action)
+    private void toggle_pause_cb ()
+    {
+        pause_action.set_is_paused (!pause_action.get_is_paused ());
+    }
+
+    private void pause_cb ()
     {
         if (pause_action.get_is_paused ())
         {
             minefield_view.paused = true;
+            hint.set_enabled (false);
             hint_action.set_sensitive (false);
             clock.stop ();
         }
         else
         {
             minefield_view.paused = false;
+            hint.set_enabled (true);
             hint_action.set_sensitive (true);
             clock.start ();
         }
@@ -575,7 +602,9 @@ public class GnoMine : Gtk.Application
     private void explode_cb (Minefield minefield)
     {
         set_face_image (sad_face_image);
+        hint.set_enabled (false);
         hint_action.set_sensitive (false);
+        pause.set_enabled (false);
         pause_action.set_sensitive (false);
         clock.stop ();
     }
@@ -839,15 +868,7 @@ public class GnoMine : Gtk.Application
             return Posix.EXIT_FAILURE;
         }
 
-        Environment.set_application_name (_("Mines"));
-
         var app = new GnoMine ();
-        app.start ();
-
-        var result = app.run ();
-
-        Settings.sync ();
-
-        return result;
+        return app.run ();
     }
 }
diff --git a/po/POTFILES.in b/po/POTFILES.in
index cb981cc..44d76ce 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -70,6 +70,7 @@ gnome-sudoku/src/lib/simple_debug.py
 gnome-sudoku/src/lib/sudoku_maker.py
 gnome-sudoku/src/lib/sudoku.py
 gnome-sudoku/src/lib/timer.py
+[type: gettext/glade]gnotravex/data/gnotravex.ui
 gnomine/data/gnomine.desktop.in.in
 gnomine/data/org.gnome.gnomine.gschema.xml.in
 gnomine/src/gnomine.vala



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]