[lightsoff] Use GtkBuilder.



commit 9424525bb5e995971384915e117c9c5cdbfb4e3b
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Mar 4 06:39:16 2015 +0100

    Use GtkBuilder.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=745625

 data/Makefile.am            |    3 +-
 data/lightsoff.ui           |   53 +++++++++++++++++++++++++++++++++++++++++++
 po/POTFILES.in              |    1 +
 src/lightsoff.gresource.xml |    6 ++--
 src/lightsoff.vala          |   34 +++++++++------------------
 5 files changed, 70 insertions(+), 27 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 53547fc..1e2f6ec 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,7 +1,8 @@
 SUBDIRS = icons
 
 dist_noinst_DATA = \
-       lightsoff-menus.ui
+       lightsoff-menus.ui \
+       lightsoff.ui
 
 lightsoffdir = $(datadir)/lightsoff
 lightsoff_DATA = \
diff --git a/data/lightsoff.ui b/data/lightsoff.ui
new file mode 100644
index 0000000..ba48c8a
--- /dev/null
+++ b/data/lightsoff.ui
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <object class="GtkApplicationWindow" id="window">
+    <property name="resizable">False</property>
+    <child type="titlebar">
+      <object class="GtkHeaderBar" id="headerbar">
+        <property name="visible">True</property>
+        <property name="show-close-button">True</property>
+        <child>
+          <object class="GtkButton">
+            <property name="visible">True</property>
+            <property name="valign">center</property><!-- ??? -->
+            <property name="focus-on-click">False</property>
+            <property name="tooltip-text" translatable="yes">Return to the previous level</property>
+            <property name="action-name">win.previous-level</property>
+            <style><class name="image-button"/></style>
+            <child>
+              <object class="GtkImage">
+                <property name="icon-name">go-previous-symbolic</property>
+                <property name="visible">True</property>
+                <property name="icon-size">1</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="pack-type">start</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkButton">
+            <property name="visible">True</property>
+            <property name="valign">center</property><!-- ??? -->
+            <property name="focus-on-click">False</property>
+            <property name="tooltip-text" translatable="yes">Proceed to the next level</property>
+            <property name="action-name">win.next-level</property>
+            <style><class name="image-button"/></style>
+            <child>
+              <object class="GtkImage">
+                <property name="icon-name">go-next-symbolic</property>
+                <property name="visible">True</property>
+                <property name="icon-size">1</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="pack-type">end</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 333d070..4ebd5e0 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -4,6 +4,7 @@
 data/lightsoff.appdata.xml.in
 data/lightsoff.desktop.in
 [type: gettext/glade]data/lightsoff-menus.ui
+[type: gettext/glade]data/lightsoff.ui
 data/org.gnome.lightsoff.gschema.xml
 src/board-view.vala
 src/game-view.vala
diff --git a/src/lightsoff.gresource.xml b/src/lightsoff.gresource.xml
index 312ca7d..f29f055 100644
--- a/src/lightsoff.gresource.xml
+++ b/src/lightsoff.gresource.xml
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
-  <!-- <gresource prefix="/org/gnome/lightsoff/ui">
+  <gresource prefix="/org/gnome/lightsoff/ui">
     <file preprocess="xml-stripblanks" alias="lightsoff.ui">../data/lightsoff.ui</file>
-    <file alias="lightsoff.css">../data/lightsoff.css</file>
-  </gresource> -->
+    <!-- <file alias="lightsoff.css">../data/lightsoff.css</file> -->
+  </gresource>
   <gresource prefix="/org/gnome/lightsoff/gtk">
     <file preprocess="xml-stripblanks" alias="menus.ui">../data/lightsoff-menus.ui</file>
   </gresource>
diff --git a/src/lightsoff.vala b/src/lightsoff.vala
index 9a58088..91423c0 100644
--- a/src/lightsoff.vala
+++ b/src/lightsoff.vala
@@ -15,6 +15,7 @@ public class LightsOff : Gtk.Application
     private Gtk.ApplicationWindow window;
     private Gtk.HeaderBar headerbar;
     private GameView game_view;
+    private SimpleAction previous_level;
 
     private const GLib.ActionEntry[] action_entries =
     {
@@ -39,36 +40,21 @@ public class LightsOff : Gtk.Application
     {
         base.startup ();
 
+        Gtk.Window.set_default_icon_name ("lightsoff");
         Gtk.Settings.get_default ().set ("gtk-application-prefer-dark-theme", true);
 
         add_action_entries (action_entries, this);
 
         settings = new Settings ("org.gnome.lightsoff");
 
-        window = new Gtk.ApplicationWindow (this);
+        Gtk.Builder builder = new Gtk.Builder.from_resource ("/org/gnome/lightsoff/ui/lightsoff.ui");
+        window = (Gtk.ApplicationWindow) builder.get_object ("window");
+        headerbar = (Gtk.HeaderBar) builder.get_object ("headerbar");
+
         window.add_action_entries (window_actions, this);
-        window.icon_name = "lightsoff";
-        window.resizable = false;
-
-        var left_button = new Gtk.Button.from_icon_name ("go-previous-symbolic", Gtk.IconSize.BUTTON);
-        left_button.valign = Gtk.Align.CENTER;
-        left_button.action_name = "win.previous-level";
-        left_button.set_tooltip_text (_("Return to the previous level"));
-        left_button.show ();
-
-        var right_button = new Gtk.Button.from_icon_name ("go-next-symbolic", Gtk.IconSize.BUTTON);
-        right_button.valign = Gtk.Align.CENTER;
-        right_button.action_name = "win.next-level";
-        right_button.set_tooltip_text (_("Proceed to the next level"));
-        right_button.show ();
-
-        headerbar = new Gtk.HeaderBar ();
-        headerbar.show_close_button = true;
-        headerbar.pack_start (left_button);
-        headerbar.pack_end (right_button);
-        headerbar.show ();
+        previous_level = (SimpleAction) window.lookup_action ("previous-level");
+
         level_changed_cb (settings.get_int ("level"));
-        window.set_titlebar (headerbar);
 
         var clutter_embed = new GtkClutter.Embed ();
         clutter_embed.show ();
@@ -86,6 +72,8 @@ public class LightsOff : Gtk.Application
 
         stage.set_size (game_view.width, game_view.height);
         clutter_embed.set_size_request ((int) stage.width, (int) stage.height);
+
+        add_window (window);
     }
 
     private void update_subtitle (int moves)
@@ -117,7 +105,7 @@ public class LightsOff : Gtk.Application
 
     private void level_changed_cb (int level)
     {
-        ((SimpleAction) (window.lookup_action ("previous-level"))).set_enabled (level > 1);
+        previous_level.set_enabled (level > 1);
         update_title (level);
        if (level != settings.get_int ("level"))
             settings.set_int ("level", level);


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