[gnome-maps] Add PlaceEntry, a SearchEntry for places
- From: Mattias Bengtsson <mattiasb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] Add PlaceEntry, a SearchEntry for places
- Date: Fri, 20 Jun 2014 02:20:18 +0000 (UTC)
commit 09d1dd34bdd6c75722c0548e8bb21410dcb07c5a
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date: Thu Jun 12 05:15:41 2014 +0200
Add PlaceEntry, a SearchEntry for places
PlaceEntry encapsulates all the search entry stuff in mainWindow in a
reusable way.
https://bugzilla.gnome.org/show_bug.cgi?id=731545
src/gnome-maps.data.gresource.xml | 1 +
src/gnome-maps.js.gresource.xml | 1 +
src/place-entry.ui | 23 +++++++
src/placeEntry.js | 128 +++++++++++++++++++++++++++++++++++++
4 files changed, 153 insertions(+), 0 deletions(-)
---
diff --git a/src/gnome-maps.data.gresource.xml b/src/gnome-maps.data.gresource.xml
index d9265a9..5efd09e 100644
--- a/src/gnome-maps.data.gresource.xml
+++ b/src/gnome-maps.data.gresource.xml
@@ -2,6 +2,7 @@
<gresources>
<gresource prefix="/org/gnome/maps">
<file preprocess="xml-stripblanks">app-menu.ui</file>
+ <file preprocess="xml-stripblanks">place-entry.ui</file>
<file preprocess="xml-stripblanks">main-window.ui</file>
<file preprocess="xml-stripblanks">zoom-control.ui</file>
<file preprocess="xml-stripblanks">search-popup.ui</file>
diff --git a/src/gnome-maps.js.gresource.xml b/src/gnome-maps.js.gresource.xml
index 37366f2..93dd219 100644
--- a/src/gnome-maps.js.gresource.xml
+++ b/src/gnome-maps.js.gresource.xml
@@ -13,6 +13,7 @@
<file>notification.js</file>
<file>notificationManager.js</file>
<file>path.js</file>
+ <file>placeEntry.js</file>
<file>placeStore.js</file>
<file>searchPopup.js</file>
<file>settings.js</file>
diff --git a/src/place-entry.ui b/src/place-entry.ui
new file mode 100644
index 0000000..417e42d
--- /dev/null
+++ b/src/place-entry.ui
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <object class="GtkEntryCompletion" id="completion">
+ <property name="minimum_key_length">2</property>
+ <child>
+ <object class="GtkCellRendererPixbuf" id="iconCellRenderer">
+ <property name="xpad">2</property>
+ </object>
+ <attributes>
+ <attribute name="pixbuf">0</attribute>
+ </attributes>
+ </child>
+ <child>
+ <object class="GtkCellRendererText" id="textCellRenderer">
+ <property name="ypad">4</property>
+ </object>
+ <attributes>
+ <attribute name="text">2</attribute>
+ </attributes>
+ </child>
+ </object>
+</interface>
diff --git a/src/placeEntry.js b/src/placeEntry.js
new file mode 100644
index 0000000..a2b1af9
--- /dev/null
+++ b/src/placeEntry.js
@@ -0,0 +1,128 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2013,2014 Jonas Danielsson, Mattias Bengtsson.
+ *
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Jonas Danielsson <jonas threetimestwo org>
+ * Mattias Bengtsson <mattias jc bengtsson gmail com>
+ */
+
+const Gtk = imports.gi.Gtk;
+const GObject = imports.gi.GObject;
+const Geocode = imports.gi.GeocodeGlib;
+const Lang = imports.lang;
+
+const Application = imports.application;
+const PlaceStore = imports.placeStore;
+const SearchPopup = imports.searchPopup;
+const Utils = imports.utils;
+
+const PlaceEntry = new Lang.Class({
+ Name: 'PlaceEntry',
+ Extends: Gtk.SearchEntry,
+ Properties: {
+ 'place': GObject.ParamSpec.object('place',
+ 'Place',
+ 'The selected place',
+ GObject.ParamFlags.READWRITE,
+ Geocode.Place)
+ },
+
+ set place(p) {
+ this._place = p;
+ this.text = p ? p.name : "";
+ this.notify("place");
+ },
+ get place() {
+ return this._place;
+ },
+
+ get popover() {
+ return this._popover;
+ },
+
+ _init: function(props) {
+ let numVisible = props.num_visible || 10;
+ delete props.num_visible;
+ this._mapView = props.mapView;
+ delete props.mapView;
+
+ props.completion = this._createCompletion();
+ this.parent(props);
+
+ this._popover = this._createPopover(numVisible);
+
+ this.connect('activate', this._onActivate.bind(this));
+ this.connect('search-changed', (function() {
+ this.popover.hide();
+
+ if (this.text.length === 0)
+ this.place = null;
+ }).bind(this));
+ },
+
+ _createCompletion: function() {
+ let { completion } = Utils.getUIObject('place-entry',
+ ['completion']);
+
+ completion.set_model(Application.placeStore);
+ completion.set_match_func(PlaceStore.completionMatchFunc);
+
+ completion.connect('match-selected', (function(c, model, iter) {
+ this.place = model.get_value(iter, PlaceStore.Columns.PLACE);
+ }).bind(this));
+
+ return completion;
+ },
+
+ _createPopover: function(numVisible) {
+ let popover = new SearchPopup.SearchPopup({ num_visible: numVisible,
+ relative_to: this,
+ no_show_all: true,
+ visible: true });
+ this.connect('size-allocate', (function(widget, allocation) {
+ // Magic number to make the alignment pixel perfect.
+ let width_request = allocation.width + 20;
+ popover.width_request = width_request;
+ }).bind(this));
+
+ popover.connect('selected', (function(widget, place) {
+ this.place = place;
+ popover.hide();
+ }).bind(this));
+
+ return popover;
+ },
+
+ _onActivate: function() {
+ if (this.text.length === 0) {
+ this.place = null;
+ return;
+ }
+
+ this._popover.showSpinner();
+ this._mapView.geocodeSearch(this.text, (function(places) {
+ if (!places) {
+ this.place = null;
+ this._popover.hide();
+ return;
+ }
+ this._popover.updateResult(places, this.text);
+ this._popover.showResult();
+ }).bind(this));
+ }
+});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]