diff options
author | James Westman <james@flyingpimonster.net> | 2020-11-25 17:05:43 -0600 |
---|---|---|
committer | Marcus Lundblad <ml@update.uu.se> | 2021-02-09 20:48:40 +0000 |
commit | 65448af914dd58471a2e6289c06376ef46872959 (patch) | |
tree | 410d11a88d6a9bc13864334bb69129b1ecc25a60 /src/mapBubble.js | |
parent | 7247026a6564f66cc0596a0ce31d1fa068812be2 (diff) | |
download | gnome-maps-65448af914dd58471a2e6289c06376ef46872959.tar.gz |
mapBubble: Split buttons into new class
This new class, PlaceButtons, will allow place buttons to be reused in different
places in the adaptive design.
Diffstat (limited to 'src/mapBubble.js')
-rw-r--r-- | src/mapBubble.js | 152 |
1 files changed, 11 insertions, 141 deletions
diff --git a/src/mapBubble.js b/src/mapBubble.js index 8609995e..879916bf 100644 --- a/src/mapBubble.js +++ b/src/mapBubble.js @@ -28,13 +28,10 @@ const Mainloop = imports.mainloop; const Application = imports.application; const ContactPlace = imports.contactPlace; const GeocodeFactory = imports.geocode; -const OSMAccountDialog = imports.osmAccountDialog; -const OSMEditDialog = imports.osmEditDialog; -const OSMUtils = imports.osmUtils; const Place = imports.place; +const PlaceButtons = imports.placeButtons; const PlaceFormatter = imports.placeFormatter; const PlaceStore = imports.placeStore; -const SendToDialog = imports.sendToDialog; const Utils = imports.utils; /* Maximum width of the popover content before it's forced to wrap */ @@ -43,15 +40,6 @@ const MAX_CONTENT_WIDTH = 300; contents */ const HEIGHT_MARGIN = 100; -var Button = { - NONE: 0, - ROUTE: 2, - SEND_TO: 4, - FAVORITE: 8, - CHECK_IN: 16, - EDIT_ON_OSM: 32, -}; - var MapBubble = GObject.registerClass({ Abstract: true }, class MapBubble extends Gtk.Popover { @@ -79,14 +67,9 @@ class MapBubble extends Gtk.Popover { 'address-label', 'bubble-main-stack', 'bubble-content-area', - 'bubble-button-area', - 'bubble-route-button', - 'bubble-send-to-button', - 'bubble-send-to-button-alt', - 'title-box', - 'bubble-favorite-button', - 'bubble-edit-button', - 'bubble-favorite-button-image']); + 'place-buttons', + 'send-to-button-alt', + 'title-box' ]); this._title = ui.labelTitle; this._thumbnail = ui.bubbleThumbnail; this._thumbnailSeparator = ui.thumbnailSeparator; @@ -97,27 +80,20 @@ class MapBubble extends Gtk.Popover { this._contactAvatar = ui.contactAvatar; this._addressLabel = ui.addressLabel; - if (!buttonFlags) - ui.bubbleButtonArea.visible = false; - else { - if (buttonFlags & Button.ROUTE) - this._initRouteButton(ui.bubbleRouteButton); - if (buttonFlags & Button.SEND_TO) - this._initSendToButton(ui.bubbleSendToButton, buttonFlags & Button.CHECK_IN); - if (buttonFlags & Button.FAVORITE) - this._initFavoriteButton(ui.bubbleFavoriteButton, ui.bubbleFavoriteButtonImage); - if (buttonFlags & Button.EDIT_ON_OSM) - this._initEditButton(ui.bubbleEditButton); - } + ui.placeButtons.visible = !!buttonFlags; + let placeButtons = new PlaceButtons.PlaceButtons({ buttonFlags, + 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.bubbleButtonArea.visible = false; + ui.placeButtons.visible = false; /* show the top-end-corner share button instead */ - this._initSendToButton(ui.bubbleSendToButtonAlt, buttonFlags & Button.CHECK_IN); + placeButtons.initSendToButton(ui.sendToButtonAlt, buttonFlags & PlaceButtons.Button.CHECK_IN); /* adjust some margins */ ui.titleBox.margin = 12; ui.titleBox.marginStart = 18; @@ -192,112 +168,6 @@ class MapBubble extends Gtk.Popover { this._title.label = formatter.title; this._contactAvatar.text = formatter.title; } - - _initFavoriteButton(button, image) { - let placeStore = Application.placeStore; - button.visible = true; - - if (placeStore.exists(this._place, - PlaceStore.PlaceType.FAVORITE)) { - image.icon_name = 'starred-symbolic'; - } else { - image.icon_name = 'non-starred-symbolic'; - } - - button.connect('clicked', () => { - if (placeStore.exists(this._place, - PlaceStore.PlaceType.FAVORITE)) { - image.icon_name = 'non-starred-symbolic'; - placeStore.removePlace(this._place, - PlaceStore.PlaceType.FAVORITE); - } else { - image.icon_name = 'starred-symbolic'; - placeStore.addPlace(this._place, - PlaceStore.PlaceType.FAVORITE); - } - }); - } - - _initSendToButton(button, showCheckIn) { - button.visible = true; - button.connect('clicked', () => { - let dialog = new SendToDialog.SendToDialog({ transient_for: this.get_toplevel(), - modal: true, - mapView: this._mapView, - place: this._place, - showCheckIn }); - dialog.connect('response', () => dialog.destroy()); - dialog.show(); - }); - } - - _initRouteButton(button) { - let query = Application.routeQuery; - let from = query.points[0]; - let to = query.points[query.points.length - 1]; - - button.visible = true; - - button.connect('clicked', () => { - query.freeze_notify(); - query.reset(); - Application.routingDelegator.reset(); - - if (Application.geoclue.place) - from.place = Application.geoclue.place; - to.place = this._place; - - this.destroy(); - query.thaw_notify(); - }); - } - - _initEditButton(button) { - button.visible = true; - button.connect('clicked', this._onEditClicked.bind(this)); - } - - _onEditClicked() { - let osmEdit = Application.osmEdit; - /* if the user is not already signed in, show the account dialog */ - if (!osmEdit.isSignedIn) { - let dialog = osmEdit.createAccountDialog(this.get_toplevel(), true); - - dialog.show(); - dialog.connect('response', (dialog, response) => { - dialog.destroy(); - if (response === OSMAccountDialog.Response.SIGNED_IN) - this._edit(); - }); - - return; - } - - this._edit(); - } - - _edit() { - let osmEdit = Application.osmEdit; - let dialog = osmEdit.createEditDialog(this.get_toplevel(), this._place); - - dialog.show(); - dialog.connect('response', (dialog, response) => { - dialog.destroy(); - - switch (response) { - case OSMEditDialog.Response.UPLOADED: - // update place - let object = osmEdit.object; - OSMUtils.updatePlaceFromOSMObject(this._place, object); - // refresh place view - this._clearView(); - this._populate(this._place); - break; - default: - break; - } - }); - } }); var MapBubbleScrolledWindow = GObject.registerClass( |