[gnome-maps/wip/jonasdn/geojson: 54/55] mainWindow: Add drag and drop support for GeoJSON



commit 1f323d98006b05327f3c8b53798ee478897a5e96
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Fri Oct 23 12:08:49 2015 +0200

    mainWindow: Add drag and drop support for GeoJSON

 src/mainWindow.js |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 3ad690b..204381e 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -23,6 +23,7 @@
 const GLib = imports.gi.GLib;
 const GObject = imports.gi.GObject;
 const Gdk = imports.gi.Gdk;
+const Gio = imports.gi.Gio;
 const Gtk = imports.gi.Gtk;
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
@@ -70,11 +71,31 @@ const MainWindow = new Lang.Class({
 
         this._configureId = 0;
 
+        this.drag_dest_set(Gtk.DestDefaults.DROP, null, 0);
+        this.drag_dest_add_uri_targets();
+
         this._mapView = new MapView.MapView({
             mapType: this.application.local_tile_path ?
                 MapView.MapType.LOCAL : MapView.MapType.STREET
         });
 
+        this.connect('drag-motion', (function(widget, ctx, x, y, time) {
+            return true;
+        }).bind(this));
+
+        this.connect('drag-data-received', (function(widget, ctx, x, y, data, info, time) {
+            let uri = data.get_uris()[0];
+            let content_type = Gio.content_type_guess(uri, null)[0];
+
+            if (content_type === 'application/vnd.geo+json' ||
+                content_type === 'application/json') {
+                this._mapView.openGeoJSON(Gio.file_new_for_uri(uri));
+                Gtk.drag_finish(ctx, true, true, time);
+            } else {
+                Gtk.drag_finish(ctx, false, false, time);
+            }
+        }).bind(this));
+
         this._overlay.add(this._mapView);
 
         this._mapView.gotoUserLocation(false);


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