Fix drag URI handling to prevent crash
This commit is contained in:
parent
93bd8a1424
commit
2239c5cf3a
|
|
@ -267,16 +267,17 @@ func preferDark() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupDragDest(p *pane, win *gtk.Window) {
|
func setupDragDest(p *pane, win *gtk.Window) {
|
||||||
// Accept URI drops
|
// Accept URI drops using a target list
|
||||||
if target, err := gtk.TargetEntryNew("text/uri-list", gtk.TARGET_OTHER_APP, 0); err == nil {
|
p.area.DragDestSet(gtk.DEST_DEFAULT_ALL, nil, gdk.ACTION_COPY)
|
||||||
p.area.DragDestSet(gtk.DEST_DEFAULT_ALL, []gtk.TargetEntry{*target}, 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) {
|
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()
|
uris := data.GetURIs()
|
||||||
if len(uris) == 0 {
|
if len(uris) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Take first URI
|
|
||||||
if path := uriToPath(uris[0]); path != "" {
|
if path := uriToPath(uris[0]); path != "" {
|
||||||
loadIntoPane(p, path)
|
loadIntoPane(p, path)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user