[gnome-games/sudoku-vala] Use GMenu



commit 48d5528e6fa4a48b327ddeb57bcd912edd0c85ad
Author: Christopher Baines <cbaines8 gmail com>
Date:   Sat Jun 2 14:33:49 2012 +0100

    Use GMenu

 gnome-sudoku/data/gnome-sudoku-menu.ui         |   65 ++++++
 gnome-sudoku/data/gnome-sudoku.ui              |  255 ------------------------
 gnome-sudoku/src/gnome-sudoku.gresource.xml.in |    1 +
 gnome-sudoku/src/gnome-sudoku.vala             |  107 +++++-----
 4 files changed, 118 insertions(+), 310 deletions(-)
---
diff --git a/gnome-sudoku/data/gnome-sudoku-menu.ui b/gnome-sudoku/data/gnome-sudoku-menu.ui
new file mode 100644
index 0000000..9dc0515
--- /dev/null
+++ b/gnome-sudoku/data/gnome-sudoku-menu.ui
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="2.16"/>
+    <menu id="sudoku-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">_Reset</attribute>
+          <attribute name="action">app.reset</attribute>
+          <attribute name="accel">&lt;Primary&gt;r</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_Undo</attribute>
+          <attribute name="action">app.undo</attribute>
+          <attribute name="accel">&lt;Primary&gt;u</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">_Redo</attribute>
+          <attribute name="action">app.redo</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_Print</attribute>
+          <attribute name="action">app.print</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">_Print Multiple Sudoku's...</attribute>
+          <attribute name="action">app.print-multiple</attribute>
+        </item>
+      </section>
+      <section>
+        <item>
+          <attribute name="label" translatable="yes">_Show Possible Numbers</attribute>
+          <attribute name="action">app.possible-numbers</attribute>
+        </item>
+        <item>
+          <attribute name="label" translatable="yes">_Warn About Unfillable Squares</attribute>
+          <attribute name="action">app.unfillable-squares</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">&lt;Primary&gt;q</attribute>
+        </item>
+      </section>
+    </menu>
+</interface>
diff --git a/gnome-sudoku/data/gnome-sudoku.ui b/gnome-sudoku/data/gnome-sudoku.ui
index 750f79f..078888d 100644
--- a/gnome-sudoku/data/gnome-sudoku.ui
+++ b/gnome-sudoku/data/gnome-sudoku.ui
@@ -9,261 +9,6 @@
       <object class="GtkVBox" id="main_vbox">
         <property name="visible">True</property>
         <child>
