[gnome-chess] Swap Pause/Resume menu label as appropriate



commit af1d76a4dcde59be1f1bbc1226b8e508da3eae2f
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Mon Jan 6 15:08:07 2014 -0600

    Swap Pause/Resume menu label as appropriate
    
    Unfortunately, this requires dynamically generating the menu. I'm not
    very impressed with the GMenu API compared to the rest of GLib....

 data/menu.ui         |   39 ---------------------------------------
 src/gnome-chess.vala |   32 +++++++++++++++++++++++++++-----
 2 files changed, 27 insertions(+), 44 deletions(-)
---
diff --git a/data/menu.ui b/data/menu.ui
index 7779c82..4bc1f5b 100644
--- a/data/menu.ui
+++ b/data/menu.ui
@@ -25,43 +25,4 @@
       </item>
     </section>
   </menu>
-  <menu id="windowmenu">
-    <section>
-      <item>
-        <attribute name="label" translatable="yes">_New</attribute>
-        <attribute name="action">win.new</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">_Open…</attribute>
-        <attribute name="action">win.open</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">_Save</attribute>
-        <attribute name="action">win.save</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">Save As…</attribute>
-        <attribute name="action">win.save-as</attribute>
-      </item>
-    </section>
-    <section>
-      <item>
-        <attribute name="label" translatable="yes">Pause</attribute>
-        <attribute name="action">win.pause-resume</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">Undo Move</attribute>
-        <attribute name="action">win.undo</attribute>
-        <attribute name="accel">&lt;Primary&gt;Z</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">Claim Draw</attribute>
-        <attribute name="action">win.claim-draw</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">Resign</attribute>
-        <attribute name="action">win.resign</attribute>
-      </item>
-    </section>
-  </menu>
 </interface>
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index f1de564..a929d66 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -122,8 +122,6 @@ public class Application : Gtk.Application
         var app_menu = (Menu) builder.get_object ("appmenu");
         set_app_menu (app_menu);
 
-        var window_menu = (Menu) builder.get_object ("windowmenu");
-
         try
         {
             builder.add_from_file (Path.build_filename (PKGDATADIR, "gnome-chess.ui", null));
@@ -147,10 +145,8 @@ public class Application : Gtk.Application
         builder.connect_signals (this);
 
         window.add_action_entries (window_entries, this);
-        menu_button.set_menu_model (window_menu);
-
-        add_window (window);
         window.icon_name = "gnome-chess";
+        add_window (window);
 
         info_bar = new Gtk.InfoBar ();
         var content_area = (Gtk.Container) info_bar.get_content_area ();
@@ -221,6 +217,7 @@ public class Application : Gtk.Application
             window.maximize ();
         }
 
+        update_window_menu ();
         show ();
     }
 
@@ -1035,6 +1032,30 @@ public class Application : Gtk.Application
             disable_window_action (UNDO_MOVE_ACTION_NAME);
     }
 
+    private void update_window_menu ()
+    {
+        var window_menu = new Menu ();
+
+        var section = new Menu ();
+        section.append (_("New"), "win." + NEW_GAME_ACTION_NAME);
+        section.append (_("Open…"), "win." + OPEN_GAME_ACTION_NAME);
+        section.append (_("Save"), "win." + SAVE_GAME_ACTION_NAME);
+        section.append (_("Save As…"), "win." + SAVE_GAME_AS_ACTION_NAME);
+        window_menu.append_section (null, section);
+
+        section = new Menu();
+        if (game.is_paused)
+            section.append (_("Resume"), "win." + PAUSE_RESUME_ACTION_NAME);
+        else
+            section.append (_("Pause"), "win." + PAUSE_RESUME_ACTION_NAME);
+        section.append (_("Undo Move"), "win." + UNDO_MOVE_ACTION_NAME);
+        section.append (_("Claim Draw"), "win." + CLAIM_DRAW_ACTION_NAME);
+        section.append (_("Resign"), "win." + RESIGN_ACTION_NAME);
+        window_menu.append_section (null, section);
+
+        menu_button.set_menu_model (window_menu);
+    }
+
     private void game_end_cb (ChessGame game)
     {
         disable_window_action (RESIGN_ACTION_NAME);
@@ -1289,6 +1310,7 @@ public class Application : Gtk.Application
 
         update_history_panel ();
         update_action_status ();
+        update_window_menu ();
     }
 
     public void quit_cb ()


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