[gnome-maps/wip/favorites: 5/8] MapBubble: Add favorite button



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

    MapBubble: Add favorite button

 data/gnome-maps.css |    8 ++++++++
 src/main-window.ui  |   21 +++++++++++++++++++++
 src/mapBubble.js    |   28 ++++++++++++++++++++++++++--
 3 files changed, 55 insertions(+), 2 deletions(-)
---
diff --git a/data/gnome-maps.css b/data/gnome-maps.css
index 629d5a6..7fa9a9a 100644
--- a/data/gnome-maps.css
+++ b/data/gnome-maps.css
@@ -2,6 +2,14 @@
     padding: 5px;
 }
 
+#bubble-favorite-button {
+    opacity: 0.45;
+}
+
+#bubble-favorite-button:checked {
+    opacity: 1.0;
+}
+
 .layer-radio-button {
     background-image: none;
     padding: 0px;
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]