[gnome-maps/wip/favorites: 6/9] MapBubble: Add favorite button



commit c9da2c48b2abe768612047fffe4775503cb189c6
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Sat Nov 22 00:55:17 2014 +0100

    MapBubble: Add favorite button
    
    https://bugzilla.gnome.org/show_bug.cgi?id=722102

 src/main-window.ui |   21 +++++++++++++++++++++
 src/mapBubble.js   |   28 ++++++++++++++++++++++++++--
 2 files changed, 47 insertions(+), 2 deletions(-)
---
diff --git a/src/main-window.ui b/src/main-window.ui
index 3e725a8..6094495 100644
--- a/src/main-window.ui
+++ b/src/main-window.ui
@@ -76,6 +76,27 @@
             <property name="pack-type">end</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkMenuButton" id="favorites-button">
+            <property name="visible">True</property>
+            <property name="can-focus">True</property>
+            <property name="valign">center</property>
+            <property name="tooltip-text" translatable="yes">Toggle favorites</property>
+            <style>
+              <class name="image-button"/>
+            </style>
+            <child>
+              <object class="GtkImage" id="favorites-button-image">
+                <property name="visible">True</property>
+                <property name="icon-size">1</property>
+                <property name="icon-name">emblem-favorite-symbolic</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="pack-type">end</property>
+          </packing>
+        </child>
       </object>
     </child>
     <child>
diff --git a/src/mapBubble.js b/src/mapBubble.js
index 4182a6d..e8d2f0a 100644
--- a/src/mapBubble.js
+++ b/src/mapBubble.js
@@ -27,13 +27,16 @@ const Lang = imports.lang;
 const Mainloop = imports.mainloop;
 
 const Application = imports.application;
+const Place = imports.place;
+const PlaceStore = imports.placeStore;
 const ShareDialog = imports.shareDialog;
 const Utils = imports.utils;
 
 const Button = {
     NONE: 0,
     ROUTE: 2,
-    SHARE: 4
+    SHARE: 4,
+    FAVORITE: 8
 };
 
 const MapBubble = new Lang.Class({
@@ -63,7 +66,8 @@ const MapBubble = new Lang.Class({
                                                    'bubble-content-area',
                                                    'bubble-button-area',
                                                    'bubble-route-button',
-                                                   'bubble-share-button' ]);
+                                                   'bubble-share-button',
+                                                   'bubble-favorite-button']);
         this._image = ui.bubbleImage;
         this._content = ui.bubbleContentArea;
 
@@ -74,6 +78,8 @@ const MapBubble = new Lang.Class({
                 this._initRouteButton(ui.bubbleRouteButton, routeFrom);
             if (buttonFlags & Button.SHARE)
                 this._initShareButton(ui.bubbleShareButton);
+            if (buttonFlags & Button.FAVORITE)
+                this._initFavoriteButton(ui.bubbleFavoriteButton);
         }
 
         this.add(ui.bubbleMainGrid);
@@ -91,6 +97,24 @@ const MapBubble = new Lang.Class({
         return this._content;
     },
 
+    _initFavoriteButton: function(button) {
+        let placeStore = Application.placeStore;
+        let isFavorite = placeStore.exists(this._place.osm_id,
+                                           PlaceStore.PlaceType.FAVORITE);
+        button.visible = true;
+        button.active = isFavorite;
+        button.connect('toggled', (function() {
+            let place = new Place.Place({ place: this._place });
+
+            if (button.active)
+                placeStore.addPlace(place,
+                                    PlaceStore.PlaceType.FAVORITE);
+            else
+                placeStore.removePlace(place,
+                                       PlaceStore.PlaceType.FAVORITE);
+        }).bind(this));
+    },
+
     _initShareButton: function(button) {
         let dialog = new ShareDialog.ShareDialog({ transient_for: this.get_toplevel(),
                                                    place: this._place });


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