diff options
author | Marcus Lundblad <ml@update.uu.se> | 2020-01-29 21:02:32 +0100 |
---|---|---|
committer | Marcus Lundblad <ml@update.uu.se> | 2020-01-30 21:17:11 +0100 |
commit | 6d2ffc379494086cf94b57fb3717e8c6bebc5898 (patch) | |
tree | b8456232a2f04062a6f9e63a91965d9a18ec2482 | |
parent | 828cf3dc9a5625086034b21bf472119759d183d6 (diff) | |
download | gnome-maps-wip/mlundblad/restructure-routing-items.tar.gz |
contextMenu: Allow setting route start/end directlywip/mlundblad/restructure-routing-items
Add individual menu options for setting start and
end points, and adding intermediate destinations,
allowing modifying query without clearing and
starting over.
-rw-r--r-- | data/ui/context-menu.ui | 34 | ||||
-rw-r--r-- | src/contextMenu.js | 57 |
2 files changed, 62 insertions, 29 deletions
diff --git a/data/ui/context-menu.ui b/data/ui/context-menu.ui index 6f3e54ca..7fcb6734 100644 --- a/data/ui/context-menu.ui +++ b/data/ui/context-menu.ui @@ -4,6 +4,33 @@ <template class="Gjs_ContextMenu" parent="GtkMenu"> <property name="visible">False</property> <child> + <object class="GtkMenuItem" id="routeFromHereItem"> + <property name="name">route-from-here-item</property> + <property name="label" translatable="yes">Route from here</property> + <property name="visible">True</property> + </object> + </child> + <child> + <object class="GtkMenuItem" id="addIntermediateDestinationItem"> + <property name="name">add-itermediate-destination-item</property> + <property name="label" translatable="yes">Add intermediate destination</property> + <property name="visible">True</property> + <property name="sensitive">False</property> + </object> + </child> + <child> + <object class="GtkMenuItem" id="routeToHereItem"> + <property name="name">route-to-here-item</property> + <property name="label" translatable="yes">Route to here</property> + <property name="visible">True</property> + </object> + </child> + <child> + <object class="GtkSeparatorMenuItem"> + <property name="visible">True</property> + </object> + </child> + <child> <object class="GtkMenuItem" id="whatsHereItem"> <property name="name">whats-here-item</property> <property name="label" translatable="yes">What’s here?</property> @@ -17,12 +44,7 @@ <property name="visible">True</property> </object> </child> - <child> - <object class="GtkMenuItem" id="routeItem"> - <property name="name">route-item</property> - <property name="visible">True</property> - </object> - </child> + <child> <object class="GtkMenuItem" id="addOSMLocationItem"> <property name="name">add-osm-location-item</property> diff --git a/src/contextMenu.js b/src/contextMenu.js index 699025de..6a4727a2 100644 --- a/src/contextMenu.js +++ b/src/contextMenu.js @@ -41,7 +41,9 @@ var ContextMenu = GObject.registerClass({ InternalChildren: [ 'whatsHereItem', 'geoURIItem', 'addOSMLocationItem', - 'routeItem' ], + 'routeFromHereItem', + 'addIntermediateDestinationItem', + 'routeToHereItem' ], }, class ContextMenu extends Gtk.Menu { _init(params) { this._mapView = params.mapView; @@ -61,11 +63,14 @@ var ContextMenu = GObject.registerClass({ this._onGeoURIActivated.bind(this)); this._addOSMLocationItem.connect('activate', this._onAddOSMLocationActivated.bind(this)); - this._routeItem.connect('activate', - this._onRouteActivated.bind(this)); + this._routeFromHereItem.connect('activate', + this._onRouteFromHereActivated.bind(this)); + this._addIntermediateDestinationItem.connect('activate', + this._onAddIntermediateDestinationActivated.bind(this)); + this._routeToHereItem.connect('activate', + this._onRouteToHereActivated.bind(this)); Application.routeQuery.connect('notify::points', this._routingUpdate.bind(this)); - this._routeItem.visible = false; this._routingUpdate(); } @@ -83,36 +88,42 @@ var ContextMenu = GObject.registerClass({ _routingUpdate() { let query = Application.routeQuery; + let numPoints = query.points.length; - this._routeItem.sensitive = query.points.length < RouteQuery.MAX_QUERY_POINTS; + this._routeFromHereItem.sensitive = numPoints < RouteQuery.MAX_QUERY_POINTS; + this._routeToHereItem.sensitive = numPoints < RouteQuery.MAX_QUERY_POINTS; + this._addIntermediateDestinationItem.sensitive = + query.filledPoints.length >= 2 && numPoints < RouteQuery.MAX_QUERY_POINTS; + } - if (query.points.length === 0) - return; + _onRouteFromHereActivated() { + let query = Application.routeQuery; + let location = new Location.Location({ latitude: this._latitude, + longitude: this._longitude, + accuracy: 0 }); + let place = new Place.Place({ location: location }); - this._routeItem.visible = true; - if (!query.points[0].place) { - this._routeItem.label = _("Route from here"); - } else if (query.filledPoints.length > 1) { - this._routeItem.label = _("Add destination"); - } else { - this._routeItem.label = _("Route to here"); - } + query.points[0].place = place; } - _onRouteActivated() { + _onRouteToHereActivated() { let query = Application.routeQuery; let location = new Location.Location({ latitude: this._latitude, longitude: this._longitude, accuracy: 0 }); let place = new Place.Place({ location: location }); - if (!query.points[0].place) { - query.points[0].place = place; - } else if (query.filledPoints.length > 1) { - query.addPoint(-1).place = place; - } else { - query.points[query.points.length - 1].place = place; - } + query.points.last().place = place; + } + + _onAddIntermediateDestinationActivated() { + let query = Application.routeQuery; + let location = new Location.Location({ latitude: this._latitude, + longitude: this._longitude, + accuracy: 0 }); + let place = new Place.Place({ location: location }); + + query.addPoint(-1).place = place; } _onWhatsHereActivated() { |