[gnome-maps/wip/mlundblad/osm-add-location: 1/3] Introduce an abstract base class for search result popovers



commit 36872f977b9640df49bdf5c17c6689bce408f137
Author: Marcus Lundblad <ml update uu se>
Date:   Sun Jan 31 11:55:54 2016 +0100

    Introduce an abstract base class for search result popovers
    
    https://bugzilla.gnome.org/show_bug.cgi?id=761327

 data/org.gnome.Maps.data.gresource.xml        |    2 +-
 data/ui/{search-popup.ui => place-popover.ui} |    2 +-
 po/POTFILES.in                                |    2 +-
 src/org.gnome.Maps.src.gresource.xml          |    3 +-
 src/placeEntry.js                             |    8 +-
 src/{searchPopup.js => placePopover.js}       |   80 +-----------------
 src/searchPopover.js                          |  112 +++++++++++++++++++++++++
 7 files changed, 126 insertions(+), 83 deletions(-)
---
diff --git a/data/org.gnome.Maps.data.gresource.xml b/data/org.gnome.Maps.data.gresource.xml
index a895e11..81dc771 100644
--- a/data/org.gnome.Maps.data.gresource.xml
+++ b/data/org.gnome.Maps.data.gresource.xml
@@ -21,8 +21,8 @@
     <file preprocess="xml-stripblanks">ui/place-bubble.ui</file>
     <file preprocess="xml-stripblanks">ui/place-entry.ui</file>
     <file preprocess="xml-stripblanks">ui/place-list-row.ui</file>
+    <file preprocess="xml-stripblanks">ui/place-popover.ui</file>
     <file preprocess="xml-stripblanks">ui/route-entry.ui</file>
-    <file preprocess="xml-stripblanks">ui/search-popup.ui</file>
     <file preprocess="xml-stripblanks">ui/send-to-dialog.ui</file>
     <file preprocess="xml-stripblanks">ui/sidebar.ui</file>
     <file preprocess="xml-stripblanks">ui/social-place-more-results-row.ui</file>
diff --git a/data/ui/search-popup.ui b/data/ui/place-popover.ui
similarity index 97%
rename from data/ui/search-popup.ui
rename to data/ui/place-popover.ui
index ae7d839..adf2f89 100644
--- a/data/ui/search-popup.ui
+++ b/data/ui/place-popover.ui
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.10 -->
-  <template class="Gjs_SearchPopup" parent="GtkPopover">
+  <template class="Gjs_PlacePopover" parent="Gjs_SearchPopover">
     <property name="visible">False</property>
     <property name="hexpand">False</property>
     <property name="modal">False</property>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c60da7f..419b841 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -13,7 +13,7 @@ data/org.gnome.Maps.gschema.xml
 [type: gettext/glade]data/ui/map-bubble.ui
 [type: gettext/glade]data/ui/osm-account-dialog.ui
 [type: gettext/glade]data/ui/osm-edit-dialog.ui
-[type: gettext/glade]data/ui/search-popup.ui
+[type: gettext/glade]data/ui/place-popover.ui
 [type: gettext/glade]data/ui/send-to-dialog.ui
 [type: gettext/glade]data/ui/shape-layer-file-chooser.ui
 [type: gettext/glade]data/ui/shape-layer-row.ui
diff --git a/src/org.gnome.Maps.src.gresource.xml b/src/org.gnome.Maps.src.gresource.xml
index 4f7fd3a..ba3150c 100644
--- a/src/org.gnome.Maps.src.gresource.xml
+++ b/src/org.gnome.Maps.src.gresource.xml
@@ -45,12 +45,13 @@
     <file>placeFormatter.js</file>
     <file>placeListRow.js</file>
     <file>placeMarker.js</file>
+    <file>placePopover.js</file>
     <file>placeStore.js</file>
     <file>route.js</file>
     <file>routeEntry.js</file>
     <file>routeQuery.js</file>
     <file>routeService.js</file>
-    <file>searchPopup.js</file>
+    <file>searchPopover.js</file>
     <file>serviceBackend.js</file>
     <file>settings.js</file>
     <file>sendToDialog.js</file>