-          <object class="GtkMenuBar" id="sudoku_menubar">
-            <property name="visible">True</property>
-            <child>
-              <object class="GtkMenuItem" id="game_menuitem">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">_Game</property>
-                <property name="use_underline">True</property>
-                <child type="submenu">
-                  <object class="GtkMenu" id="game_menu">
-                    <property name="visible">True</property>
-                    <child>
-                      <object class="GtkMenuItem" id="new_game_imagemenuitem">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">New</property>
-                        <property name="use_underline">True</property>
-                        <accelerator key="n" signal="activate" modifiers="GDK_CONTROL_MASK"/>
-                        <signal name="activate" handler="new_game_cb"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="reset_game_imagemenuitem">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">Reset</property>
-                        <property name="use_underline">True</property>
-                        <accelerator key="b" signal="activate" modifiers="GDK_CONTROL_MASK"/>
-                        <signal name="activate" handler="reset_game_cb"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkSeparatorMenuItem" id="game_menu_separator0">
-                        <property name="visible">True</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="undo_imagemenuitem">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">Undo</property>
-                        <property name="use_underline">True</property>
-                        <accelerator key="z" signal="activate" modifiers="GDK_CONTROL_MASK"/>
-                        <signal name="activate" handler="undo_cb"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="redo_imagemenuitem">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">Redo</property>
-                        <property name="use_underline">True</property>
-                        <accelerator key="z" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
-                        <signal name="activate" handler="redo_cb"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkSeparatorMenuItem" id="game_menu_separator1">
-                        <property name="visible">True</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="statistics_menuitem">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">Puzzle Statistics...</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="statistics_cb"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkSeparatorMenuItem" id="game_menu_separator2">
-                        <property name="visible">True</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="print_menuitem">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">Print...</property>
-                        <property name="use_underline">True</property>
-                        <accelerator key="p" signal="activate" modifiers="GDK_CONTROL_MASK"/>
-                        <signal name="activate" handler="print_cb"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="print_multiple_menuitem">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">Print Multiple Sudokus...</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="print_multiple_cb"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkSeparatorMenuItem" id="game_menu_separator3">
-                        <property name="visible">True</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="quit_imagemenuitem">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">Close</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="quit_cb"/>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
-            <child>
-              <object class="GtkMenuItem" id="settings_menuitem">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">_Settings</property>
-                <property name="use_underline">True</property>
-                <child type="submenu">
-                  <object class="GtkMenu" id="settings_menu">
-                    <property name="visible">True</property>
-                    <child>
-                      <object class="GtkCheckMenuItem" id="toggle_fullscreen_imagemenuitem">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">Fullscreen</property>
-                        <property name="use_underline">True</property>
-                        <accelerator key="F11" signal="activate"/>
-                        <signal name="toggled" handler="toggle_fullscreen_cb"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkCheckMenuItem" id="toggle_toolbar_imagemenuitem">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">Show Toolbar</property>
-                        <property name="use_underline">True</property>
-                        <signal name="toggled" handler="toggle_toolbar_cb"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkSeparatorMenuItem" id="settings_menu_separator0">
-                        <property name="visible">True</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkCheckMenuItem" id="toggle_highlighter_imagemenuitem">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">Hilighter</property>
-                        <property name="use_underline">True</property>
-                        <signal name="toggled" handler="toggle_highlighter_cb"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkCheckMenuItem" id="toggle_hints_menuitem">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">Show Possible Numbers</property>
-                        <property name="use_underline">True</property>
-                        <signal name="toggled" handler="toggle_hints_cb"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkCheckMenuItem" id="toggle_warnings_menuitem">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">Warn About Unfillable Squares</property>
-                        <property name="use_underline">True</property>
-                        <signal name="toggled" handler="toggle_warnings_cb"/>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
-            <child>
-              <object class="GtkMenuItem" id="tools_menuitem">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">Tools</property>
-                <property name="use_underline">True</property>
-                <child type="submenu">
-                  <object class="GtkMenu" id="tools_menu">
-                    <property name="visible">True</property>
-                    <child>
-                      <object class="GtkMenuItem" id="hint_menuitem">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">Hint</property>
-                        <property name="use_underline">True</property>
-                        <accelerator key="h" signal="activate" modifiers="GDK_CONTROL_MASK"/>
-                        <signal name="activate" handler="hint_cb"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkSeparatorMenuItem" id="tools_menu_separator0">
-                        <property name="visible">True</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="clear_top_notes_menuitem">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">Clear Top Notes</property>
-                        <property name="use_underline">True</property>
-                        <accelerator key="j" signal="activate" modifiers="GDK_CONTROL_MASK"/>
-                        <signal name="activate" handler="clear_top_notes_cb"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="clear_bottom_notes_menuitem">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">Clear Bottom Notes</property>
-                        <property name="use_underline">True</property>
-                        <accelerator key="k" signal="activate" modifiers="GDK_CONTROL_MASK"/>
-                        <signal name="activate" handler="clear_bottom_notes_cb"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkSeparatorMenuItem" id="tools_menu_separator1">
-                        <property name="visible">True</property>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkCheckMenuItem" id="toggle_tracker_menuitem">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">Track Additions</property>
-                        <property name="use_underline">True</property>
-                        <accelerator key="t" signal="activate" modifiers="GDK_CONTROL_MASK"/>
-                        <signal name="toggled" handler="toggle_tracker_cb"/>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
-            <child>
-              <object class="GtkMenuItem" id="help_menuitem">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">_Help</property>
-                <property name="use_underline">True</property>
-                <child type="submenu">
-                  <object class="GtkMenu" id="help_menu">
-                    <property name="visible">True</property>
-                    <child>
-                      <object class="GtkMenuItem" id="help_imagemenuitem">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">Contents</property>
-                        <property name="use_underline">True</property>
-                        <accelerator key="F1" signal="activate"/>
-                        <signal name="activate" handler="help_cb"/>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkMenuItem" id="about_menuitem">
-                        <property name="visible">True</property>
-                        <property name="label" translatable="yes">About</property>
-                        <property name="use_underline">True</property>
-                        <signal name="activate" handler="about_cb"/>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
           <object class="GtkToolbar" id="sudoku_toolbar">
             <property name="visible">True</property>
             <child>
diff --git a/gnome-sudoku/src/gnome-sudoku.gresource.xml.in b/gnome-sudoku/src/gnome-sudoku.gresource.xml.in
index e6d2393..fd76e08 100644
--- a/gnome-sudoku/src/gnome-sudoku.gresource.xml.in
+++ b/gnome-sudoku/src/gnome-sudoku.gresource.xml.in
@@ -2,6 +2,7 @@
 <gresources>
   <gresource prefix="/org/gnome/gnome-sudoku/ui">
     <file alias="gnome-sudoku.ui" preprocess="xml-stripblanks">@top_srcdir@/gnome-sudoku/data/gnome-sudoku.ui</file>
