[gnome-calculator] Use an .ui file for the app menu



commit 06dd08af4c0bea4232746bf01a49ac5e38a409d8
Author: Paolo Borelli <pborelli gnome org>
Date:   Tue Apr 23 21:56:41 2013 +0200

    Use an .ui file for the app menu

 data/gnome-calculator.gresource.xml |    1 +
 data/menu.ui                        |   51 +++++++++++++++++++++++++++++++++++
 src/gnome-calculator.vala           |   30 +++++++-------------
 3 files changed, 62 insertions(+), 20 deletions(-)
---
diff --git a/data/gnome-calculator.gresource.xml b/data/gnome-calculator.gresource.xml
index 3a9d73d..c625834 100644
--- a/data/gnome-calculator.gresource.xml
+++ b/data/gnome-calculator.gresource.xml
@@ -5,5 +5,6 @@
     <file preprocess="xml-stripblanks">buttons-basic.ui</file>
     <file preprocess="xml-stripblanks">buttons-financial.ui</file>
     <file preprocess="xml-stripblanks">buttons-programming.ui</file>
+    <file preprocess="xml-stripblanks">menu.ui</file>
   </gresource>
 </gresources>
diff --git a/data/menu.ui b/data/menu.ui
new file mode 100644
index 0000000..0d330fa
--- /dev/null
+++ b/data/menu.ui
@@ -0,0 +1,51 @@
+<?xml version="1.0"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <menu id="appmenu">
+    <section>
+      <attribute name="label" translatable="yes">Mode</attribute>
+      <item>
+        <attribute name="label" translatable="yes">Basic</attribute>
+        <attribute name="action">app.mode</attribute>
+        <attribute name="target">basic</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Advanced</attribute>
+        <attribute name="action">app.mode</attribute>
+        <attribute name="target">advanced</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Financial</attribute>
+        <attribute name="action">app.mode</attribute>
+        <attribute name="target">financial</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Programming</attribute>
+        <attribute name="action">app.mode</attribute>
+        <attribute name="target">programming</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">Preferences</attribute>
+        <attribute name="action">app.preferences</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">About Calculator</attribute>
+        <attribute name="action">app.about</attribute>
+      </item>
+      <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">Quit</attribute>
+        <attribute name="action">app.quit</attribute>
+        <attribute name="accel">&lt;Primary&gt;q</attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
diff --git a/src/gnome-calculator.vala b/src/gnome-calculator.vala
index e560d2f..fef50b6 100644
--- a/src/gnome-calculator.vala
+++ b/src/gnome-calculator.vala
@@ -74,29 +74,19 @@ public class Calculator : Gtk.Application
         buttons.notify["mode"].connect ((pspec) => { mode_cb (); });
         mode_cb ();
 
-        var menu = new Menu ();
-
-        var section = new Menu ();
-        section.append (_("Basic"), "app.mode::basic");
-        section.append (_("Advanced"), "app.mode::advanced");
-        section.append (_("Financial"), "app.mode::financial");
-        section.append (_("Programming"), "app.mode::programming");
-        menu.append_section (_("Mode"), section);
-
-        section = new Menu ();
-        section.append (_("Preferences"), "app.preferences");
-        menu.append_section (null, section);
-
-        section = new Menu ();
-        section.append (_("About Calculator"), "app.about");
-        section.append (_("Help"), "app.help");
-        section.append (_("Quit"), "app.quit");
-        menu.append_section (null, section);
+        var builder = new Gtk.Builder ();
+        try
+        {
+            builder.add_from_resource ("/org/gnome/calculator/menu.ui");
+        }
+        catch (Error e)
+        {
+            error ("Error loading menu UI: %s", e.message);
+        }
 
+        var menu = builder.get_object ("appmenu") as MenuModel;
         set_app_menu (menu);
 
-        add_accelerator ("<control>Q", "app.quit", null);
-        add_accelerator ("F1", "app.help", null);
         add_accelerator ("<control>C", "app.copy", null);
         add_accelerator ("<control>V", "app.paste", null);
         add_accelerator ("<control>Z", "app.undo", null);


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