diff --git a/src/placeEntry.js b/src/placeEntry.js
index b4df702..eee769f 100644
--- a/src/placeEntry.js
+++ b/src/placeEntry.js
@@ -31,7 +31,7 @@ const Application = imports.application;
 const Location = imports.location;
 const Place = imports.place;
 const PlaceStore = imports.placeStore;
-const SearchPopup = imports.searchPopup;
+const PlacePopover = imports.placePopover;
 const Utils = imports.utils;
 
 const PlaceEntry = new Lang.Class({
@@ -137,9 +137,9 @@ const PlaceEntry = new Lang.Class({
     },
 
     _createPopover: function(numVisible, maxChars) {
-        let popover = new SearchPopup.SearchPopup({ num_visible:   numVisible,
-                                                    relative_to:   this,
-                                                    maxChars:      maxChars});
+        let popover = new PlacePopover.PlacePopover({ num_visible:   numVisible,
+                                                      relative_to:   this,
+                                                      maxChars:      maxChars});
 
         this.connect('size-allocate', (function(widget, allocation) {
             // Magic number to make the alignment pixel perfect.
diff --git a/src/searchPopup.js b/src/placePopover.js
similarity index 69%
rename from src/searchPopup.js
rename to src/placePopover.js
index dd33ae1..fbe94fb 100644
--- a/src/searchPopup.js
+++ b/src/placePopover.js
@@ -17,7 +17,6 @@
  * Author: Jonas Danielsson <jonas threetimestwo org>
  */
 
-const Gdk = imports.gi.Gdk;
 const GObject = imports.gi.GObject;
 const Gtk = imports.gi.Gtk;
 const Lang = imports.lang;
@@ -25,6 +24,7 @@ const Lang = imports.lang;
 const Application = imports.application;
 const PlaceListRow = imports.placeListRow;
 const PlaceStore = imports.placeStore;
+const SearchPopover = imports.searchPopover;
 
 const _PLACE_ICON_SIZE = 20;
 
@@ -35,13 +35,13 @@ const Mode = {
     RESULT: 3 // We are displaying results
 };
 
-const SearchPopup = new Lang.Class({
-    Name: 'SearchPopup',
-    Extends: Gtk.Popover,
+const PlacePopover = new Lang.Class({
+    Name: 'PlacePopover',
+    Extends: SearchPopover.SearchPopover,
     Signals : {
         'selected' : { param_types: [ GObject.TYPE_OBJECT ] }
     },
-    Template: 'resource:///org/gnome/Maps/ui/search-popup.ui',
+    Template: 'resource:///org/gnome/Maps/ui/place-popover.ui',
     InternalChildren: [ 'hintRevealer',
                         'scrolledWindow',
                         'stack',
@@ -81,14 +81,6 @@ const SearchPopup = new Lang.Class({
         this._list.connect('selected-rows-changed',
                            this._updateHint.bind(this));
 
-        // We need to propagate events to the listbox so that we can
-        // keep typing while selecting a place. But we do not want to
-        // propagate the 'enter' key press if there is a selection.
-        this._entry.connect('key-press-event',
-                            this._propagateKeys.bind(this));
-        this._entry.connect('button-press-event',
-                            this._list.unselect_all.bind(this._list));
-
         this._list.set_header_func(function(row, before) {
             let header = new Gtk.Separator();
             if (before)
@@ -193,67 +185,5 @@ const SearchPopup = new Lang.Class({
             this._hintRevealer.reveal_child = false;
         else
             this._hintRevealer.reveal_child = true;
-    },
-
-    _propagateKeys: function(entry, event) {
-        let row;
-
-        if (this.visible) {
-            row = this._list.get_selected_row();
-            if (!row)
-                row = this._list.get_row_at_index(0);
-        } else
-            row = this._list.get_row_at_index(0);
-
-        if (!row)
-            return false;
-
-        let length = this._list.get_children().length;
-        let keyval = event.get_keyval()[1];
-
-        if (keyval === Gdk.KEY_Escape) {
-            this._list.unselect_all();
-            this.hide();
-            return false;
-        }
-
-        // If we get an 'enter' keypress and we have a selected
-        // row, we do not want to propagate the event.
-        if ((this.visible && row.is_selected()) &&
-            keyval === Gdk.KEY_Return ||
-            keyval === Gdk.KEY_KP_ENTER ||
-            keyval === Gdk.KEY_ISO_Enter) {
-            row.activate();
-
-            return true;
-        } else if (keyval === Gdk.KEY_KP_Up || keyval === Gdk.KEY_Up) {
-            this.show();
-
-            if (!row.is_selected()) {
-                let pRow = this._list.get_row_at_index(length - 1);
-                this._list.select_row(pRow);
-                return false;
-            }
-
-            if (row.get_index() > 0) {
-                let pRow = this._list.get_row_at_index(row.get_index() - 1);
-                this._list.select_row(pRow);
-            } else
-                this._list.unselect_all();
-        } else if (keyval === Gdk.KEY_KP_Down || keyval === Gdk.KEY_Down) {
-            this.show();
-
-            if (!row.is_selected()) {
-                this._list.select_row(row);
-                return false;
-            }
-
-            if (row.get_index() !== (length - 1)) {
-                let nRow = this._list.get_row_at_index(row.get_index() + 1);
-                this._list.select_row(nRow);
-            } else
-                this._list.unselect_all();
-        }
-        return false;
     }
 });
diff --git a/src/searchPopover.js b/src/searchPopover.js
new file mode 100644
index 0000000..03c47e9
--- /dev/null
+++ b/src/searchPopover.js
@@ -0,0 +1,112 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2016 Marcus Lundblad.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Marcus Lundblad <ml update uu se>
+ *         Jonas Danielsson <jonas threetimestwo org>
+ */
+
+const Gdk = imports.gi.Gdk;
+const GObject = imports.gi.GObject;
+const Gtk = imports.gi.Gtk;
+const Lang = imports.lang;
+
+/* Abstract search result popover that progagates keypress events from a
+   focus-taking internal widget to the spawning search entry widget */
+const SearchPopover = new Lang.Class({
+    Name: 'SearchPopover',
+    Extends: Gtk.Popover,
+    Abstract: true,
+
+    _init: function(props) {
+        this.parent(props);
+
+        this._entry = this.relative_to;
+
+        // We need to propagate events to the listbox so that we can
+        // keep typing while selecting a place. But we do not want to
+        // propagate the 'enter' key press if there is a selection.
+        this._entry.connect('key-press-event',
+                            this._propagateKeys.bind(this));
+        this._entry.connect('button-press-event',
+                            this._list.unselect_all.bind(this._list));
+    },
+
+    _propagateKeys: function(entry, event) {
+        let row;
+
+        if (this.visible) {
+            row = this._list.get_selected_row();
+            if (!row)
+                row = this._list.get_row_at_index(0);
+        } else
+            row = this._list.get_row_at_index(0);
+
+        if (!row)
+            return false;
+
+        let length = this._list.get_children().length;
+        let keyval = event.get_keyval()[1];
+
+        if (keyval === Gdk.KEY_Escape) {
+            this._list.unselect_all();
+            this.hide();
+            return false;
+        }
+
+        // If we get an 'enter' keypress and we have a selected
+        // row, we do not want to propagate the event.
+        if ((this.visible && row.is_selected()) &&
+            keyval === Gdk.KEY_Return ||
+            keyval === Gdk.KEY_KP_ENTER ||
+            keyval === Gdk.KEY_ISO_Enter) {
+            row.activate();
+
+            return true;
+        } else if (keyval === Gdk.KEY_KP_Up || keyval === Gdk.KEY_Up) {
+            this.show();
+
+            if (!row.is_selected()) {
+                let pRow = this._list.get_row_at_index(length - 1);
+                this._list.select_row(pRow);
+                return false;
+            }
+
+            if (row.get_index() > 0) {
+                let pRow = this._list.get_row_at_index(row.get_index() - 1);
+                this._list.select_row(pRow);
+            } else
+                this._list.unselect_all();
+        } else if (keyval === Gdk.KEY_KP_Down || keyval === Gdk.KEY_Down) {
+            this.show();
+
+            if (!row.is_selected()) {
+                this._list.select_row(row);
+                return true;
+            }
+
+            if (row.get_index() !== (length - 1)) {
+                let nRow = this._list.get_row_at_index(row.get_index() + 1);
+                this._list.select_row(nRow);
+            } else
+                this._list.unselect_all();
+            return true;
+        }
+        return false;
+    }
+});
+


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