+    <file alias="gnome-sudoku-menu.ui" preprocess="xml-stripblanks">@top_srcdir@/gnome-sudoku/data/gnome-sudoku-menu.ui</file>
   </gresource>
 </gresources>
 
diff --git a/gnome-sudoku/src/gnome-sudoku.vala b/gnome-sudoku/src/gnome-sudoku.vala
index cb6bf02..537c559 100644
--- a/gnome-sudoku/src/gnome-sudoku.vala
+++ b/gnome-sudoku/src/gnome-sudoku.vala
@@ -11,11 +11,32 @@ public class Sudoku : Gtk.Application
 
     private Gtk.AboutDialog? about_dialog = null;
 
+    private const GLib.ActionEntry action_entries[] =
+    {
+        {"new-game", new_game_cb                                                                },
+        {"reset", reset_cb                                                                      },
+        {"undo", undo_cb                                                                        },
+        {"redo", redo_cb                                                                        },
+        {"print", print_cb                                                                      },
+        {"print-multiple", print_multiple_cb                                                    },
+        {"possible-numbers",   possible_numbers_cb,   null, "false", possible_numbers_changed   },
+        {"unfillable-squares", unfillable_squares_cb, null, "false", unfillable_squares_changed },
+        {"help", help_cb                                                                        },
+        {"about", about_cb                                                                      },
+        {"quit", quit_cb                                                                        }
+    };
+
     public Sudoku ()
     {
         Object (application_id: "org.gnome.gnome-sudoku", flags: ApplicationFlags.FLAGS_NONE);
     }
 
