[gnome-maps] mapBubble: Split buttons into new class
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] mapBubble: Split buttons into new class
- Date: Tue, 9 Feb 2021 20:56:56 +0000 (UTC)
commit 65448af914dd58471a2e6289c06376ef46872959
Author: James Westman <james flyingpimonster net>
Date: Wed Nov 25 17:05:43 2020 -0600
mapBubble: Split buttons into new class
This new class, PlaceButtons, will allow place buttons to be reused in different
places in the adaptive design.
data/org.gnome.Maps.data.gresource.xml | 1 +
data/ui/map-bubble.ui | 101 +------------------
data/ui/place-buttons.ui | 104 +++++++++++++++++++
src/mapBubble.js | 152 +++-------------------------
src/org.gnome.Maps.src.gresource.xml | 1 +
src/placeBubble.js | 13 +--
src/placeButtons.js | 176 +++++++++++++++++++++++++++++++++
7 files changed, 303 insertions(+), 245 deletions(-)
---
diff --git a/data/org.gnome.Maps.data.gresource.xml b/data/org.gnome.Maps.data.gresource.xml
index e020e549..1eb1e5e9 100644
--- a/data/org.gnome.Maps.data.gresource.xml
+++ b/data/org.gnome.Maps.data.gresource.xml
@@ -22,6 +22,7 @@
<file preprocess="xml-stripblanks">ui/osm-type-list-row.ui</file>
<file preprocess="xml-stripblanks">ui/osm-type-search-entry.ui</file>
<file preprocess="xml-stripblanks">ui/osm-type-popover.ui</file>
+ <file preprocess="xml-stripblanks">ui/place-buttons.ui</file>
<file preprocess="xml-stripblanks">ui/place-entry.ui</file>
<file preprocess="xml-stripblanks">ui/place-list-row.ui</file>
<file preprocess="xml-stripblanks">ui/place-popover.ui</file>
diff --git a/data/ui/map-bubble.ui b/data/ui/map-bubble.ui
index 3565c2ac..efbc889f 100644
--- a/data/ui/map-bubble.ui
+++ b/data/ui/map-bubble.ui
@@ -60,7 +60,7 @@
</object>
</child>
<child>
- <object class="GtkButton" id="bubble-send-to-button-alt">
+ <object class="GtkButton" id="send-to-button-alt">
<property name="visible">False</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@@ -87,105 +87,10 @@
</object>
</child>
<child>
- <object class="GtkBox" id="bubble-button-area">
+ <object class="GtkBox" id="place-buttons">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="orientation">horizontal</property>
- <property name="spacing">6</property>
- <child>
- <object class="GtkButton" id="bubble-route-button">
- <property name="name">bubble-route-button</property>
- <property name="visible">False</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="tooltip-text" translatable="yes" comments="Translators: This is a
tooltip">Add to new route</property>
- <child>
- <object class="GtkBox">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="orientation">horizontal</property>
- <property name="spacing">6</property>
- <child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="icon-name">route-button-symbolic</property>
- <property name="pixel_size">16</property>
- </object>
- </child>
- <child>
- <object class="GtkLabel">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes" comments="Translators: This is the
button to find a route to a place">Directions</property>
- </object>
- </child>
- </object>
- </child>
- <style>
- <class name="suggested-action"/>
- </style>
- </object>
- </child>
- <child>
- <object class="GtkButton" id="bubble-send-to-button">
- <property name="name">bubble-send-to-button</property>
- <property name="visible">False</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="tooltip-text" translatable="yes" comments="Translators: This is a
tooltip">Share location</property>
- <child>
- <object class="GtkImage" id="bubble-send-to-button-image">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="icon-name">send-to-symbolic</property>
- <property name="pixel_size">16</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="pack-type">end</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="bubble-favorite-button">
- <property name="name">bubble-favorite-button</property>
- <property name="visible">False</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="tooltip-text" translatable="yes" comments="Translators: This is a
tooltip">Mark as favorite</property>
- <child>
- <object class="GtkImage" id="bubble-favorite-button-image">
- <property name="name">bubble-favorite-button-image</property>
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="icon-name">starred-symbolic</property>
- <property name="pixel_size">16</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="pack-type">end</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="bubble-edit-button">
- <property name="visible">False</property>
- <property name="can_focus">True</property>
- <property name="tooltip-text" translatable="yes" comments="Translators: This is a
tooltip">Edit on OpenStreetMap</property>
- <child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="icon-name">document-edit-symbolic</property>
- <property name="pixel_size">16</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="pack-type">end</property>
- </packing>
- </child>
+ <property name="orientation">vertical</property>
</object>
</child>
</object>
diff --git a/data/ui/place-buttons.ui b/data/ui/place-buttons.ui
new file mode 100644
index 00000000..9260171e
--- /dev/null
+++ b/data/ui/place-buttons.ui
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk+" version="3.12"/>
+ <template class="Gjs_PlaceButtons" parent="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">horizontal</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkButton" id="routeButton">
+ <property name="name">bubble-route-button</property>
+ <property name="visible">False</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="tooltip-text" translatable="yes" comments="Translators: This is a tooltip">Add to
new route</property>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">horizontal</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon-name">route-button-symbolic</property>
+ <property name="pixel_size">16</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes" comments="Translators: This is the button to find
a route to a place">Directions</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <style>
+ <class name="suggested-action"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="sendToButton">
+ <property name="name">bubble-send-to-button</property>
+ <property name="visible">False</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="tooltip-text" translatable="yes" comments="Translators: This is a tooltip">Share
location</property>
+ <child>
+ <object class="GtkImage" id="sendToButtonImage">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon-name">send-to-symbolic</property>
+ <property name="pixel_size">16</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="favoriteButton">
+ <property name="name">bubble-favorite-button</property>
+ <property name="visible">False</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="tooltip-text" translatable="yes" comments="Translators: This is a tooltip">Mark as
favorite</property>
+ <child>
+ <object class="GtkImage" id="favoriteButtonImage">
+ <property name="name">bubble-favorite-button-image</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon-name">starred-symbolic</property>
+ <property name="pixel_size">16</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="editButton">
+ <property name="visible">False</property>
+ <property name="can_focus">True</property>
+ <property name="tooltip-text" translatable="yes" comments="Translators: This is a tooltip">Edit on
OpenStreetMap</property>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon-name">document-edit-symbolic</property>
+ <property name="pixel_size">16</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="pack-type">end</property>
+ </packing>
+ </child>
+ </template>
+</interface>
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(
diff --git a/src/org.gnome.Maps.src.gresource.xml b/src/org.gnome.Maps.src.gresource.xml
index c398e3cd..994b07ce 100644
--- a/src/org.gnome.Maps.src.gresource.xml
+++ b/src/org.gnome.Maps.src.gresource.xml
@@ -57,6 +57,7 @@
<file>place.js</file>
<file>placeBubble.js</file>
<file>placeBubbleImage.js</file>
+ <file>placeButtons.js</file>
<file>placeEntry.js</file>
<file>placeFormatter.js</file>
<file>placeListRow.js</file>
diff --git a/src/placeBubble.js b/src/placeBubble.js
index e1256694..7538a866 100644
--- a/src/placeBubble.js
+++ b/src/placeBubble.js
@@ -33,6 +33,7 @@ const MapBubble = imports.mapBubble;
const Overpass = imports.overpass;
const Place = imports.place;
const PlaceBubbleImage = imports.placeBubbleImage;
+const PlaceButtons = imports.placeButtons;
const PlaceStore = imports.placeStore;
const Translations = imports.translations;
const Utils = imports.utils;
@@ -53,18 +54,18 @@ var PlaceBubble = GObject.registerClass({
}, class PlaceBubble extends MapBubble.MapBubble {
_init(params) {
- params.buttons = (MapBubble.Button.ROUTE |
- MapBubble.Button.SEND_TO);
+ params.buttons = (PlaceButtons.Button.ROUTE |
+ PlaceButtons.Button.SEND_TO);
if (params.place.store)
- params.buttons |= MapBubble.Button.FAVORITE;
+ params.buttons |= PlaceButtons.Button.FAVORITE;
if (!(params.place instanceof ContactPlace.ContactPlace) && params.place.osm_id)
- params.buttons |= MapBubble.Button.EDIT_ON_OSM;
+ params.buttons |= PlaceButtons.Button.EDIT_ON_OSM;
if (params.place.isUserLocation) {
- params.buttons |= MapBubble.Button.CHECK_IN;
- params.buttons &= ~MapBubble.Button.ROUTE;
+ params.buttons |= PlaceButtons.Button.CHECK_IN;
+ params.buttons &= ~PlaceButtons.Button.ROUTE;
}
super._init(params);
diff --git a/src/placeButtons.js b/src/placeButtons.js
new file mode 100644
index 00000000..fa0ace5f
--- /dev/null
+++ b/src/placeButtons.js
@@ -0,0 +1,176 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * Copyright (c) 2020 James Westman
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: James Westman <james flyingpimonster net>
+ */
+
+
+const GObject = imports.gi.GObject;
+const Gtk = imports.gi.Gtk;
+
+const Application = imports.application;
+const OSMAccountDialog = imports.osmAccountDialog;
+const OSMEditDialog = imports.osmEditDialog;
+const OSMUtils = imports.osmUtils;
+const PlaceStore = imports.placeStore;
+const SendToDialog = imports.sendToDialog;
+
+var Button = {
+ NONE: 0,
+ ROUTE: 2,
+ SEND_TO: 4,
+ FAVORITE: 8,
+ CHECK_IN: 16,
+ EDIT_ON_OSM: 32,
+};
+
+var PlaceButtons = GObject.registerClass({
+ Template: 'resource:///org/gnome/Maps/ui/place-buttons.ui',
+ InternalChildren: [ 'routeButton',
+ 'sendToButton',
+ 'favoriteButton',
+ 'editButton',
+ 'favoriteButtonImage' ],
+}, class PlaceButtons extends Gtk.Box {
+ _init(params) {
+ let buttonFlags = params.buttonFlags;
+ delete params.buttonFlags;
+
+ this._place = params.place;
+ delete params.place;
+
+ this._mapView = params.mapView;
+ delete params.mapView;
+
+ super._init(params);
+
+ if (buttonFlags & Button.ROUTE)
+ this._initRouteButton(this._routeButton);
+ if (buttonFlags & Button.SEND_TO)
+ this.initSendToButton(this._sendToButton, buttonFlags & Button.CHECK_IN);
+ if (buttonFlags & Button.FAVORITE)
+ this._initFavoriteButton(this._favoriteButton, this._favoriteButtonImage);
+ if (buttonFlags & Button.EDIT_ON_OSM)
+ this._initEditButton(this._editButton);
+ }
+
+ 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();
+ });
+ }
+
+ _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);
+ }
+ });
+ }
+
+ _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;
+
+ 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;
+ }
+ });
+ }
+});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]