[gnome-maps/wip/favorites: 4/8] Add FavoritesPopover
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/favorites: 4/8] Add FavoritesPopover
- Date: Sat, 22 Nov 2014 20:16:25 +0000 (UTC)
commit eda8159cde0f44b0efea099ab8a9f2da3757c197
Author: Jonas Danielsson <jonas threetimestwo org>
Date: Sat Nov 22 00:53:33 2014 +0100
Add FavoritesPopover
https://bugzilla.gnome.org/show_bug.cgi?id=722102
src/favorites-popover.ui | 65 ++++++++++++++++++++
src/favoritesPopover.js | 120 +++++++++++++++++++++++++++++++++++++
src/gnome-maps.data.gresource.xml | 1 +
src/gnome-maps.js.gresource.xml | 1 +
4 files changed, 187 insertions(+), 0 deletions(-)
---
diff --git a/src/favorites-popover.ui b/src/favorites-popover.ui
new file mode 100644
index 0000000..5eaea53
--- /dev/null
+++ b/src/favorites-popover.ui
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.10 -->
+ <template class="Gjs_FavoritesPopover" parent="GtkPopover">
+ <property name="visible">False</property>
+ <property name="no_show_all">True</property>
+ <property name="hexpand">False</property>
+ <style>
+ <class name="maps-popover"/>
+ </style>
+ <child>
+ <object class="GtkStack" id="stack">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="homogeneous">False</property>
+ <child>
+ <object class="GtkGrid" id="mainGrid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkRevealer" id="revealer">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkEntry" id="entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="margin">10</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow" id="scrolledWindow">
+ <property name="hscrollbar_policy">never</property>
+ <property name="shadow_type">in</property>
+ <property name="visible">True</property>
+ <child>
+ <object class="GtkListBox" id="list">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="expand">True</property>
+ <property name="activate_on_single_click">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="noFavoritesLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin">10</property>
+ <property name="label" translatable="yes">You have no favorite places yet!</property>
+ <style>
+ <class name="dim-label"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/favoritesPopover.js b/src/favoritesPopover.js
new file mode 100644
index 0000000..3976987
--- /dev/null
+++ b/src/favoritesPopover.js
@@ -0,0 +1,120 @@
+/* -*- 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 Gtk = imports.gi.Gtk;
+const Lang = imports.lang;
+
+const Application = imports.application;
+const PlaceListRow = imports.placeListRow;
+const PlaceStore = imports.placeStore;
+
+const _N_VISIBLE = 6;
+const _ROW_HEIGHT = 50;
+
+const FavoritesPopover = new Lang.Class({
+ Name: 'FavoritesPopover',
+ Extends: Gtk.Popover,
+ Template: 'resource:///org/gnome/maps/favorites-popover.ui',
+ InternalChildren: [ 'stack',
+ 'mainGrid',
+ 'revealer',
+ 'entry',
+ 'scrolledWindow',
+ 'list',
+ 'noFavoritesLabel'],
+ Signals: { 'rows-changed': { } },
+
+ _init: function(params) {
+ params = params || { };
+
+ this._mapView = params.mapView;
+ delete params.mapView;
+
+ this.parent(params);
+
+ this._rows = 0;
+
+ let placeType = PlaceStore.PlaceType.FAVORITE;
+ this._model = Application.placeStore.getModelForPlaceType(placeType);
+
+ this._model.connect('row-deleted',
+ this._updateList.bind(this));
+ this._model.connect('row-inserted',
+ this._updateList.bind(this));
+
+ this._list.set_header_func(function(row, before) {
+ let header = before ? new Gtk.Separator() : null;
+ row.set_header(header);
+ });
+
+ this._entry.connect('changed',
+ this._list.invalidate_filter.bind(this._list));
+
+ this._list.connect('row-activated', (function(list, row) {
+ this.hide();
+ this._mapView.showSearchResult(row.place);
+ }).bind(this));
+
+ this._list.set_filter_func((function(row) {
+ let text = this._entry.text.toLowerCase();
+ let title = row.title.toLowerCase();
+ let length = text.length;
+
+ return title.substring(0, length) === text.substring(0, length);
+ }).bind(this));
+
+ this._updateList();
+ },
+
+ get rows() {
+ return this._rows;
+ },
+
+ _updateList: function() {
+ this._list.forall(function(row) {
+ row.destroy();
+ });
+
+ this._rows = 0;
+ this._model.foreach((function(model, path, iter) {
+ let place = model.get_value(iter, PlaceStore.Columns.PLACE);
+
+ let row = new PlaceListRow.PlaceListRow({ place: place,
+ maxChars: 15,
+ can_focus: true });
+ this._list.add(row);
+ this._rows++;
+ }).bind(this));
+
+ if (this._rows === 0) {
+ this._stack.visible_child = this._noFavoritesLabel;
+ } else {
+ this._stack.visible_child = this._mainGrid;
+ let visible = Math.min(this._rows, _N_VISIBLE);
+
+ this._scrolledWindow.min_content_height = visible * PlaceListRow.ROW_HEIGHT + 3;
+ if (this._rows > _N_VISIBLE)
+ this._revealer.reveal_child = true;
+ else
+ this._revealer.reveal_child = false;
+ }
+ this.emit('rows-changed');
+ }
+});
diff --git a/src/gnome-maps.data.gresource.xml b/src/gnome-maps.data.gresource.xml
index 436598b..0512a79 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">favorites-popover.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>
diff --git a/src/gnome-maps.js.gresource.xml b/src/gnome-maps.js.gresource.xml
index 33355bc..ce962cc 100644
--- a/src/gnome-maps.js.gresource.xml
+++ b/src/gnome-maps.js.gresource.xml
@@ -5,6 +5,7 @@
<file>config.js</file>
<file>contextMenu.js</file>
<file>epaf.js</file>
+ <file>favoritesPopover.js</file>
<file>geoclue.js</file>
<file>geocodeService.js</file>
<file>http.js</file>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]