[gnome-maps/wip/osm-edit: 16/47] osmEditor: Add edit dialog and hook up OSM data fetching to feed the dialog
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/osm-edit: 16/47] osmEditor: Add edit dialog and hook up OSM data fetching to feed the dialog
- Date: Thu, 30 Apr 2015 12:58:43 +0000 (UTC)
commit 0b7d8518bee0bfddbb66f188adc9e39ec6283f21
Author: Marcus Lundblad <ml update uu se>
Date: Sun Feb 8 23:25:01 2015 +0100
osmEditor: Add edit dialog and hook up OSM data fetching to feed the dialog
The dialog still contains no functionallity and has some left-overs from the check-in
dialog lingering.
data/org.gnome.Maps.data.gresource.xml | 1 +
data/ui/osm-edit-dialog.ui | 108 ++++++++++++++++++++++++++++++++
src/mapBubble.js | 3 +-
src/org.gnome.Maps.src.gresource.xml | 1 +
src/osmConnection.js | 6 ++-
src/osmEdit.js | 25 +++++--
src/osmEditDialog.js | 80 +++++++++++++++++++++++
7 files changed, 215 insertions(+), 9 deletions(-)
---
diff --git a/data/org.gnome.Maps.data.gresource.xml b/data/org.gnome.Maps.data.gresource.xml
index 6ba6040..eb68093 100644
--- a/data/org.gnome.Maps.data.gresource.xml
+++ b/data/org.gnome.Maps.data.gresource.xml
@@ -13,6 +13,7 @@
<file preprocess="xml-stripblanks">ui/main-window.ui</file>
<file preprocess="xml-stripblanks">ui/map-bubble.ui</file>
<file preprocess="xml-stripblanks">ui/notification.ui</file>
+ <file preprocess="xml-stripblanks">ui/osm-edit-dialog.ui</file>
<file preprocess="xml-stripblanks">ui/place-bubble.ui</file>
<file preprocess="xml-stripblanks">ui/place-entry.ui</file>
<file preprocess="xml-stripblanks">ui/place-list-row.ui</file>
diff --git a/data/ui/osm-edit-dialog.ui b/data/ui/osm-edit-dialog.ui
new file mode 100644
index 0000000..8638c43
--- /dev/null
+++ b/data/ui/osm-edit-dialog.ui
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk+" version="3.12"/>
+ <template class="Gjs_OSMEditDialog" parent="GtkDialog">
+ <property name="can_focus">False</property>
+ <property name="type">popup</property>
+ <property name="type_hint">dialog</property>
+ <property name="width_request">500</property>
+ <child internal-child="vbox">
+ <object class="GtkBox" id="contentArea">
+ <child>
+ <object class="GtkStack" id="stack">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="homogeneous">True</property>
+ <property name="transition_type">crossfade</property>
+ <child>
+ <object class="GtkGrid" id="loadingGrid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkSpinner" id="loadingSpinner">
+ <property name="height_request">32</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="active">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="name">loading</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkGrid" id="editorGrid">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="margin_start">15</property>
+ <property name="margin_end">15</property>
+ <property name="margin_top">15</property>
+ <property name="margin_bottom">15</property>
+ <child>
+ <object class="GtkFrame" id="accountFrame">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="label_xalign">0</property>
+ <property name="shadow_type">in</property>
+ <child type="label_item">
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="name">editor</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child type="titlebar">
+ <object class="GtkHeaderBar" id="headerBar">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="show-close-button">False</property>
+ <child>
+ <object class="GtkButton" id="cancelButton">
+ <property name="label" translatable="yes">_Cancel</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="use_underline">True</property>
+ </object>
+ <packing>
+ <property name="pack-type">start</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="saveButton">
+ <property name="label" translatable="yes">_Save</property>
+ <property name="visible">False</property>
+ <property name="can_focus">True</property>
+ <property name="use_underline">True</property>
+ <style>
+ <class name="suggested-action"/>
+ </style>
+ </object>
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+
+ </template>
+</interface>
diff --git a/src/mapBubble.js b/src/mapBubble.js
index 2adc755..f5c20d8 100644
--- a/src/mapBubble.js
+++ b/src/mapBubble.js
@@ -182,7 +182,8 @@ const MapBubble = new Lang.Class({
print ('about to edit place: type: ' + this._place.osm_type + ' id: ' +
this._place.osm_id);
- Application.osmEditManager.initEditing(this.place);
+ Application.osmEditManager.showEditDialog(this.get_toplevel(),
+ this.place);
}).bind(this));
}
});
diff --git a/src/org.gnome.Maps.src.gresource.xml b/src/org.gnome.Maps.src.gresource.xml
index 6995bc6..bdbc4ec 100644
--- a/src/org.gnome.Maps.src.gresource.xml
+++ b/src/org.gnome.Maps.src.gresource.xml
@@ -29,6 +29,7 @@
<file>osmChangeset.js</file>
<file>osmConnection.js</file>
<file>osmEdit.js</file>
+ <file>osmEditDialog.js</file>
<file>osmNode.js</file>
<file>osmObject.js</file>
<file>osmRelation.js</file>
diff --git a/src/osmConnection.js b/src/osmConnection.js
index cd1cd79..8292e64 100644
--- a/src/osmConnection.js
+++ b/src/osmConnection.js
@@ -40,12 +40,16 @@ const OSMConnection = new Lang.Class({
Maps.osm_init();
},
- getOSMObject: function(type, id, callback) {
+ getOSMObject: function(type, id, callback, cancellable) {
let url = this._getQueryUrl(type, id);
let uri = new Soup.URI(url);
let request = new Soup.Message({ method: 'GET',
uri: uri });
+ cancellable.connect((function() {
+ this._session.cancel_message(request, Soup.STATUS_CANCELLED);
+ }).bind(this));
+
this._session.queue_message(request, (function(obj, message) {
if (message.status_code !== Soup.KnownStatusCode.OK) {
callback(false, message.status_code, null);
diff --git a/src/osmEdit.js b/src/osmEdit.js
index 9f7ce66..5f41d39 100644
--- a/src/osmEdit.js
+++ b/src/osmEdit.js
@@ -23,6 +23,7 @@
const GObject = imports.gi.GObject;
const Lang = imports.lang;
+const OSMEditDialog = imports.osmEditDialog;
const OSMConnection = imports.osmConnection;
const OSMEditManager = new Lang.Class({
@@ -33,15 +34,25 @@ const OSMEditManager = new Lang.Class({
this._osmConnection = new OSMConnection.OSMConnection();
},
- initEditing: function(place) {
- let osmType = this._getOSMTypeName(place);
+ showEditDialog: function(parentWindow, place) {
+ let dialog = new OSMEditDialog.OSMEditDialog( { transient_for: parentWindow,
+ place: place });
+ let response = dialog.run();
+
+ dialog.destroy();
+ },
+ fetchObject: function(place, callback, cancellable) {
+ let osmType = this._getOSMTypeName(place);
+
this._osmConnection.getOSMObject(osmType, place.osm_id,
- (function(success, status, data) {
- print('success: ' + success);
- print('status: ' + status);
- print('data: ' + data);
- }));
+ (function(success, status, data) {
+ print('success: ' + success);
+ print('status: ' + status);
+ print('data: ' + data);
+ callback(success, status, data);
+ }), cancellable);
+
},
_getOSMTypeName: function(place) {
diff --git a/src/osmEditDialog.js b/src/osmEditDialog.js
new file mode 100644
index 0000000..d43daaf
--- /dev/null
+++ b/src/osmEditDialog.js
@@ -0,0 +1,80 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2015 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, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Marcus Lundblad <ml update uu se>
+ */
+
+const Gio = imports.gi.Gio;
+const Gtk = imports.gi.Gtk;
+const Lang = imports.lang;
+
+const Application = imports.application;
+
+const Response = {
+ SUCCESS: 0,
+ CANCELLED: 1,
+};
+
+const OSMEditDialog = new Lang.Class({
+ Name: 'OSMEditDialog',
+ Extends: Gtk.Dialog,
+ Template: 'resource:///org/gnome/Maps/ui/osm-edit-dialog.ui',
+ InternalChildren: [ 'cancelButton',
+ 'saveButton',
+ 'stack'],
+
+ _init: function(params) {
+ this._place = params.place;
+ delete params.place;
+
+ // This is a construct-only property and cannot be set by GtkBuilder
+ params.use_header_bar = true;
+
+ this.parent(params);
+
+ this._cancellable = new Gio.Cancellable();
+ this._cancellable.connect((function() {
+ this.response(Response.CANCELLED);
+ }).bind(this));
+
+ this.connect('delete-event', (function() {
+ this._cancellable.cancel();
+ }).bind(this));
+
+ Application.osmEditManager.fetchObject(this._place,
+ this._fetchOSMObjectCB.bind(this),
+ this._cancellable);
+ },
+
+ _fetchOSMObjectCB: function(success, status, data) {
+ if (success) {
+ this._loadOSMData(data);
+ } else {
+ this._showError(status);
+ }
+ },
+
+ _loadOSMData: function(data) {
+ this._stack.set_visible_child_name('editor');
+ },
+
+ _showError: function(status) {
+
+ }
+});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]