+    protected override void startup()
+    {
+        base.startup ();
+        add_action_entries (action_entries, this);
+    }
+
     protected override void activate () {
         settings = new Settings ("org.gnome.gnome-sudoku");
 
@@ -23,6 +44,7 @@ public class Sudoku : Gtk.Application
         try
         {
             builder.add_from_resource ("/org/gnome/gnome-sudoku/ui/gnome-sudoku.ui");
+            builder.add_from_resource ("/org/gnome/gnome-sudoku/ui/gnome-sudoku-menu.ui");
         }
         catch (GLib.Error e)
         {
@@ -35,6 +57,8 @@ public class Sudoku : Gtk.Application
 
         add_window (window);
 
+        set_app_menu (builder.get_object ("sudoku-menu") as MenuModel);
+
         fullscreen_menu = (Gtk.CheckMenuItem) builder.get_object ("toggle_fullscreen_imagemenuitem");
         var main_vbox = (Gtk.VBox) builder.get_object ("main_vbox");
         toolbar = (Gtk.Toolbar) builder.get_object ("sudoku_toolbar");
@@ -51,55 +75,61 @@ public class Sudoku : Gtk.Application
         window.show ();
     }
 
-    [CCode (cname = "G_MODULE_EXPORT new_game_cb", instance_pos = -1)]
-    public void new_game_cb (Gtk.Widget widget)
+    public void new_game_cb ()
     {
         stdout.printf ("TODO: new game\n");
     }
 
-    [CCode (cname = "G_MODULE_EXPORT reset_game_cb", instance_pos = -1)]
-    public void reset_game_cb (Gtk.Widget widget)
+    public void reset_cb ()
     {
         game.reset ();
     }
 
-    [CCode (cname = "G_MODULE_EXPORT undo_cb", instance_pos = -1)]
-    public void undo_cb (Gtk.Widget widget)
+    public void undo_cb ()
     {
         game.undo ();
     }
 
-    [CCode (cname = "G_MODULE_EXPORT redo_cb", instance_pos = -1)]
-    public void redo_cb (Gtk.Widget widget)
+    public void redo_cb ()
     {
         game.redo ();
     }
 
-    [CCode (cname = "G_MODULE_EXPORT statistics_cb", instance_pos = -1)]
-    public void statistics_cb (Gtk.Widget widget)
+    public void print_cb ()
     {
-        stdout.printf ("TODO: Show statistics\n");
+        stdout.printf ("TODO: Print\n");    
     }
 
-    [CCode (cname = "G_MODULE_EXPORT print_cb", instance_pos = -1)]
-    public void print_cb (Gtk.Widget widget)
+    public void print_multiple_cb ()
     {
-        stdout.printf ("TODO: Print\n");    
+        stdout.printf ("TODO: Print multiple\n");
     }
 
-    [CCode (cname = "G_MODULE_EXPORT print_multiple_cb", instance_pos = -1)]
-    public void print_multiple_cb (Gtk.Widget widget)
+    public void possible_numbers_cb ()
+    {  
+        stdout.printf ("TODO: Possible numbers\n");
+    }
+ 
+    private void possible_numbers_changed (SimpleAction action, Variant state)
     {
-        stdout.printf ("TODO: Print multiple\n");
+        stdout.printf ("TODO: Possible numbers changed\n");
     }
 
-    [CCode (cname = "G_MODULE_EXPORT quit_cb", instance_pos = -1)]
-    public void quit_cb (Gtk.Widget widget)
+    public void unfillable_squares_cb ()
+    {  
+        stdout.printf ("TODO: Unfillable squares\n");
+    }
+ 
+    private void unfillable_squares_changed (SimpleAction action, Variant state)
+    {
+        stdout.printf ("TODO: Unfillable squares changed\n");
+    }
+
+    public void quit_cb ()
     {
         window.destroy ();
     }
 
-    [CCode (cname = "G_MODULE_EXPORT sudoku_app_window_state_event_cb", instance_pos = -1)]
     public bool sudoku_app_window_state_event_cb (Gtk.Widget widget, Gdk.EventWindowState event)
     {
         if ((event.changed_mask & Gdk.WindowState.FULLSCREEN) != 0)
@@ -112,69 +142,37 @@ public class Sudoku : Gtk.Application
         return false;
     }
 
-
-    [CCode (cname = "G_MODULE_EXPORT toggle_fullscreen_cb", instance_pos = -1)]
-    public void toggle_fullscreen_cb (Gtk.CheckMenuItem item)
-    {  
-        if (item.active) 
-            window.fullscreen (); 
-        else 
-            window.unfullscreen ();
-    }
-
-    [CCode (cname = "G_MODULE_EXPORT toggle_toolbar_cb", instance_pos = -1)]
-    public void toggle_toolbar_cb (Gtk.CheckMenuItem item)
-    {    
-        if (item.active)
-            toolbar.show();
-        else
-            toolbar.hide(); 
-    }
-
-    [CCode (cname = "G_MODULE_EXPORT toggle_highlighter_cb", instance_pos = -1)]
-    public void toggle_highlighter_cb (Gtk.Widget widget)
-    {
-        view.show_highlights = !view.show_highlights;
-    }
-
-    [CCode (cname = "G_MODULE_EXPORT toggle_hints_cb", instance_pos = -1)]
     public void toggle_hints_cb (Gtk.Widget widget)
     {
         view.show_hints = !view.show_hints;
     }
 
-    [CCode (cname = "G_MODULE_EXPORT toggle_warnings_cb", instance_pos = -1)]
     public void toggle_warnings_cb (Gtk.Widget widget)
     {
         view.show_warnings = !view.show_warnings;    
     }
 
-    [CCode (cname = "G_MODULE_EXPORT hint_cb", instance_pos = -1)]
     public void hint_cb (Gtk.Widget widget)
     {
         view.hint ();
     }
 
-    [CCode (cname = "G_MODULE_EXPORT clear_top_notes_cb", instance_pos = -1)]
     public void clear_top_notes_cb (Gtk.Widget widget)
     {
         view.clear_top_notes ();
     }
 
-    [CCode (cname = "G_MODULE_EXPORT clear_bottom_notes_cb", instance_pos = -1)]
     public void clear_bottom_notes_cb (Gtk.Widget widget)
     {
         view.clear_bottom_notes ();
     }
 
-    [CCode (cname = "G_MODULE_EXPORT toggle_tracker_cb", instance_pos = -1)]
     public void toggle_tracker_cb (Gtk.Widget widget)
     {
         stdout.printf ("TODO: Toggle tracker\n");
     }
 
-    [CCode (cname = "G_MODULE_EXPORT help_cb", instance_pos = -1)]
-    public void help_cb (Gtk.Widget widget)
+    public void help_cb ()
     {
         try
         {
@@ -189,8 +187,7 @@ public class Sudoku : Gtk.Application
     private const string[] authors = { "Robert Ancell <robert ancell gmail com>" };
     private const string[] artists = { "" };
 
-    [CCode (cname = "G_MODULE_EXPORT about_cb", instance_pos = -1)]
-    public void about_cb (Gtk.Widget widget)
+    public void about_cb ()
     {
         if (about_dialog != null)
         {



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