[gnome-maps] mapBubble: Move content to placeBubble



commit e3368acc19676628454ef87cb0a60954e13b18ad
Author: James Westman <james flyingpimonster net>
Date:   Mon Dec 28 15:54:11 2020 -0600

    mapBubble: Move content to placeBubble
    
    PlaceBubble is now a GtkBox rather than a subclass of MapBubble. It contains
    most of what used to be in MapBubble except the parts specific to popovers.
    This will make it easy to add a place dialog.

 src/mapBubble.js   | 116 +++++------------------------------------------------
 src/mapMarker.js   |   6 +--
 src/placeBubble.js | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 125 insertions(+), 112 deletions(-)
---
diff --git a/src/mapBubble.js b/src/mapBubble.js
index 0ab299bb..3663539d 100644
--- a/src/mapBubble.js
+++ b/src/mapBubble.js
@@ -29,6 +29,7 @@ const Application = imports.application;
 const ContactPlace = imports.contactPlace;
 const GeocodeFactory = imports.geocode;
 const Place = imports.place;
+const PlaceBubble = imports.placeBubble;
 const PlaceButtons = imports.placeButtons;
 const PlaceFormatter = imports.placeFormatter;
 const PlaceStore = imports.placeStore;
@@ -40,131 +41,32 @@ const MAX_CONTENT_WIDTH = 300;
    contents */
 const HEIGHT_MARGIN = 100;
 
