The now deprecated Gtk ListStore implemented drag & drop, but its replacement, Gio ListStore documentation says nothing about such functionality.
So how does it work now, how to make Gtk.ListView items be drag & droppable / re-orderable?
For reference here is the code:
class ModelObject(GObject.GObject):
__gtype_name__ = 'ModelObject'
def __init__(self, name):
super().__init__()
self._name = os.path.basename(name)
self._path = name
@GObject.Property(type=str)
def name(self):
return self._name
@GObject.Property(type=str)
def path(self):
return self._path
model = Gio.ListStore.new(ModelObject)
selection = Gtk.SingleSelection.new(model)
def __init__(self, **kwargs):
super().__init__(**kwargs)
factory = Gtk.BuilderListItemFactory.new_from_resource(None, '/org/yphil/matinee/resources/listitem.ui')
self.listView = Gtk.ListView.new(self.selection, factory)
self.scrolledWindow.set_child(self.listView)
And here is the listitem.ui resource:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GtkListItem">
<property name="child">
<object class="GtkLabel">
<binding name="label">
<lookup name="name" type="ModelObject">
<lookup name="item">GtkListItem</lookup>
</lookup>
</binding>
</object>
</property>
</template>
</interface>
Yes this is Python, but I only need to understand the logic and I can’t seem to find any information, in any language, specific to this new implementation.