[gnome-weather/wip/gjs-experiments: 4/6] Use a .ui file for the main window



commit 83d743ad5520e348aa8baa7dbfd934a6a21bf027
Author: Paolo Borelli <pborelli gnome org>
Date:   Fri Mar 8 19:33:18 2013 +0100

    Use a .ui file for the main window
    
    This starts using a ui file for the toolbar an its buttons.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=695457

 data/gnome-weather.gresource.xml |    1 +
 data/window.ui                   |   78 ++++++++++++++++++++++++++++++++++++++
 src/window.js                    |   30 +++++----------
 3 files changed, 89 insertions(+), 20 deletions(-)
---
diff --git a/data/gnome-weather.gresource.xml b/data/gnome-weather.gresource.xml
index 627cd69..6c3ea90 100644
--- a/data/gnome-weather.gresource.xml
+++ b/data/gnome-weather.gresource.xml
@@ -2,6 +2,7 @@
 <gresources>
   <gresource prefix="/org/gnome/weather">
     <file preprocess="xml-stripblanks">app-menu.ui</file>
+    <file preprocess="xml-stripblanks">window.ui</file>
     <file>application.css</file>
   </gresource>
 </gresources>
diff --git a/data/window.ui b/data/window.ui
new file mode 100644
index 0000000..ec55e87
--- /dev/null
+++ b/data/window.ui
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkGrid" id="main-panel">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="orientation">vertical</property>
+    <child>
+      <object class="GdHeaderBar" id="header-bar">
+        <property name="visible">True</property>
+        <property name="vexpand">False</property>
+        <child>
+          <object class="GdHeaderSimpleButton" id="new-button">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">New</property>
+            <signal name="clicked" handler="_newLocation"/>
+          </object>
+          <packing>
+            <property name="pack_type">start</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GdHeaderSimpleButton" id="world-button">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">World Weather</property>
+            <signal name="clicked" handler="_goWorld"/>
+          </object>
+          <packing>
+            <property name="pack_type">start</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GdHeaderSimpleButton" id="select-button">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="symbolic-icon-name">object-select-symbolic</property>
+          </object>
+          <packing>
+            <property name="pack_type">end</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GdHeaderSimpleButton" id="done-button">
+            <property name="visible">True</property>
+            <property name="no_show_all">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">Done</property>
+            <style>
+              <class name="suggested-action"/>
+            </style>
+          </object>
+          <packing>
+            <property name="pack_type">end</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GdHeaderSimpleButton" id="refresh-button">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="symbolic-icon-name">view-refresh-symbolic</property>
+            <signal name="clicked" handler="update"/>
+          </object>
+          <packing>
+            <property name="pack_type">end</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">0</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+  </object>
+</interface>
diff --git a/src/window.js b/src/window.js
index fc2fdea..fc49556 100644
--- a/src/window.js
+++ b/src/window.js
@@ -107,34 +107,24 @@ const MainWindow = new Lang.Class({
                           { name: 'about',
                             callback: this._showAbout }]);
 
-        let grid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL });
+        let builder = Util.loadUI('/org/gnome/weather/window.ui', this);
 
-        this._header = new Gd.HeaderBar({ hexpand: true });
-        grid.add(this._header);
+        let grid = builder.get_object('main-panel');
+        this._header = builder.get_object('header-bar');
 
-        let newButton = new Gd.HeaderSimpleButton({ label: _("New") });
-        newButton.connect('clicked', Lang.bind(this, this._newLocation));
-        this._header.pack_start(newButton);
+        let newButton = builder.get_object('new-button');
         this._pageWidgets[Page.WORLD].push(newButton);
 
-        let goWorldButton = new Gd.HeaderSimpleButton({ label: _("World Weather") });
-        goWorldButton.connect('clicked', Lang.bind(this, this._goWorld));
-        this._header.pack_start(goWorldButton);
+        let goWorldButton = builder.get_object('world-button');
         this._pageWidgets[Page.CITY].push(goWorldButton);
 
-        let refresh = new Gd.HeaderSimpleButton({ symbolic_icon_name: 'view-refresh-symbolic' });
-        refresh.connect('clicked', Lang.bind(this, this.update));
-        this._header.pack_end(refresh);
-        this._pageWidgets[Page.CITY].push(refresh);
-
-        let select = new Gd.HeaderSimpleButton({ symbolic_icon_name: 'object-select-symbolic' });
-        this._header.pack_end(select);
+        let select = builder.get_object('select-button');
         this._pageWidgets[Page.WORLD].push(select);
 
-        let selectDone = new Gd.HeaderSimpleButton({ label: _("Done"),
-                                                     no_show_all: true });
-        selectDone.get_style_context().add_class('suggested-action');
-        this._header.pack_end(selectDone);
+        let refresh = builder.get_object('refresh-button');
+        this._pageWidgets[Page.CITY].push(refresh);
+
+        let selectDone = builder.get_object('done-button');
         this._pageWidgets[Page.WORLD].push(selectDone);
 
         this._stack = new Gd.Stack({ transition_type: Gd.StackTransitionType.CROSSFADE });


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