Fix drag URI handling to prevent crash

This commit is contained in:
Stu 2025-12-13 22:30:37 -05:00
parent 93bd8a1424
commit 2239c5cf3a

View File

@ -267,16 +267,17 @@ func preferDark() {
}
func setupDragDest(p *pane, win *gtk.Window) {
// Accept URI drops
if target, err := gtk.TargetEntryNew("text/uri-list", gtk.TARGET_OTHER_APP, 0); err == nil {
p.area.DragDestSet(gtk.DEST_DEFAULT_ALL, []gtk.TargetEntry{*target}, gdk.ACTION_COPY)
// Accept URI drops using a target list
p.area.DragDestSet(gtk.DEST_DEFAULT_ALL, nil, gdk.ACTION_COPY)
if tl, err := gtk.TargetListNew([]gtk.TargetEntry{}); err == nil && tl != nil {
tl.AddURITargets(0)
p.area.DragDestSetTargetList(tl)
}
p.area.Connect("drag-data-received", func(_ *gtk.DrawingArea, ctx *gdk.DragContext, x, y int, data *gtk.SelectionData, info uint, t uint32) {
uris := data.GetURIs()
if len(uris) == 0 {
return
}
// Take first URI
if path := uriToPath(uris[0]); path != "" {
loadIntoPane(p, path)
}