[gnome-maps/wip/mlundblad/osm-add-location: 6/6] osmEdit: WIP: Add a context menu item for adding locations



commit eb2c683be95005aa131edc180b816c67b4087bfd
Author: Marcus Lundblad <ml update uu se>
Date:   Mon Dec 21 22:01:03 2015 +0100

    osmEdit: WIP: Add a context menu item for adding locations
    
    Launches the OSM edit dialog in add new location mode.

 data/ui/context-menu.ui |    7 +++++++
 src/contextMenu.js      |   27 ++++++++++++++++++++++++++-
 src/osmEdit.js          |   12 ++++++++++++
 3 files changed, 45 insertions(+), 1 deletions(-)
---
diff --git a/data/ui/context-menu.ui b/data/ui/context-menu.ui
index b968616..36a9b25 100644
--- a/data/ui/context-menu.ui
+++ b/data/ui/context-menu.ui
@@ -24,5 +24,12 @@
         <property name="visible">True</property>
       </object>
     </child>
+    <child>
+      <object class="GtkMenuItem" id="addOSMLocationItem">
+        <property name="name">add-osm-location-item</property>
+        <property name="label" translatable="yes">Add Location</property>
+        <property name="visible">True</property>
+      </object>
+    </child>
   </template>
 </interface>
diff --git a/src/contextMenu.js b/src/contextMenu.js
index 39633b1..154c41f 100644
--- a/src/contextMenu.js
+++ b/src/contextMenu.js
@@ -30,6 +30,9 @@ const Application = imports.application;
 const ExportViewDialog = imports.exportViewDialog;
 const Lang = imports.lang;
 const Location = imports.location;
+const OSMAccountDialog = imports.osmAccountDialog;
+const OSMEdit = imports.osmEdit;
+const OSMEditDialog = imports.osmEditDialog;
 const Utils = imports.utils;
 
 const ContextMenu = new Lang.Class({
@@ -38,7 +41,8 @@ const ContextMenu = new Lang.Class({
     Template: 'resource:///org/gnome/Maps/ui/context-menu.ui',
     InternalChildren: [ 'whatsHereItem',
                         'geoURIItem',
-                        'exportItem' ],
+                        'exportItem',
+                        'addOSMLocationItem' ],
 
     _init: function(params) {
         this._mapView = params.mapView;
@@ -55,6 +59,8 @@ const ContextMenu = new Lang.Class({
                                  this._onGeoURIActivated.bind(this));
         this._exportItem.connect('activate',
                                  this._onExportActivated.bind(this));
+        this._addOSMLocationItem.connect('activate',
+                                         this._onAddOSMLocationActivated.bind(this));
     },
 
     _onButtonReleaseEvent: function(actor, event) {
@@ -92,6 +98,25 @@ const ContextMenu = new Lang.Class({
         clipboard.set_text(uri, uri.length);
     },
 
+    _onAddOSMLocationActivated: function() {
+        let osmEdit = Application.osmEdit;
+        /* if the user is not alread signed in, show the account dialog */
+        if (!osmEdit.isSignedIn) {
+            let response = osmEdit.showAccountDialog(this.get_toplevel(), true);
+            if (!response === OSMAccountDialog.Response.SIGNED_IN)
+                return;
+        }
+
+        let response =
+            osmEdit.showEditNewDialog(this.get_toplevel(),
+                                      this._latitude, this._longitude);
+        /* TODO: should we create a location in the location store, and maybe
+           show a place marker (on success)? */
+        if (response === OSMEditDialog.Response.UPLOADED) {
+            /* TODO: show a notification on success */
+        }
+    },
+
     _activateExport: function() {
         let view = this._mapView.view;
         let surface = view.to_surface(true);
diff --git a/src/osmEdit.js b/src/osmEdit.js
index 62f15d5..5d911c6 100644
--- a/src/osmEdit.js
+++ b/src/osmEdit.js
@@ -54,6 +54,18 @@ const OSMEdit = new Lang.Class({
         return response;
     },
 
+    showEditNewDialog: function(parentWindow, latitude, longitude) {
+        let dialog = new OSMEditDialog.OSMEditDialog({
+            transient_for: parentWindow,
+            addLocation: true,
+            latitude: latitude,
+            longitude: longitude
+        });
+        let response = dialog.run();
+        dialog.destroy();
+        return response;
+    },
+
     showAccountDialog: function(parentWindow, closeOnSignIn) {
         let dialog = new OSMAccountDialog.OSMAccountDialog({
             transient_for: parentWindow,


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