[gnome-maps] Add a map type changing button in the header bar



commit 4f501e7361fc39ce9f7fc967b1ffb14edb9a7d64
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date:   Fri May 3 03:47:20 2013 +0200

    Add a map type changing button in the header bar
    
    Only expose Street and Satellite for now. Cycling and Transit
    might make sense later on, but probably as vector layers painted on top
    of the map.

 src/main-window.ui |   26 ++++++++++++++++++++++++++
 src/mainWindow.js  |   36 +++++++++++++++++++++++++++++++-----
 2 files changed, 57 insertions(+), 5 deletions(-)
---
diff --git a/src/main-window.ui b/src/main-window.ui
index 1dd6bd8..2e4b4d3 100644
--- a/src/main-window.ui
+++ b/src/main-window.ui
@@ -1,6 +1,20 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
+  <menu id="map-type-menu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">Street</attribute>
+        <attribute name="action">win.map-type</attribute>
+        <attribute name="target">STREET</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">Satellite</attribute>
+        <attribute name="action">win.map-type</attribute>
+        <attribute name="target">AERIAL</attribute>
+      </item>
+    </section>
+  </menu>
   <object class="GtkGrid" id="window-content">
     <property name="visible">True</property>
     <property name="orientation">vertical</property>
@@ -24,6 +38,18 @@
             <property name="pack_type">start</property>
           </packing>
         </child>
+        <child>
+          <object class="GdHeaderMenuButton" id="layer-menu-button">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="symbolic-icon-name">emblem-system-symbolic</property>
+            <property name="menu-model">map-type-menu</property>
+            <property name="action_name">win.map-type-menu</property>
+          </object>
+          <packing>
+            <property name="pack_type">end</property>
+          </packing>
+        </child>
       </object>
     </child>
   </object>
diff --git a/src/mainWindow.js b/src/mainWindow.js
index f101306..6cb3ee5 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -55,10 +55,25 @@ const MainWindow = new Lang.Class({
                                                   hide_titlebar_when_maximized: true,
                                                   title: _("Maps") });
 
-        Utils.initActions(this.window, [{ 
-            properties: { name: 'about' }, 
-            signalHandlers: { activate: this._onAboutActivate }
-        }], this.window);
+        Utils.initActions(this.window, [
+            { 
+                properties: { name: 'about' }, 
+                signalHandlers: { activate: this._onAboutActivate }
+            }, {
+                properties: {
+                    name: 'map-type-menu', 
+                    state: GLib.Variant.new('b', false)
+                },
+                signalHandlers: { activate: this._onMapTypeMenuActivate }
+            }, {
+                properties: {
+                    name: 'map-type',
+                    parameter_type: GLib.VariantType.new('s'),
+                    state: GLib.Variant.new('s', 'STREET')
+                },
+                signalHandlers: { activate: this._onMapTypeActivate }
+            }
+        ], this);
 
         // apply the last saved window size and position
         let size = Application.settings.get_value('window-size');
@@ -200,6 +215,17 @@ const MainWindow = new Lang.Class({
         return false;
     },
 
+    _onMapTypeMenuActivate: function(action) {
+        let state = action.get_state().get_boolean();
+        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]);
+    },
+
     _onAboutActivate: function() {
         let aboutDialog = new Gtk.AboutDialog();
 
@@ -217,7 +243,7 @@ const MainWindow = new Lang.Class({
         aboutDialog.wrap_license = true;
 
         aboutDialog.modal = true;
-        aboutDialog.transient_for = this;
+        aboutDialog.transient_for = this.window;
 
         aboutDialog.show();
         aboutDialog.connect('response', function() {


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