From 5a920b2c614dff0acda19c073cb30a473b8f850c Mon Sep 17 00:00:00 2001 From: Theo Linkspfeifer Date: Fri, 28 Feb 2020 11:40:04 +0100 Subject: [PATCH] Sort device entries in tree view (Bug #16471) --- thunar/thunar-tree-model.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/thunar/thunar-tree-model.c b/thunar/thunar-tree-model.c index 32bcc0da..17d9bf55 100644 --- a/thunar/thunar-tree-model.c +++ b/thunar/thunar-tree-model.c @@ -1075,12 +1075,26 @@ thunar_tree_model_device_added (ThunarDeviceMonitor *device_monitor, _thunar_return_if_fail (THUNAR_IS_DEVICE (device)); _thunar_return_if_fail (THUNAR_IS_TREE_MODEL (model)); + /* lookup the last child of the root (the "File System" node) */ + node = g_node_last_child (model->root); + + /* determine the position for the new node in the item list */ + for (node = node->prev; node != NULL; node = node->prev) + { + item = THUNAR_TREE_MODEL_ITEM (node->data); + if (item->device == NULL) + break; + + /* sort devices by timestamp */ + if (thunar_device_sort (item->device, device) < 0) + break; + } + /* allocate a new item for the volume */ item = thunar_tree_model_item_new_with_device (model, device); - /* insert before the last child of the root (the "File System" node) */ - node = g_node_last_child (model->root); - node = g_node_insert_data_before (model->root, node, item); + /* insert the new node */ + node = g_node_insert_data_after (model->root, node, item); /* determine the iterator for the new node */ GTK_TREE_ITER_INIT (iter, model->stamp, node); -- 2.25.0