[gnome-maps/wip/mlundblad/long-press-context-menu] mapView: Open the context menu on long-press
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/long-press-context-menu] mapView: Open the context menu on long-press
- Date: Wed, 31 Aug 2022 21:28:41 +0000 (UTC)
commit 2a03b39bac727bd83232e896706e2e7e0ef0c64b
Author: Marcus Lundblad <ml dfupdate se>
Date: Wed Aug 31 23:26:42 2022 +0200
mapView: Open the context menu on long-press
Trigger the context menu also on long-press on
touch.
src/mapView.js | 38 ++++++++++++++++++++++++++------------
1 file changed, 26 insertions(+), 12 deletions(-)
---
diff --git a/src/mapView.js b/src/mapView.js
index 37fde131..bf5fe02a 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -197,6 +197,11 @@ export class MapView extends Gtk.Overlay {
this._clickGesture = new Gtk.GestureClick({ button: Gdk.BUTTON_SECONDARY });
this._clickGesture.connect('pressed', this._onClickGesturePressed.bind(this));
this.add_controller(this._clickGesture);
+
+ this._longPressGesture = new Gtk.GestureLongPress();;
+ this._longPressGesture.connect('pressed',
+ this._onLongPressGesturePressed.bind(this));
+ this.add_controller(this._longPressGesture);
}
vfunc_size_allocate(width, height, baseline) {
@@ -967,23 +972,32 @@ export class MapView extends Gtk.Overlay {
let event = gesture.get_current_event();
if (event.triggers_context_menu()) {
- let viewport = this.map.viewport;
- let rect = new Gdk.Rectangle({ x: x, y: y, width: 0, height: 0 });
+ this._showContextMenuAt(gesture, x, y);
+ gesture.set_state(Gtk.EventSequenceState.CLAIMED);
+ }
- [this._latitude, this._longitude] = viewport.widget_coords_to_location(this, x, y);
+ gesture.set_state(Gtk.EventSequenceState.DENIED);
+ }
- if (this.direction === Gtk.TextDirection.RTL) {
- this._contextMenu.halign = Gtk.Align.END;
- } else {
- this._contextMenu.halign = Gtk.Align.START;
- }
+ _onLongPressGesturePressed(gesture, x, y) {
+ this._showContextMenuAt(gesture, x, y);
+ gesture.set_state(Gtk.EventSequenceState.CLAIMED);
+ }
- this._contextMenu.pointing_to = rect;
- this._contextMenu.popup();
- gesture.set_state(Gtk.EventSequenceState.CLAIMED);
+ _showContextMenuAt(gesture, x, y) {
+ let viewport = this.map.viewport;
+ let rect = new Gdk.Rectangle({ x: x, y: y, width: 0, height: 0 });
+
+ [this._latitude, this._longitude] = viewport.widget_coords_to_location(this, x, y);
+
+ if (this.direction === Gtk.TextDirection.RTL) {
+ this._contextMenu.halign = Gtk.Align.END;
+ } else {
+ this._contextMenu.halign = Gtk.Align.START;
}
- gesture.set_state(Gtk.EventSequenceState.DENIED);
+ this._contextMenu.pointing_to = rect;
+ this._contextMenu.popup();
}
_onRouteFromHereActivated() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]