[gnome-maps/wip/mlundblad/export-in-hamburger: 1/2] mainWindow: Add "Export as Image" to the hamburger menu



commit 1c969f3fd2c43e0c2370cbd07dffb50870ef4357
Author: Marcus Lundblad <ml update uu se>
Date:   Sun Jan 19 23:31:08 2020 +0100

    mainWindow: Add "Export as Image" to the hamburger menu

 data/ui/main-window.ui |  4 ++++
 src/mainWindow.js      | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
---
diff --git a/data/ui/main-window.ui b/data/ui/main-window.ui
index 0d168df9..ace2a6e2 100644
--- a/data/ui/main-window.ui
+++ b/data/ui/main-window.ui
@@ -7,6 +7,10 @@
         <attribute name="action">app.osm-account-setup</attribute>
         <attribute name="label" translatable="yes">Set up OpenStreetMap Account</attribute>
       </item>
+      <item>
+        <attribute name="action">win.export-as-image</attribute>
+        <attribute name="label" translatable="yes">Export as Image</attribute>
+      </item>
     </section>
     <section>
       <item>
diff --git a/src/mainWindow.js b/src/mainWindow.js
index a1753fab..8525245e 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -22,6 +22,7 @@
 
 const _ = imports.gettext.gettext;
 
+const Champlain = imports.gi.Champlain;
 const GLib = imports.gi.GLib;
 const GObject = imports.gi.GObject;
 const Gdk = imports.gi.Gdk;
@@ -31,6 +32,7 @@ const Mainloop = imports.mainloop;
 
 const Application = imports.application;
 const ContextMenu = imports.contextMenu;
+const ExportViewDialog = imports.exportViewDialog;
 const FavoritesPopover = imports.favoritesPopover;
 const Geoclue = imports.geoclue;
 const GeocodeFactory = imports.geocode;
@@ -244,6 +246,9 @@ var MainWindow = GObject.registerClass({
             'open-shape-layer': {
                 accels: ['<Primary>O'],
                 onActivate: () => this._onOpenShapeLayer()
+            },
+            'export-as-image': {
+                onActivate: () => this._onExportActivated()
             }
         });
     }
@@ -464,6 +469,38 @@ var MainWindow = GObject.registerClass({
         });
     }
 
+    _activateExport() {
+        let view = this._mapView.view;
+        let surface = view.to_surface(true);
+        let bbox = view.get_bounding_box();
+        let [latitude, longitude] = bbox.get_center();
+
+        let dialog = new ExportViewDialog.ExportViewDialog({
+            transient_for: this,
+            modal: true,
+            surface: surface,
+            latitude: latitude,
+            longitude: longitude,
+            mapView: this._mapView
+        });
+
+        dialog.connect('response', () => dialog.destroy());
+        dialog.show_all();
+    }
+
+    _onExportActivated() {
+        if (this._mapView.view.state === Champlain.State.DONE) {
+            this._activateExport();
+        } else {
+            let notifyId = this._mapView.view.connect('notify::state', () => {
+                if (this._mapView.view.state === Champlain.State.DONE) {
+                    this._mapView.view.disconnect(notifyId);
+                    this._activateExport();
+                }
+            });
+        }
+    }
+
     _printRouteActivate() {
         if (this._mapView.routeShowing) {
             let operation = new PrintOperation.PrintOperation({ mainWindow: this });


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