[gnome-maps/wip/favorites: 3/8] Split out PlaceListRow from SearchPopup
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/favorites: 3/8] Split out PlaceListRow from SearchPopup
- Date: Sat, 22 Nov 2014 20:16:20 +0000 (UTC)
commit 2713c5adde5bfd3f85990473956ff6e5278f803f
Author: Jonas Danielsson <jonas threetimestwo org>
Date: Sat Nov 22 00:52:18 2014 +0100
Split out PlaceListRow from SearchPopup
https://bugzilla.gnome.org/show_bug.cgi?id=722102
src/gnome-maps.data.gresource.xml | 2 +-
src/gnome-maps.js.gresource.xml | 1 +
src/{search-popup-row.ui => place-list-row.ui} | 2 +-
src/placeListRow.js | 71 ++++++++++++++++++++++++
src/searchPopup.js | 60 ++------------------
5 files changed, 81 insertions(+), 55 deletions(-)
---
diff --git a/src/gnome-maps.data.gresource.xml b/src/gnome-maps.data.gresource.xml
index 82bdf11..436598b 100644
--- a/src/gnome-maps.data.gresource.xml
+++ b/src/gnome-maps.data.gresource.xml
@@ -6,7 +6,7 @@
<file preprocess="xml-stripblanks">main-window.ui</file>
<file preprocess="xml-stripblanks">zoom-control.ui</file>
<file preprocess="xml-stripblanks">search-popup.ui</file>
- <file preprocess="xml-stripblanks">search-popup-row.ui</file>
+ <file preprocess="xml-stripblanks">place-list-row.ui</file>
<file preprocess="xml-stripblanks">sidebar.ui</file>
<file preprocess="xml-stripblanks">context-menu.ui</file>
<file preprocess="xml-stripblanks">layers-popover.ui</file>
diff --git a/src/gnome-maps.js.gresource.xml b/src/gnome-maps.js.gresource.xml
index ff80c84..33355bc 100644
--- a/src/gnome-maps.js.gresource.xml
+++ b/src/gnome-maps.js.gresource.xml
@@ -22,6 +22,7 @@
<file>place.js</file>
<file>placeEntry.js</file>
<file>placeFormatter.js</file>
+ <file>placeListRow.js</file>
<file>placeStore.js</file>
<file>route.js</file>
<file>routeQuery.js</file>
diff --git a/src/search-popup-row.ui b/src/place-list-row.ui
similarity index 98%
rename from src/search-popup-row.ui
rename to src/place-list-row.ui
index 509e900..7db9cc2 100644
--- a/src/search-popup-row.ui
+++ b/src/place-list-row.ui
@@ -2,7 +2,7 @@
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.12"/>
- <template class="Gjs_SearchPopupRow" parent="GtkListBoxRow">
+ <template class="Gjs_PlaceListRow" parent="GtkListBoxRow">
<property name="visible">True</property>
<child>
<object class="GtkGrid" id="grid">
diff --git a/src/placeListRow.js b/src/placeListRow.js
new file mode 100644
index 0000000..a758213
--- /dev/null
+++ b/src/placeListRow.js
@@ -0,0 +1,71 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * 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>
+ */
+
+const GLib = imports.gi.GLib;
+const Gtk = imports.gi.Gtk;
+const Lang = imports.lang;
+
+const PlaceFormatter = imports.placeFormatter;
+
+const ROW_HEIGHT = 50;
+
+const PlaceListRow = new Lang.Class({
+ Name: 'PlaceListRow',
+ Extends: Gtk.ListBoxRow,
+ Template: 'resource:///org/gnome/maps/place-list-row.ui',
+ InternalChildren: [ 'icon',
+ 'name',
+ 'details' ],
+
+ _init: function(params) {
+ this.place = params.place;
+ delete params.place;
+
+ let searchString = params.searchString || '';
+ delete params.searchString;
+
+ let maxChars = params.maxChars || 40;
+ delete params.maxChars;
+
+ params.height_request = ROW_HEIGHT;
+ this.parent(params);
+
+ let formatter = new PlaceFormatter.PlaceFormatter(this.place);
+ this.title = formatter.title;
+ let markup = GLib.markup_escape_text(formatter.title, -1);
+
+ this._name.label = this._boldMatch(markup, searchString);
+ this._details.max_width_chars = maxChars;
+ this._details.label = formatter.getDetailsString();
+ this._icon.gicon = this.place.icon;
+ },
+
+ _boldMatch: function(title, string) {
+ string = string.toLowerCase();
+
+ let index = title.toLowerCase().indexOf(string);
+
+ if (index !== -1) {
+ let substring = title.substring(index, index + string.length);
+ title = title.replace(substring, substring.bold());
+ }
+ return title;
+ }
+});
diff --git a/src/searchPopup.js b/src/searchPopup.js
index baac607..a48553d 100644
--- a/src/searchPopup.js
+++ b/src/searchPopup.js
@@ -18,60 +18,13 @@
* Author: Jonas Danielsson <jonas threetimestwo org>
*/
-const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
-const GdkPixbuf = imports.gi.GdkPixbuf;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
-const PlaceFormatter = imports.placeFormatter;
-const Utils = imports.utils;
+const PlaceListRow = imports.placeListRow;
const _PLACE_ICON_SIZE = 20;
-const _ROW_HEIGHT = 50;
-
-const SearchPopupRow = new Lang.Class({
- Name: 'SearchPopupRow',
- Extends: Gtk.ListBoxRow,
- Template: 'resource:///org/gnome/maps/search-popup-row.ui',
- InternalChildren: [ 'icon',
- 'name',
- 'details' ],
-
- _init: function(params) {
- this.place = params.place;
- delete params.place;
-
- let searchString = params.searchString;
- delete params.searchString;
-
- let maxChars = params.maxChars || 40;
- delete params.maxChars;
-
- params.height_request = _ROW_HEIGHT;
- this.parent(params);
-
- let formatter = new PlaceFormatter.PlaceFormatter(this.place);
- let title = GLib.markup_escape_text(formatter.title, -1);
-
- this._name.label = this._boldMatch(title, searchString);
- this._details.max_width_chars = maxChars;
- this._details.label = formatter.getDetailsString();
- this._icon.gicon = this.place.icon;
- },
-
- _boldMatch: function(title, string) {
- string = string.toLowerCase();
-
- let index = title.toLowerCase().indexOf(string);
-
- if (index !== -1) {
- let substring = title.substring(index, index + string.length);
- title = title.replace(substring, substring.bold());
- }
- return title;
- }
-});
const SearchPopup = new Lang.Class({
Name: 'SearchPopup',
@@ -109,7 +62,7 @@ const SearchPopup = new Lang.Class({
// NOTE: the magic number 3 makes the scrolled window height be exactly
// aligned with 6 rows.
- this._scrolledWindow.min_content_height = numVisible * _ROW_HEIGHT + 3;
+ this._scrolledWindow.min_content_height = numVisible * PlaceListRow.ROW_HEIGHT + 3;
},
showSpinner: function() {
@@ -147,10 +100,11 @@ const SearchPopup = new Lang.Class({
places.forEach((function(place) {
if (!place.location)
return;
- let row = new SearchPopupRow({ place: place,
- searchString: searchString,
- maxChars: this._maxChars,
- can_focus: true });
+
+ let row = new PlaceListRow.PlaceListRow({ place: place,
+ searchString: searchString,
+ maxChars: this._maxChars,
+ can_focus: true });
this._list.add(row);
}).bind(this));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]