[gnome-maps/wip/mlundblad/fix-drag-n-drop-routes] sidebar: Fix drag-and-dropping route entries
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/fix-drag-n-drop-routes] sidebar: Fix drag-and-dropping route entries
- Date: Thu, 29 Sep 2022 20:45:23 +0000 (UTC)
commit 73796ec4b479dd35d110cfec41da13f9f4c0ac53
Author: Marcus Lundblad <ml dfupdate se>
Date: Thu Sep 29 22:43:57 2022 +0200
sidebar: Fix drag-and-dropping route entries
This was not working since the GTK4 port.
src/sidebar.js | 51 ++++++++++++++-------------------------------------
1 file changed, 14 insertions(+), 37 deletions(-)
---
diff --git a/src/sidebar.js b/src/sidebar.js
index 5a44c2a8..fc722194 100644
--- a/src/sidebar.js
+++ b/src/sidebar.js
@@ -559,51 +559,25 @@ export class Sidebar extends Gtk.Revealer {
return true;
}
- _dragHighlightRow(row) {
- row.opacity = 0.6;
- }
-
- _dragUnhighlightRow(row) {
- row.opacity = 1.0;
- }
-
- // Set the opacity of the row we are currently dragging above
- // to semi transparent.
- _onDragMotion(row, context, x, y, time) {
- let routeEntry = row.get_child();
-
- if (this._draggedPoint && this._draggedPoint !== routeEntry.point) {
- this._dragHighlightRow(row);
- Gdk.drag_status(context, Gdk.DragAction.MOVE, time);
- } else
- Gdk.drag_status(context, 0, time);
- return true;
- }
-
// Drag ends, show the dragged row again.
_onDragEnd(row) {
this._draggedPoint = null;
+ row.opacity = 1.0;
+ }
- // Restore to natural height
- row.height_request = -1;
- row.get_child().show();
+ _onDragPrepare(routeEntry, source, x, y) {
+ return Gdk.ContentProvider.new_for_value(routeEntry);
}
- // Drag begins, set the correct drag icon and hide the dragged row.
+ // Drag begins, set the correct drag icon and dim the dragged row.
_onDragBegin(source, row) {
let routeEntry = row.get_child();
let {x, y, width, height} = row.get_allocation();
-
- this._draggedPoint = routeEntry.point;
-
- // Set a fixed height on the row to prevent the sidebar height
- // to shrink while dragging a row.
- row.height_request = height;
- row.get_child().hide();
-
- let paintable = new Gtk.WidgetPaintable(row);
+ let paintable = new Gtk.WidgetPaintable({ widget: routeEntry });
source.set_icon(paintable, 0, 0);
+ this._draggedPoint = routeEntry.point;
+ row.opacity = 0.6;
}
// Set up drag and drop between RouteEntrys. The drag source is from a
@@ -616,17 +590,20 @@ export class Sidebar extends Gtk.Revealer {
dragIcon.add_controller(dragSource);
+ dragSource.connect('prepare',
+ this._onDragPrepare.bind(this, routeEntry));
dragSource.connect('drag-begin',
- (source, drag, widget) => this._onDragBegin(source, row));
+ (source, drag, widget) =>
+ this._onDragBegin(source, row));
dragSource.connect('drag-end',
(source, dele, data) => this._onDragEnd(row));
- let dropTarget = Gtk.DropTarget.new(RouteEntry, Gdk.DragAction.MOVE);
+ let dropTarget = Gtk.DropTarget.new(RouteEntry, Gdk.DragAction.COPY);
row.add_controller(dropTarget);
dropTarget.connect('drop',
- (target, value, x, y, data) => this._onDragDrop(target));
+ (target, value, x, y, data) => this._onDragDrop(row));
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]