-var MapBubble = GObject.registerClass({ Abstract: true },
+var MapBubble = GObject.registerClass(
 class MapBubble extends Gtk.Popover {
 
     _init(params) {
-        this._place = params.place;
+        let place = params.place;
         delete params.place;
 
-        this._mapView = params.mapView;
-        params.relative_to = params.mapView;
-        params.transitions_enabled = false;
+        let mapView = params.mapView;
         delete params.mapView;
 
+        params.relative_to = mapView;
+        params.transitions_enabled = false;
         params.modal = false;
 
         super._init(params);
-        let ui = Utils.getUIObject('map-bubble', [ 'bubble-main-box',
-                                                   'bubble-spinner',
-                                                   'bubble-thumbnail',
-                                                   'thumbnail-separator',
-                                                   'label-title',
-                                                   'contact-avatar',
-                                                   'address-label',
-                                                   'bubble-main-stack',
-                                                   'bubble-content-area',
-                                                   'place-buttons',
-                                                   'send-to-button-alt',
-                                                   'title-box' ]);
-        this._title = ui.labelTitle;
-        this._thumbnail = ui.bubbleThumbnail;
-        this._thumbnailSeparator = ui.thumbnailSeparator;
-        this._content = ui.bubbleContentArea;
-        this._mainStack = ui.bubbleMainStack;
-        this._spinner = ui.bubbleSpinner;
-        this._mainBox = ui.bubbleMainBox;
-        this._contactAvatar = ui.contactAvatar;
-        this._addressLabel = ui.addressLabel;
-
-        let placeButtons = new PlaceButtons.PlaceButtons({ place: this._place,
-                                                           mapView: this._mapView })
-        ui.placeButtons.add(placeButtons);
-
-        if (this.place.isCurrentLocation) {
-            /* Current Location bubbles have a slightly different layout, to
-               avoid awkward whitespace */
-
-            /* hide the normal button area */
-            ui.placeButtons.visible = false;
-
-            /* show the top-end-corner share button instead */
-            ui.sendToButtonAlt.visible = true;
-            placeButtons.initSendToButton(ui.sendToButtonAlt);
-
-            /* adjust some margins */
-            ui.titleBox.margin = 12;
-            ui.titleBox.marginStart = 18;
-            ui.titleBox.spacing = 18;
-        }
+
+        let content = new PlaceBubble.PlaceBubble({ place, mapView, visible: true });
 
         let scrolledWindow = new MapBubbleScrolledWindow({ visible: true,
                                                            propagateNaturalWidth: true,
                                                            propagateNaturalHeight: true,
                                                            hscrollbarPolicy: Gtk.PolicyType.NEVER });
-        scrolledWindow.add(this._mainStack);
+        scrolledWindow.add(content);
         this.add(scrolledWindow);
 
-        /* Set up contact avatar */
-        if (this.place instanceof ContactPlace.ContactPlace) {
-            this._contactAvatar.visible = true;
-            Utils.load_icon(this.place.icon, 32, (pixbuf) => {
-                this._contactAvatar.set_image_load_func((size) => Utils.loadAvatar(pixbuf, size));
-            });
-        }
-
         this.get_style_context().add_class("map-bubble");
-
-        this.updatePlaceDetails();
-    }
-
-    get place() {
-        return this._place;
-    }
-
-    get content() {
-        return this._content;
-    }
-
-    get thumbnail() {
-        return this._thumbnail.pixbuf;
-    }
-
-    set thumbnail(val) {
-        if (val) {
-            this._thumbnail.pixbuf = val;
-            this._thumbnail.visible = true;
-            this._thumbnailSeparator.visible = true;
-        }
-    }
-
-    get loading() {
-        return this._spinner.active;
-    }
-    set loading(val) {
-        this._mainStack.set_visible_child(val ? this._spinner : this._mainBox);
-        this._spinner.active = val;
-    }
-
-    updatePlaceDetails() {
-        let place = this.place;
-        let formatter = new PlaceFormatter.PlaceFormatter(place);
-
-        let address = formatter.rows.map((row) => {
-            row = row.map(function(prop) {
-                return GLib.markup_escape_text(place[prop], -1);
-            });
-            return row.join(', ');
-        });
-        if (address.length > 0) {
-            this._addressLabel.label = address.join('\n');
-            this._addressLabel.show();
-        } else {
-            this._addressLabel.hide();
-        }
-
-        this._title.label = formatter.title;
-        this._contactAvatar.text = formatter.title;
     }
 });
 
diff --git a/src/mapMarker.js b/src/mapMarker.js
index fe2468bd..b5a0e7fa 100644
--- a/src/mapMarker.js
+++ b/src/mapMarker.js
@@ -28,8 +28,8 @@ const Gtk = imports.gi.Gtk;
 const Mainloop = imports.mainloop;
 
 const Application = imports.application;
+const MapBubble = imports.mapBubble;
 const MapWalker = imports.mapWalker;
-const PlaceBubble = imports.placeBubble;
 const Utils = imports.utils;
 
 var MapMarker = GObject.registerClass({
@@ -208,8 +208,8 @@ var MapMarker = GObject.registerClass({
     get bubble() {
         if (this._bubble === undefined && this._hasBubble()) {
             if (this._place.name) {
-                this._bubble = new PlaceBubble.PlaceBubble({ place: this._place,
-                                                             mapView: this._mapView });
+                this._bubble = new MapBubble.MapBubble({ place: this._place,
+                                                         mapView: this._mapView });
             }
         }
 
diff --git a/src/placeBubble.js b/src/placeBubble.js
index c7dcb353..3814f655 100644
--- a/src/placeBubble.js
+++ b/src/placeBubble.js
@@ -28,11 +28,12 @@ const Pango = imports.gi.Pango;
 const Format = imports.format;
 
 const Application = imports.application;
-const MapBubble = imports.mapBubble;
+const ContactPlace = imports.contactPlace;
 const Overpass = imports.overpass;
 const Place = imports.place;
 const PlaceBubbleImage = imports.placeBubbleImage;
 const PlaceButtons = imports.placeButtons;
+const PlaceFormatter = imports.placeFormatter;
 const PlaceStore = imports.placeStore;
 const Translations = imports.translations;
 const Utils = imports.utils;
@@ -50,11 +51,70 @@ var PlaceBubble = GObject.registerClass({
                                                    GObject.ParamFlags.WRITABLE,
                                                    Geocode.Place)
     }
-}, class PlaceBubble extends MapBubble.MapBubble {
+}, class PlaceBubble extends Gtk.Box {
 
     _init(params) {
+        this._place = params.place;
+        delete params.place;
+
+        let mapView = params.mapView;
+        delete params.mapView;
+
         super._init(params);
 
+        let ui = Utils.getUIObject('map-bubble', [ 'bubble-main-box',
+                                                   'bubble-spinner',
+                                                   'bubble-thumbnail',
+                                                   'thumbnail-separator',
+                                                   'label-title',
+                                                   'contact-avatar',
+                                                   'address-label',
+                                                   'bubble-main-stack',
+                                                   'bubble-content-area',
+                                                   'place-buttons',
+                                                   'send-to-button-alt',
+                                                   'title-box' ]);
+        this._title = ui.labelTitle;
+        this._thumbnail = ui.bubbleThumbnail;
+        this._thumbnailSeparator = ui.thumbnailSeparator;
+        this._content = ui.bubbleContentArea;
+        this._mainStack = ui.bubbleMainStack;
+        this._spinner = ui.bubbleSpinner;
+        this._mainBox = ui.bubbleMainBox;
+        this._contactAvatar = ui.contactAvatar;
+        this._addressLabel = ui.addressLabel;
+
+        this.add(this._mainStack);
+
+        let placeButtons = new PlaceButtons.PlaceButtons({ place: this._place,
+                                                           mapView: mapView });
+        ui.placeButtons.add(placeButtons);
+
+        if (this.place.isCurrentLocation) {
+            /* Current Location bubbles have a slightly different layout, to
+               avoid awkward whitespace */
+
+            /* hide the normal button area */
+            ui.placeButtons.visible = false;
+
+            /* show the top-end-corner share button instead */
+            ui.sendToButtonAlt.visible = true;
+            placeButtons.initSendToButton(ui.sendToButtonAlt);
+
+            /* adjust some margins */
+            ui.titleBox.margin = 12;
+            ui.titleBox.marginStart = 18;
+            ui.titleBox.spacing = 18;
+        }
+
+        /* Set up contact avatar */
+        if (this.place instanceof ContactPlace.ContactPlace) {
+            this._contactAvatar.visible = true;
+            Utils.load_icon(this.place.icon, 32, (pixbuf) => {
+                this._contactAvatar.set_image_load_func((size) => Utils.loadAvatar(pixbuf, size));
+            });
+        }
+
         this.loading = true;
 
         this._placeDetails = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL,
@@ -88,6 +148,8 @@ var PlaceBubble = GObject.registerClass({
                 this._populate(this.place);
             }
         }
+
+        this.updatePlaceDetails();
     }
 
     updateLocation() {
@@ -95,6 +157,55 @@ var PlaceBubble = GObject.registerClass({
         this._populate(this.place);
     }
 
+    get place() {
+        return this._place;
+    }
+
+    get content() {
+        return this._content;
+    }
+
+    get thumbnail() {
+        return this._thumbnail.pixbuf;
+    }
+
+    set thumbnail(val) {
+        if (val) {
+            this._thumbnail.pixbuf = val;
+            this._thumbnail.visible = true;
+            this._thumbnailSeparator.visible = true;
+        }
+    }
+
+    get loading() {
+        return this._spinner.active;
+    }
+    set loading(val) {
+        this._mainStack.set_visible_child(val ? this._spinner : this._mainBox);
+        this._spinner.active = val;
+    }
+
+    updatePlaceDetails() {
+        let place = this.place;
+        let formatter = new PlaceFormatter.PlaceFormatter(place);
+
+        let address = formatter.rows.map((row) => {
+            row = row.map(function(prop) {
+                return GLib.markup_escape_text(place[prop], -1);
+            });
+            return row.join(', ');
+        });
+        if (address.length > 0) {
+            this._addressLabel.label = address.join('\n');
+            this._addressLabel.show();
+        } else {
+            this._addressLabel.hide();
+        }
+
+        this._title.label = formatter.title;
+        this._contactAvatar.text = formatter.title;
+    }
+
     _onInfoAdded() {
         this._populate(this.place);
         if (Application.placeStore.exists(this.place, null))


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