This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch main
in repository explore.

View the commit online.

commit c82a811c3ed78648026c5b8e9ec681b5c11adabe
Author: Alastair Poole <[email protected]>
AuthorDate: Tue Dec 1 00:14:56 2026 +0000

    pane: only update items which change
---
 src/bin/explore_pane.c      | 123 +++++++++++++++++++++++++++++++++++++++-----
 src/lib/explore_directory.c |  19 ++++---
 src/lib/explore_directory.h |   1 +
 3 files changed, 123 insertions(+), 20 deletions(-)

diff --git a/src/bin/explore_pane.c b/src/bin/explore_pane.c
index 1ceb1cc..fe697d5 100644
--- a/src/bin/explore_pane.c
+++ b/src/bin/explore_pane.c
@@ -518,6 +518,36 @@ explore_pane_restore_scroll(void *data)
    return ECORE_CALLBACK_CANCEL;
 }
 
+static Eina_Bool
+explore_pane_file_visible(const Explore_Pane *pane, const Explore_File *file)
+{
+   return (pane->window->settings.hidden || file->name[0] != '.' ||
+           !strcmp(pane->path, EXPLORE_TRASH_PATH)) &&
+          (!pane->filter || strcasestr(file->name, pane->filter));
+}
+
+static Elm_Object_Item *
+explore_pane_item_add(Explore_Pane *pane, Explore_File *file, Elm_Object_Item *before)
+{
+   Explore_Window *window;
+
+   window = pane->window;
+   if (pane->items_grid)
+     {
+        if (before)
+          return elm_gengrid_item_insert_before(pane->items, window->grid_class, file,
+                                                before, explore_pane_selected, pane);
+        return elm_gengrid_item_append(pane->items, window->grid_class, file,
+                                       explore_pane_selected, pane);
+     }
+   if (before)
+     return elm_genlist_item_insert_before(pane->items, window->list_class, file, NULL,
+                                           before, ELM_GENLIST_ITEM_NONE,
+                                           explore_pane_selected, pane);
+   return elm_genlist_item_append(pane->items, window->list_class, file, NULL,
+                                  ELM_GENLIST_ITEM_NONE, explore_pane_selected, pane);
+}
+
 static Eina_Bool
 explore_pane_populate(void *data)
 {
@@ -536,17 +566,9 @@ explore_pane_populate(void *data)
 
         file = eina_list_data_get(pane->next_file);
         pane->next_file = eina_list_next(pane->next_file);
-        if (!window->settings.hidden && file->name[0] == '.' &&
-            strcmp(pane->path, EXPLORE_TRASH_PATH)) continue;
-        if (pane->filter && !strcasestr(file->name, pane->filter)) continue;
+        if (!explore_pane_file_visible(pane, file)) continue;
         pane->matches++;
-
-        if (grid)
-          item = elm_gengrid_item_append(pane->items, window->grid_class, file,
-                                         explore_pane_selected, pane);
-        else
-          item = elm_genlist_item_append(pane->items, window->list_class, file, NULL,
-                                         ELM_GENLIST_ITEM_NONE, explore_pane_selected, pane);
+        item = explore_pane_item_add(pane, file, NULL);
         if (item && pane->restore_anchor_path && !strcmp(file->path, pane->restore_anchor_path))
           pane->restore_anchor = item;
         if (item && pane->restore_neighbor_path && !strcmp(file->path, pane->restore_neighbor_path))
@@ -860,6 +882,82 @@ explore_pane_history_go(Explore_Pane *pane, Eina_Bool forward)
    explore_pane_load(pane, eina_list_data_get(target), EINA_FALSE);
 }
 
