Fix sorting of tree view elements

https://stackoverflow.com/questions/9194588/how-to-programmatically-sort-treeview
This commit is contained in:
Arjan Molenaar 2021-09-19 21:10:04 +02:00
parent 4a00cfcf96
commit d14a800781

View File

@ -3,6 +3,7 @@ from __future__ import annotations
import logging
from typing import TYPE_CHECKING
from gaphas.decorators import g_async
from gi.repository import Gtk
from gaphor import UML
@ -206,6 +207,14 @@ class NamespaceModel(Gtk.TreeStore):
if iter:
path = self.get_path(iter)
self.row_changed(path, iter)
self.sort()
@g_async(single=True)
def sort(self):
self.set_sort_column_id(
Gtk.TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID, Gtk.SortType.ASCENDING
)
self.set_sort_column_id(0, Gtk.SortType.ASCENDING)
def do_row_draggable(self, path):
return True