[gnome-weather] Use the new GtkBuilder support in libgweather
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-weather] Use the new GtkBuilder support in libgweather
- Date: Sun, 19 May 2013 15:02:14 +0000 (UTC)
commit b5e238ce7063d149cb21728cbef229dfc8f6ff3a
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Sun May 19 16:47:43 2013 +0200
Use the new GtkBuilder support in libgweather
GWeatherLocationEntry can be used in glade now, so we can greatly
simplify the code around the new location dialog.
data/new-location-dialog.ui | 84 +++++++++++++++++++++++++++++++++---------
src/util.js | 13 ++++---
src/window.js | 23 +++---------
3 files changed, 80 insertions(+), 40 deletions(-)
---
diff --git a/data/new-location-dialog.ui b/data/new-location-dialog.ui
index e2a4ea2..2eda149 100644
--- a/data/new-location-dialog.ui
+++ b/data/new-location-dialog.ui
@@ -1,26 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <!-- interface-requires gtk+ 3.0 -->
- <object class="GtkGrid" id="location-dialog-content">
- <property name="visible">True</property>
+ <!-- interface-requires libgweather 3.0 -->
+ <!-- interface-requires gtk+ 3.10 -->
+ <object class="GtkDialog" id="location-dialog">
<property name="can_focus">False</property>
- <property name="halign">center</property>
- <property name="valign">center</property>
- <property name="border_width">5</property>
- <property name="row_spacing">6</property>
- <child>
- <object class="GtkLabel" id="label2">
- <property name="visible">True</property>
+ <property name="modal">True</property>
+ <property name="type_hint">dialog</property>
+ <property name="transient-for">parent-window</property>
+ <property name="title" translatable="True">New Location</property>
+ <child internal-child="vbox">
+ <object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Search for a city:</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="dialog-action_area1">
+ <property name="can_focus">False</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkGrid" id="location-dialog-content">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ <property name="border_width">5</property>
+ <property name="row_spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Search for a city:</property>
+ </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>
+ <child>
+ <object class="GWeatherLocationEntry" id="location-entry">
+ <property name="width_request">400</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="secondary_icon_name">edit-find-symbolic</property>
+ <property name="activates-default">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</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/util.js b/src/util.js
index 4ee8847..c7553cd 100644
--- a/src/util.js
+++ b/src/util.js
@@ -24,12 +24,15 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-function loadUI(file) {
- file = file || 'main.ui';
-
+function loadUI(resourcePath, objects) {
let ui = new Gtk.Builder();
- ui.add_from_file(GLib.build_filenamev([pkg.pkgdatadir,
- file]));
+
+ if (objects) {
+ for (let o in objects)
+ ui.expose_object(o, objects[o]);
+ }
+
+ ui.add_from_resource(resourcePath);
return ui;
}
diff --git a/src/window.js b/src/window.js
index 2a1ee5c..1d485c6 100644
--- a/src/window.js
+++ b/src/window.js
@@ -209,23 +209,11 @@ const MainWindow = new Lang.Class({
},
_newLocation: function() {
- let dialog = new Gtk.Dialog({ title: _("New Location"),
- transient_for: this.get_toplevel(),
- modal: true });
+ let builder = Util.loadUI('/org/gnome/weather/new-location-dialog.ui',
+ { 'parent-window': this.get_toplevel() });
- let builder = new Gtk.Builder();
- builder.add_from_resource('/org/gnome/weather/new-location-dialog.ui');
-
- let grid = builder.get_object('location-dialog-content');
-
- let find_icon = Gio.ThemedIcon.new_with_default_fallbacks("edit-find-symbolic");
- let entry = new GWeather.LocationEntry({ top: this._world,
- width_request: 400,
- activates_default: true });
- entry.set_icon_from_gicon(Gtk.EntryIconPosition.SECONDARY, find_icon);
-
- grid.attach(entry, 0, 1, 1, 1);
- dialog.get_content_area().add(grid);
+ let dialog = builder.get_object('location-dialog');
+ let entry = builder.get_object('location-entry');
dialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL);
dialog.add_button(Gtk.STOCK_ADD, Gtk.ResponseType.OK);
@@ -243,7 +231,8 @@ const MainWindow = new Lang.Class({
this._worldView.model.addLocation(entry.location);
}));
- dialog.show_all();
+
+ dialog.show();
},
_setSelectionMode: function(action, param) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]