+static void
+explore_pane_item_refresh(Explore_Pane *pane, Elm_Object_Item *item, Explore_File *file)
+{
+   const Explore_File *old;
+
+   old = elm_object_item_data_get(item);
+   elm_object_item_data_set(item, file);
+   if (old->thumbnail_ready == file->thumbnail_ready &&
+       ((!old->thumbnail && !file->thumbnail) ||
+        (old->thumbnail && file->thumbnail && !strcmp(old->thumbnail, file->thumbnail))) &&
+       old->info.st_mode == file->info.st_mode &&
+       old->info.st_size == file->info.st_size &&
+       old->info.st_mtim.tv_sec == file->info.st_mtim.tv_sec &&
+       old->info.st_mtim.tv_nsec == file->info.st_mtim.tv_nsec &&
+       old->info.st_ino == file->info.st_ino &&
+       old->info.st_dev == file->info.st_dev) return;
+
+   if (pane->items_grid) elm_gengrid_item_update(item);
+   else elm_genlist_item_update(item);
+}
+
+static Elm_Object_Item *
+explore_pane_item_remove(Explore_Pane *pane, Elm_Object_Item *item)
+{
+   Elm_Object_Item *next;
+
+   next = pane->items_grid ? elm_gengrid_item_next_get(item) : elm_genlist_item_next_get(item);
+   if (pane->restore_anchor == item) pane->restore_anchor = NULL;
+   if (pane->restore_neighbor == item) pane->restore_neighbor = NULL;
+   elm_object_item_del(item);
+   return next;
+}
+
+static Eina_Bool
+explore_pane_update_items(Explore_Pane *pane)
+{
+   Elm_Object_Item *item;
+   Eina_List *node;
+   Explore_File *file;
+
+   if (!pane->items || pane->restore_selection ||
+       (pane->populate && (pane->restore_scroll_x || pane->restore_scroll_y)))
+     return EINA_FALSE;
+
+   if (pane->populate)
+     {
+        ecore_idler_del(pane->populate);
+        pane->populate = NULL;
+        pane->next_file = NULL;
+     }
+   pane->matches = 0;
+   item = pane->items_grid ? elm_gengrid_first_item_get(pane->items) :
+                             elm_genlist_first_item_get(pane->items);
+
+   /* Both sequences are in directory sort order. Keep matching widgets in place. */
+   EINA_LIST_FOREACH(pane->files, node, file)
+     {
+        if (!explore_pane_file_visible(pane, file)) continue;
+        pane->matches++;
+        while (item && explore_file_compare(elm_object_item_data_get(item), file) < 0)
+          item = explore_pane_item_remove(pane, item);
+        if (item && !explore_file_compare(elm_object_item_data_get(item), file))
+          {
+             explore_pane_item_refresh(pane, item, file);
+             item = pane->items_grid ? elm_gengrid_item_next_get(item) :
+                                       elm_genlist_item_next_get(item);
+          }
+        else if (!explore_pane_item_add(pane, file, item))
+          return EINA_FALSE;
+     }
+   while (item)
+     item = explore_pane_item_remove(pane, item);
+
+   return EINA_TRUE;
+}
+
 static void
 explore_pane_loaded(void *owner, void *data)
 {
@@ -941,13 +1039,14 @@ explore_pane_loaded(void *owner, void *data)
         free(markup);
      }
 
-   /* Item callbacks still reference the previous model while widgets are destroyed. */
+   /* Keep the old model alive while items still reference it. */
    old_files = pane->files;
    pane->files = directory->files;
    pane->count = directory->count;
    pane->visible = directory->visible;
    directory->files = NULL;
-   explore_pane_render_items(pane, directory->refresh);
+   if (!directory->refresh || !explore_pane_update_items(pane))
+     explore_pane_render_items(pane, directory->refresh);
    explore_directory_free(old_files);
    if (pane == pane->window->active)
      {
diff --git a/src/lib/explore_directory.c b/src/lib/explore_directory.c
index d4fac51..88dfcbe 100644
--- a/src/lib/explore_directory.c
+++ b/src/lib/explore_directory.c
@@ -12,18 +12,21 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
-static int
-explore_file_compare(const void *left, const void *right)
+int
+explore_file_compare(const Explore_File *a, const Explore_File *b)
 {
-   const Explore_File *a, *b;
    int order;
 
-   a = left;
-   b = right;
-
    if (a->directory != b->directory) return a->directory ? -1 : 1;
    order = strcasecmp(a->name, b->name);
-   return order ? order : strcmp(a->name, b->name);
+   if (!order) order = strcmp(a->name, b->name);
+   return order ? order : strcmp(a->path, b->path);
+}
+
+static int
+explore_directory_compare(const void *left, const void *right)
+{
+   return explore_file_compare(left, right);
 }
 
 static void
@@ -194,7 +197,7 @@ explore_directory_load(void *data, Ecore_Thread *thread)
         if (!directory->path || !explore_directory_read(directory, directory->path, NULL, thread))
           directory->error = errno;
      }
-   directory->files = eina_list_sort(directory->files, 0, explore_file_compare);
+   directory->files = eina_list_sort(directory->files, 0, explore_directory_compare);
 }
 
 void
diff --git a/src/lib/explore_directory.h b/src/lib/explore_directory.h
index 310c444..830d30e 100644
--- a/src/lib/explore_directory.h
+++ b/src/lib/explore_directory.h
@@ -25,6 +25,7 @@ typedef struct
 Explore_Directory *explore_directory_new(const char *path, const char *cache, Eina_Bool refresh);
 void explore_directory_load(void *data, Ecore_Thread *thread);
 void explore_directory_destroy(void *data);
+int explore_file_compare(const Explore_File *a, const Explore_File *b);
 void explore_directory_free(Eina_List *files);
 
 #endif

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to