[gnome-maps/wip/osm-edit: 16/16] osmEdit: Hook up edit button in the place bubble.



commit 6645f4df4de6fe9ab80f952cbf047372f1f8839e
Author: Marcus Lundblad <ml update uu se>
Date:   Mon Oct 19 21:47:01 2015 +0200

    osmEdit: Hook up edit button in the place bubble.
    
    Add the Edit button (this should later be reworked to invoke the account
    setup if the user has not yet added an OSM account).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=726628

 src/application.js |    3 +++
 src/mapBubble.js   |    7 +++++--
 src/placeBubble.js |   44 +++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 51 insertions(+), 3 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 292c46c..51fa37f 100644
--- a/src/application.js
+++ b/src/application.js
@@ -35,6 +35,7 @@ const GeocodeService = imports.geocodeService;
 const MainWindow = imports.mainWindow;
 const Maps = imports.gi.GnomeMaps;
 const NotificationManager = imports.notificationManager;
+const OSMEdit = imports.osmEdit;
 const PlaceStore = imports.placeStore;
 const RouteService = imports.routeService;
 const Settings = imports.settings;
@@ -51,6 +52,7 @@ let geocodeService = null;
 let networkMonitor = null;
 let checkInManager = null;
 let contactStore = null;
+let osmEditManager = null;
 
 const Application = new Lang.Class({
     Name: 'Application',
@@ -225,6 +227,7 @@ const Application = new Lang.Class({
         checkInManager = new CheckIn.CheckInManager();
         contactStore = new Maps.ContactStore();
         contactStore.load();
+       osmEditManager = new OSMEdit.OSMEditManager();
     },
 
     _createWindow: function() {
diff --git a/src/mapBubble.js b/src/mapBubble.js
index 0d67414..dd15b24 100644
--- a/src/mapBubble.js
+++ b/src/mapBubble.js
@@ -37,7 +37,8 @@ const Button = {
     ROUTE: 2,
     SEND_TO: 4,
     FAVORITE: 8,
-    CHECK_IN: 16
+    CHECK_IN: 16,
+    EDIT: 32
 };
 
 const MapBubble = new Lang.Class({
@@ -75,9 +76,11 @@ const MapBubble = new Lang.Class({
                                                    'bubble-route-button',
                                                    'bubble-send-to-button',
                                                    'bubble-favorite-button',
-                                                   'bubble-check-in-button']);
+                                                   'bubble-check-in-button',
+                                                   'bubble-edit-button']);
         this._image = ui.bubbleImage;
         this._content = ui.bubbleContentArea;
+        this._editButton = ui.bubbleEditButton;
 
         if (!buttonFlags)
             ui.bubbleButtonArea.visible = false;
diff --git a/src/placeBubble.js b/src/placeBubble.js
index 4759b68..89b8a21 100644
--- a/src/placeBubble.js
+++ b/src/placeBubble.js
@@ -26,6 +26,8 @@ const Lang = imports.lang;
 const Application = imports.application;
 const ContactPlace = imports.contactPlace;
 const MapBubble = imports.mapBubble;
+const OSMEditDialog = imports.osmEditDialog;
+const OSMUtils = imports.osmUtils;
 const Overpass = imports.overpass;
 const Place = imports.place;
 const PlaceFormatter = imports.placeFormatter;
@@ -41,7 +43,8 @@ const PlaceBubble = new Lang.Class({
                                                      'box-content',
                                                      'label-title']);
         params.buttons = (MapBubble.Button.ROUTE |
-                          MapBubble.Button.SEND_TO);
+                          MapBubble.Button.SEND_TO |
+                         MapBubble.Button.EDIT);
 
         if (params.place.store)
             params.buttons |= MapBubble.Button.FAVORITE;
@@ -79,6 +82,8 @@ const PlaceBubble = new Lang.Class({
             this._populate(this.place);
         }
         this.content.add(this._stack);
+
+       this._initEditButton(this._editButton);
     },
 
     _formatWikiLink: function(wiki) {
@@ -134,5 +139,42 @@ const PlaceBubble = new Lang.Class({
         }).bind(this));
 
         this._stack.visible_child = this._boxContent;
+    },
+
+    // clear the view widgets to be able to re-populate an updated place
+    _clearView: function() {
+           let widgets = this._boxContent.get_children();
+
+           // remove the dynamically added content, the title label
+           // has position 0 in the box
+           for (let i = 1; i < widgets.length; i++) {
+               this._boxContent.remove(widgets[i]);
+           }
+    },
+
+    _initEditButton: function(button) {
+           button.visible = true;
+           button.connect('clicked', this._onEditClicked.bind(this));
+    },
+
+    _onEditClicked: function() {
+           let response =
+               Application.osmEditManager.showEditDialog(this.get_toplevel(),
+                                                                             this._place);
+
+           switch (response) {
+           case OSMEditDialog.Response.UPLOADED:
+               if (!Application.osmEditManager.useTestApi) {
+                       // update place
+                       let osmObject = Application.osmEditManager.osmObject;
+                       OSMUtils.updatePlaceFromOSMObject(this._place, osmObject);
+                       // refresh place view
+                       this._clearView();
+                       this._populate(this._place);
+               }
+               break;
+           default:
+               break;
+           }
     }
 });


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