[gnome-maps/wip/mlundblad/osm-add-location: 6/6] osmEdit: WIP: Add a context menu item for adding locations
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/osm-add-location: 6/6] osmEdit: WIP: Add a context menu item for adding locations
- Date: Sat, 23 Jan 2016 16:12:09 +0000 (UTC)
commit 554fbdb81b75c8fd5f2921f462f2e07d2850cc0a
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.
Offer to zoom in if the zoom level is not one the two
innermost ones.
data/org.gnome.Maps.data.gresource.xml | 1 +
data/ui/context-menu.ui | 7 ++++
data/ui/place-bubble.ui | 2 +-
data/ui/zoom-in-notification.ui | 25 ++++++++++++++
src/contextMenu.js | 44 ++++++++++++++++++++++++-
src/org.gnome.Maps.src.gresource.xml | 1 +
src/osmEdit.js | 12 +++++++
src/osmUtils.js | 3 ++
src/zoomInNotification.js | 57 ++++++++++++++++++++++++++++++++
9 files changed, 150 insertions(+), 2 deletions(-)
---
diff --git a/data/org.gnome.Maps.data.gresource.xml b/data/org.gnome.Maps.data.gresource.xml
index 36e71bd..d24532c 100644
--- a/data/org.gnome.Maps.data.gresource.xml
+++ b/data/org.gnome.Maps.data.gresource.xml
@@ -32,6 +32,7 @@
<file preprocess="xml-stripblanks">ui/social-place-row.ui</file>
<file preprocess="xml-stripblanks">ui/user-location-bubble.ui</file>
<file preprocess="xml-stripblanks">ui/zoom-control.ui</file>
+ <file preprocess="xml-stripblanks">ui/zoom-in-notification.ui</file>
<file alias="application.css">gnome-maps.css</file>
<file alias="ui/maptype-aerial.png">media/maptype-aerial.png</file>
<file alias="ui/maptype-street.png">media/maptype-street.png</file>
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/data/ui/place-bubble.ui b/data/ui/place-bubble.ui
index fa37801..5c2f97d 100644
--- a/data/ui/place-bubble.ui
+++ b/data/ui/place-bubble.ui
@@ -55,7 +55,7 @@
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="icon-name">document-edit-symbolic</property>
+ <property name="icon-name">edit-symbolic</property>
<property name="pixel_size">16</property>
</object>
</child>
diff --git a/data/ui/zoom-in-notification.ui b/data/ui/zoom-in-notification.ui
new file mode 100644
index 0000000..818302d
--- /dev/null
+++ b/data/ui/zoom-in-notification.ui
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <object class="GtkGrid" id="grid">
+ <property name="visible">True</property>
+ <property name="hexpand">False</property>
+ <property name="orientation">horizontal</property>
+ <child>
+ <object class="GtkLabel" id="label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin-end">30</property>
+ <property name="label" translatable="yes">You need to be zoomed-in to edit!</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="zoomInButton">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Zoom</property>
+ <property name="focus-on-click">False</property>
+ <property name="margin-end">5</property>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/src/contextMenu.js b/src/contextMenu.js
index 39633b1..ff0fecb 100644
--- a/src/contextMenu.js
+++ b/src/contextMenu.js
@@ -19,6 +19,8 @@
* Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
*/
+const _ = imports.gettext.gettext;
+
const Champlain = imports.gi.Champlain;
const Clutter = imports.gi.Clutter;
const Gdk = imports.gi.Gdk;
@@ -30,7 +32,12 @@ 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 OSMUtils = imports.osmUtils;
const Utils = imports.utils;
+const ZoomInNotification = imports.zoomInNotification;
const ContextMenu = new Lang.Class({
Name: 'ContextMenu',
@@ -38,7 +45,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 +63,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 +102,38 @@ const ContextMenu = new Lang.Class({
clipboard.set_text(uri, uri.length);
},
+ _onAddOSMLocationActivated: function() {
+ /* if we're not sufficently zoomed-in, show a notification with the
+ opportunity to zoom-in */
+ let view = this._mapView.get_view();
+
+ if (view.zoom_level < OSMUtils.MIN_ADD_LOCATION_ZOOM_LEVEL) {
+ let notification =
+ new ZoomInNotification.ZoomInNotification({latitude: this._latitude,
+ longitude: this._longitude,
+ view: view});
+ Application.notificationManager.showNotification(notification);
+ return;
+ }
+
+ 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) {
+ Application.notificationManager.showMessage(_("Location added, it may take a while before it
appears on the map and in searches"));
+ }
+ },
+
_activateExport: function() {
let view = this._mapView.view;
let surface = view.to_surface(true);
diff --git a/src/org.gnome.Maps.src.gresource.xml b/src/org.gnome.Maps.src.gresource.xml
index ebaea93..0b60b69 100644
--- a/src/org.gnome.Maps.src.gresource.xml
+++ b/src/org.gnome.Maps.src.gresource.xml
@@ -70,6 +70,7 @@
<file>userLocationMarker.js</file>
<file>utils.js</file>
<file>zoomControl.js</file>
+ <file>zoomInNotification.js</file>
<file alias="geojsonvt/clip.js">clip.js</file>
<file alias="geojsonvt/convert.js">convert.js</file>
<file alias="geojsonvt/geojsonvt.js">index.js</file>
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,
diff --git a/src/osmUtils.js b/src/osmUtils.js
index 4c2f183..d2735e1 100644
--- a/src/osmUtils.js
+++ b/src/osmUtils.js
@@ -24,6 +24,9 @@ const Soup = imports.gi.Soup;
const Application = imports.application;
+/* minimum zoom level at which to offer adding a location */
+const MIN_ADD_LOCATION_ZOOM_LEVEL = 16;
+
/*
* Gets a Wikipedia article in OSM tag format (i.e. lang:Article title)
* given a URL or null if input doesn't match a Wikipedia URL
diff --git a/src/zoomInNotification.js b/src/zoomInNotification.js
new file mode 100644
index 0000000..d29fc22
--- /dev/null
+++ b/src/zoomInNotification.js
@@ -0,0 +1,57 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2016 Marcus Lundblad.
+ *
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Marcus Lundblad <ml update uu se>
+ */
+
+const Lang = imports.lang;
+
+const Application = imports.application;
+const Notification = imports.notification;
+const OSMUtils = imports.osmUtils;
+const Utils = imports.utils;
+
+const ZoomInNotification = Lang.Class({
+ Name: 'ZoomInNotification',
+ Extends: Notification.Notification,
+ InternalChildren: ['zoomInButton'],
+
+ _init: function(props) {
+ this._latitude = props.latitude;
+ this._longitude = props.longitude;
+ this._view = props.view;
+ this.parent();
+
+ let ui = Utils.getUIObject('zoom-in-notification', [ 'grid',
+ 'zoomInButton' ]);
+
+ ui.zoomInButton.connect('clicked', this._onZoomIn.bind(this));
+
+ this._ui.body.add(ui.grid);
+ },
+
+ _onZoomIn: function() {
+ /* zoom in to the inner-most level */
+ this._view.zoom_level = OSMUtils.MIN_ADD_LOCATION_ZOOM_LEVEL;
+
+ /* center on the position first selected */
+ this._view.center_on(this._latitude, this._longitude);
+ this.dismiss();
+ }
+})
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]