Update: Show drag icon when reordering PrefsBoxOrderItemRows using DND

The following code from GNOME/gnome-control-center was used as a
reference to make this code work:
- ab7d752de9/panels/search/cc-search-panel-row.c (L96)
- ab7d752de9/panels/search/cc-search-panel-row.c (L84)
This commit is contained in:
Julian 2022-10-24 01:07:24 +02:00
parent 249f3554d5
commit 3299686041
Signed by: julian
GPG Key ID: 094C2AC34192FA11

View File

@ -46,13 +46,28 @@ var PrefsBoxOrderItemRow = GObject.registerClass({
// `this`.
let dragSource = new Gtk.DragSource();
dragSource.set_actions(Gdk.DragAction.MOVE);
dragSource.connect("prepare", () => {
dragSource.connect("prepare", (source, x, y) => {
this._drag_starting_point_x = x;
this._drag_starting_point_y = y;
return Gdk.ContentProvider.new_for_value(this);
});
// Stop all scrolling, which is due to this DND operation.
dragSource.connect("drag-end", () => {
scrollManager.stopScrollAll();
});
dragSource.connect("drag-begin", (source, drag) => {
let dragWidget = new Gtk.ListBox();
let allocation = this.get_allocation();
dragWidget.set_size_request(allocation.width, allocation.height);
let dragPrefsBoxOrderItemRow = new PrefsBoxOrderItemRow({}, null, this.item)
dragWidget.append(dragPrefsBoxOrderItemRow);
dragWidget.drag_highlight_row(dragPrefsBoxOrderItemRow);
let currentDragIcon = Gtk.DragIcon.get_for_drag(drag);
currentDragIcon.set_child(dragWidget);
drag.set_hotspot(this._drag_starting_point_x, this._drag_starting_point_y);
});
this.add_controller(dragSource);
/// Make `this` accept drops by creating a drop target and adding it to