[gnome-maps] mainWindow, mapView: Add keyboard shortcuts to switch map mode



commit e890bd96fae3f89b36f9ff6ebc47eb9c6325e03a
Author: Marcus Lundblad <ml update uu se>
Date:   Tue Apr 18 23:02:04 2017 +0200

    mainWindow,mapView: Add keyboard shortcuts to switch map mode
    
    Added shortcuts to switch between street and aerial views.
    Manually update the state of the layer switcher buttons to avoid
    recursive signal emissions.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=759574

 data/ui/layers-popover.ui |    4 ----
 src/layersPopover.js      |   16 ++++++++++++++++
 src/mainWindow.js         |   23 +++++++++++++++--------
 src/mapView.js            |    4 +++-
 4 files changed, 34 insertions(+), 13 deletions(-)
---
diff --git a/data/ui/layers-popover.ui b/data/ui/layers-popover.ui
index a33f17d..573c364 100644
--- a/data/ui/layers-popover.ui
+++ b/data/ui/layers-popover.ui
@@ -13,8 +13,6 @@
           <object class="GtkRadioButton" id="streetLayerButton">
             <property name="visible">True</property>
             <property name="can-focus">True</property>
-            <property name="action-name">win.map-type</property>
-            <property name="action-target">"STREET"</property>
             <property name="draw-indicator">False</property>
             <style>
               <class name="layer-radio-button"/>
@@ -35,8 +33,6 @@
           <object class="GtkRadioButton" id="aerialLayerButton">
             <property name="visible">True</property>
             <property name="can-focus">True</property>
-            <property name="action-name">win.map-type</property>
-            <property name="action-target">"AERIAL"</property>
             <property name="draw-indicator">False</property>
             <style>
               <class name="layer-radio-button"/>
diff --git a/src/layersPopover.js b/src/layersPopover.js
index f37109f..37e4450 100644
--- a/src/layersPopover.js
+++ b/src/layersPopover.js
@@ -20,6 +20,7 @@
 const Gtk = imports.gi.Gtk;
 const Lang = imports.lang;
 
+const MapView = imports.mapView;
 const ShapeLayer = imports.shapeLayer;
 const Utils = imports.utils;
 
@@ -109,6 +110,21 @@ const LayersPopover = new Lang.Class({
 
         this._loadLayerButton.connect('clicked',
                                       this._onLoadLayerClicked.bind(this));
+
+        this._streetLayerButton.connect('clicked', (function () {
+            this._mapView.setMapType(MapView.MapType.STREET);
+        }).bind(this));
+
+        this._aerialLayerButton.connect('clicked', (function () {
+            this._mapView.setMapType(MapView.MapType.AERIAL);
+        }).bind(this));
+    },
+
+    setMapType: function(mapType) {
+        if (mapType === MapView.MapType.STREET)
+            this._streetLayerButton.active = true;
+        else if (mapType === MapView.MapType.AERIAL)
+            this._aerialLayerButton.active = true;
     },
 
     _onRemoveClicked: function(row, button) {
diff --git a/src/mainWindow.js b/src/mainWindow.js
index eb9755e..cfbd438 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -176,10 +176,13 @@ const MainWindow = new Lang.Class({
                 state: ['b', false],
                 onActivate: this._onMapTypeMenuActivate.bind(this)
             },
-            'map-type': {
-                paramType: 's',
-                state: ['s', 'STREET'],
-                onActivate: this._onMapTypeActivate.bind(this)
+            'switch-to-street-view': {
+                accels: ['<Primary>1', '<Primary>KP_1'],
+                onActivate: this._onStreetViewActivate.bind(this)
+            },
+            'switch-to-aearial-view': {
+                accels: ['<Primary>2', '<Primary>KP_2'],
+                onActivate: this._onAerialViewActivate.bind(this)
             },
             'goto-user-location': {
                 accels: ['<Primary>L'],
@@ -411,10 +414,14 @@ const MainWindow = new Lang.Class({
         action.set_state(GLib.Variant.new('b', !state));
     },
 
-    _onMapTypeActivate: function(action, value) {
-        action.set_state(value);
-        let [mapType, len] = value.get_string();
-        this._mapView.setMapType(MapView.MapType[mapType]);
+    _onStreetViewActivate: function() {
+        this._mapView.setMapType(MapView.MapType.STREET);
+        this.layersPopover.setMapType(MapView.MapType.STREET);
+    },
+
+    _onAerialViewActivate: function() {
+        this._mapView.setMapType(MapView.MapType.AERIAL);
+        this.layersPopover.setMapType(MapView.MapType.AERIAL);
     },
 
     _onToggleSidebarChangeState: function(action, variant) {
diff --git a/src/mapView.js b/src/mapView.js
index d19b6f5..2658b3e 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -296,11 +296,13 @@ const MapView = new Lang.Class({
     },
 
     setMapType: function(mapType) {
-        if (this.view.map_source.id === mapType)
+        if (this._mapType === mapType)
             return;
 
         let overlay_sources = this.view.get_overlay_sources();
 
+        this._mapType = mapType;
+
         if (mapType !== MapType.LOCAL) {
             if (mapType === MapType.AERIAL)
                 this.view.map_source = MapSource.createAerialSource();


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