[gnome-maps] routing: Add button to quickly reverse a route search



commit 62d61883893afb7315221984fd0503db1d9f0945
Author: Marcus Lundblad <ml update uu se>
Date:   Sun Jan 22 22:24:26 2017 +0100

    routing: Add button to quickly reverse a route search
    
    Adds a button to reverse a route search.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777559

 data/ui/route-entry.ui |    2 +-
 src/routeEntry.js      |    4 +---
 src/sidebar.js         |   22 ++++++++++++++++++++++
 3 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/data/ui/route-entry.ui b/data/ui/route-entry.ui
index 1f48e1c..40bd08f 100644
--- a/data/ui/route-entry.ui
+++ b/data/ui/route-entry.ui
@@ -32,7 +32,7 @@
     </child>
     <child>
       <object class="GtkButton" id="button">
-        <property name="visible">False</property>
+        <property name="visible">True</property>
         <property name="no_show_all">True</property>
         <property name="can-focus">True</property>
         <property name="valign">center</property>
diff --git a/src/routeEntry.js b/src/routeEntry.js
index 56f6efa..7e9d7f0 100644
--- a/src/routeEntry.js
+++ b/src/routeEntry.js
@@ -68,16 +68,14 @@ const RouteEntry = new Lang.Class({
         case Type.FROM:
             this._buttonImage.icon_name = 'list-add-symbolic';
             this._icon.icon_name = 'maps-point-start-symbolic';
-            this._button.show();
             break;
         case Type.VIA:
             this._buttonImage.icon_name = 'list-remove-symbolic';
             this._icon.icon_name = 'maps-point-end-symbolic';
-            this._button.show();
             break;
         case Type.TO:
+            this._buttonImage.icon_name = 'route-reverse-symbolic';
             this._icon.icon_name = 'maps-point-end-symbolic';
-            this._button.hide();
             break;
         }
     },
diff --git a/src/sidebar.js b/src/sidebar.js
index faaa292..273b1ef 100644
--- a/src/sidebar.js
+++ b/src/sidebar.js
@@ -203,6 +203,9 @@ const Sidebar = new Lang.Class({
                 let row = routeEntry.get_parent();
                 this._query.removePoint(row.get_index());
             }).bind(this));
+        } else if (type === RouteEntry.Type.TO) {
+            routeEntry.button.connect('clicked',
+                                      this._reverseRoutePoints.bind(this));
         }
 
         this._initRouteDragAndDrop(routeEntry);
@@ -424,6 +427,25 @@ const Sidebar = new Lang.Class({
         this._query.thaw_notify();
     },
 
+    /* The reason we don't just use the array .reverse() function is that we
+     * need to update the place parameters on the actual point objects in the
+     * array to fire the query notify signal that will iniate an update.
+     */
+    _reverseRoutePoints: function() {
+        let points = this._query.points;
+        let length = points.length;
+
+        this._query.freeze_notify();
+        for (let i = 0; i < length / 2; i++) {
+            let p1 = points[i].place;
+            let p2 = points[length - i - 1].place;
+
+            points[i].place = p2;
+            points[length - i - 1].place = p1;
+        }
+        this._query.thaw_notify();
+    },
+
     _onDragDrop: function(row, context, x, y, time) {
         let srcIndex = this._query.points.indexOf(this._draggedPoint);
         let destIndex = row.get_index();


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