[gnome-games] mahjongg: Use GMenu



commit 347d890dc8455b14f3cbfdd7f2e6f75dee7d4ef2
Author: Thomas Hindoe Paaboel Andersen <phomes gmail com>
Date:   Mon May 14 23:26:54 2012 +0200

    mahjongg: Use GMenu

 mahjongg/src/mahjongg.vala |  112 +++++++++++++++++--------------------------
 1 files changed, 44 insertions(+), 68 deletions(-)
---
diff --git a/mahjongg/src/mahjongg.vala b/mahjongg/src/mahjongg.vala
index ed86079..ad079f5 100644
--- a/mahjongg/src/mahjongg.vala
+++ b/mahjongg/src/mahjongg.vala
@@ -26,6 +26,8 @@ public class Mahjongg : Gtk.Application
     public Mahjongg ()
     {
         Object (application_id: "org.gnome.mahjongg", flags: ApplicationFlags.FLAGS_NONE);
+
+        add_action_entries (action_entries, this);
     }
 
     protected override void startup ()
@@ -77,7 +79,23 @@ public class Mahjongg : Gtk.Application
 
         create_menus (ui_manager);
         window.add_accel_group (ui_manager.get_accel_group ());
-        var box = ui_manager.get_widget ("/MainMenu");
+
+        /* Create the menus */
+        var menu = new Menu ();
+        var section = new Menu ();
+        menu.append_section (null, section);
+        section.append (_("_New Game"), "app.new-game");
+        section.append (_("_Restart Game"), "app.restart-game");
+        section.append (_("_Scores"), "app.scores");
+        section.append (_("_Preferences"), "app.preferences");
+        section = new Menu ();
+        menu.append_section (null, section);
+        section.append (_("_Help"), "app.help");
+        section.append (_("_About"), "app.about");
+        section = new Menu ();
+        menu.append_section (null, section);
+        section.append (_("_Quit"), "app.quit");
+        set_app_menu (menu);
 
         game_view = new GameView ();
         game_view.button_press_event.connect (view_button_press_event);        
@@ -96,7 +114,6 @@ public class Mahjongg : Gtk.Application
 
         toolbar.insert (status_item, -1);
 
-        vbox.pack_start (box, false, false, 0);
         vbox.pack_start (toolbar, false, false, 0);
         vbox.pack_start (game_view, true, true, 0);
 
@@ -112,7 +129,6 @@ public class Mahjongg : Gtk.Application
         leave_fullscreen_action.set_visible_policy (GnomeGamesSupport.VisiblePolicy.ON_FULLSCREEN);
         conf_value_changed_cb (settings, "tileset");
         conf_value_changed_cb (settings, "bgcolour");
-        conf_value_changed_cb (settings, "show-toolbar");
     }
 
     public override void activate ()
@@ -162,10 +178,6 @@ public class Mahjongg : Gtk.Application
                 game_view.theme = load_theme_texture ("postmodern.svg", true);
             }
         }
-        else if (key == "show-toolbar")
-        {
-            toolbar.visible = settings.get_boolean ("show-toolbar");
-        }
         else if (key == "bgcolour")
         {
             game_view.set_background (settings.get_string ("bgcolour"));
@@ -221,12 +233,6 @@ public class Mahjongg : Gtk.Application
         return false;
     }
 
-    private void show_toolbar_cb (Gtk.Action action)
-    {
-        var toggle_action = (Gtk.ToggleAction) action;
-        settings.set_boolean ("show-toolbar", toggle_action.active);
-    }
-
     private void background_changed_cb (Gtk.ColorButton widget)
     {
         Gdk.RGBA colour;
@@ -308,7 +314,7 @@ public class Mahjongg : Gtk.Application
         }
     }
 
