Skip to content

Commit aeea1bf

Browse files
committed
port: Drag and Drop
1 parent 5cff4b0 commit aeea1bf

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Diff for: src/Drag and Drop/main.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import GObject from "gi://GObject";
33
import Gdk from "gi://Gdk?version=4.0";
44
import Gtk from "gi://Gtk?version=4.0";
55

6-
const list = workbench.builder.get_object("list");
7-
const drop_target = Gtk.DropTarget.new(Gtk.ListBoxRow, Gdk.DragAction.MOVE);
6+
const list = workbench.builder.get_object<Gtk.ListBox>("list");
7+
const drop_target = Gtk.DropTarget.new(Gtk.ListBoxRow.$gtype, Gdk.DragAction.MOVE);
88

99
list.add_controller(drop_target);
1010

1111
// Iterate over ListBox children
12-
for (const row of list) {
12+
// @ts-expect-error Gtk.ListBox is iterable
13+
// See: https://github.com/gjsify/ts-for-gir/issues/193
14+
for (const object of list) {
15+
const row = object as Adw.ActionRow;
1316
let drag_x;
1417
let drag_y;
1518

@@ -28,7 +31,7 @@ for (const row of list) {
2831
drag_y = y;
2932

3033
const value = new GObject.Value();
31-
value.init(Gtk.ListBoxRow);
34+
value.init(Gtk.ListBoxRow.$gtype);
3235
value.set_object(row);
3336

3437
return Gdk.ContentProvider.new_for_value(value);
@@ -68,7 +71,7 @@ for (const row of list) {
6871
}
6972

7073
// Drop Handling
71-
drop_target.connect("drop", (_drop, value, _x, y) => {
74+
drop_target.connect("drop", (_drop, value: Gtk.Widget, _x, y) => {
7275
const target_row = list.get_row_at_y(y);
7376
const target_index = target_row.get_index();
7477

0 commit comments

Comments
 (0)