-    private void properties_cb ()
+    private void preferences_cb ()
     {
         if (preferences_dialog != null)
         {
@@ -557,7 +563,7 @@ public class Mahjongg : Gtk.Application
         update_ui ();
     }
 
-    private void scores_cb (Gtk.Action action)
+    private void scores_cb ()
     {
         var map_scores_dialog = new GnomeGamesSupport.ScoresDialog (window, highscores, _("Mahjongg Scores"));
         map_scores_dialog.set_category_description (_("Map:"));
@@ -565,12 +571,12 @@ public class Mahjongg : Gtk.Application
         map_scores_dialog.destroy ();
     }
 
-    private void new_game_cb (Gtk.Action action)
+    private void new_game_cb ()
     {
         new_game ();
     }
 
-    private void restart_game_cb (Gtk.Action action)
+    private void restart_game_cb ()
     {
         game_view.game.reset ();
         game_view.queue_draw ();
@@ -581,7 +587,7 @@ public class Mahjongg : Gtk.Application
         window.destroy ();
     }
 
-    private void redo_cb (Gtk.Action action)
+    private void redo_cb ()
     {
         if (game_view.paused)
             return;
@@ -637,7 +643,7 @@ public class Mahjongg : Gtk.Application
         update_ui ();
     }
 
-    private void help_cb (Gtk.Action action)
+    private void help_cb ()
     {
         try
         {
@@ -649,71 +655,43 @@ public class Mahjongg : Gtk.Application
         }
     }
 
-    private const Gtk.ActionEntry actions[] =
+    private const GLib.ActionEntry[] action_entries =
     {
-        {"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},
-        {"RestartGame", GnomeGamesSupport.STOCK_RESTART_GAME, null, null, N_("Restart the current game"), restart_game_cb},
-        {"UndoMove", GnomeGamesSupport.STOCK_UNDO_MOVE, null, null, N_("Undo the last move"), undo_cb},
-        {"RedoMove", GnomeGamesSupport.STOCK_REDO_MOVE, null, null, N_("Redo the last move"), redo_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_cb},
-        {"Preferences", Gtk.Stock.PREFERENCES, null, null, null, properties_cb},
-        {"Contents", GnomeGamesSupport.STOCK_CONTENTS, null, null, null, help_cb},
-        {"About", Gtk.Stock.ABOUT, null, null, null, about_cb}
-    };
-
-    private const Gtk.ToggleActionEntry toggle_actions[] =
-    {
-        {"ShowToolbar", null, N_("_Toolbar"), null, N_("Show or hide the toolbar"), show_toolbar_cb}
+        { "new-game",      new_game_cb     },
+        { "restart-game",  restart_game_cb },
+        { "scores",        scores_cb       },
+        { "preferences",   preferences_cb  },
+        { "help",          help_cb         },
+        { "about",         about_cb        },
+        { "quit",          quit_cb         }
     };
 
     private const string ui_description =
       "<ui>" +
-      "  <menubar name='MainMenu'>" +
-      "    <menu action='GameMenu'>" +
-      "      <menuitem action='NewGame'/>" +
-      "      <menuitem action='RestartGame'/>" +
-      "      <menuitem action='PauseGame'/>" +
-      "      <separator/>" +
-      "      <menuitem action='UndoMove'/>" +
-      "      <menuitem action='RedoMove'/>" +
-      "      <menuitem action='Hint'/>" +
-      "      <separator/>" +
-      "      <menuitem action='Scores'/>" +
-      "      <separator/>" +
-      "      <menuitem action='Quit'/>" +
-      "    </menu>" +
-      "    <menu action='SettingsMenu'>" +
-      "      <menuitem action='Fullscreen'/>" +
-      "      <menuitem action='ShowToolbar'/>" +
-      "      <separator/>" +
-      "      <menuitem action='Preferences'/>" +
-      "    </menu>" +
-      "    <menu action='HelpMenu'>" +
-      "      <menuitem action='Contents'/>" +
-      "      <menuitem action='About'/>" +
-      "    </menu>" +
-      "  </menubar>" +
       "  <toolbar name='Toolbar'>" +
       "    <toolitem action='NewGame'/>" +
       "    <toolitem action='UndoMove'/>" +
+      "    <toolitem action='RedoMove'/>" +
       "    <toolitem action='Hint'/>" +
       "    <toolitem action='PauseGame'/>" +
       "    <toolitem action='LeaveFullscreen'/>" +
       "  </toolbar>" +
       "</ui>";
 
+    private const Gtk.ActionEntry actions[] =
+    {
+        {"NewGame", GnomeGamesSupport.STOCK_NEW_GAME, null, null, N_("Start a new game"), new_game_cb},
+        {"UndoMove", GnomeGamesSupport.STOCK_UNDO_MOVE, null, null, N_("Undo the last move"), undo_cb},
+        {"RedoMove", GnomeGamesSupport.STOCK_REDO_MOVE, null, null, N_("Redo the last move"), redo_cb},
+        {"Hint", GnomeGamesSupport.STOCK_HINT, null, null, N_("Show a hint"), hint_cb}
+    };
+
     private void create_menus (Gtk.UIManager ui_manager)
     {
         var action_group = new Gtk.ActionGroup ("group");
 
         action_group.set_translation_domain (GETTEXT_PACKAGE);
         action_group.add_actions (actions, this);
-        action_group.add_toggle_actions (toggle_actions, this);
 
         ui_manager.insert_action_group (action_group, 0);
         try
@@ -723,7 +701,7 @@ public class Mahjongg : Gtk.Application
         catch (Error e)
         {
         }
-        restart_action = action_group.get_action ("RestartGame");
+
         pause_action = new GnomeGamesSupport.PauseAction ("PauseGame");
         pause_action.is_important = true;
         pause_action.state_changed.connect (pause_cb);
@@ -733,15 +711,13 @@ public class Mahjongg : Gtk.Application
         undo_action = action_group.get_action ("UndoMove");
         undo_action.is_important = true;
         redo_action = action_group.get_action ("RedoMove");
-        var show_toolbar_action = (Gtk.ToggleAction) action_group.get_action ("ShowToolbar");
+        redo_action.is_important = true;
 
         fullscreen_action = new GnomeGamesSupport.FullscreenAction ("Fullscreen", window);
         action_group.add_action_with_accel (fullscreen_action, null);
 
         leave_fullscreen_action = new GnomeGamesSupport.FullscreenAction ("LeaveFullscreen", window);
         action_group.add_action_with_accel (leave_fullscreen_action, null);
-
-        show_toolbar_action.active = settings.get_boolean ("show-toolbar");
     }
 
     private void load_maps ()



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