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

git pushed a commit to branch master
in repository edi.

View the commit online.

commit 84398685158fc198cdb647686757fe01e37c480a
Author: Alastair Poole <[email protected]>
AuthorDate: Tue Apr 14 22:23:31 2026 +0100

    filepanel: select file and expand file panel item.
    
    When a file is seleted ensure we navigate safely to the item
    within the filepanel and bring that region into view.
    
    This adds continuity between the panel/editor and the file selector.
---
 src/bin/edi_filepanel.c | 151 ++++++++++++++++++++++++++++++++++++++++++++----
 src/bin/edi_main.c      |  11 ++++
 2 files changed, 152 insertions(+), 10 deletions(-)

diff --git a/src/bin/edi_filepanel.c b/src/bin/edi_filepanel.c
index 821c6e4..b1279d2 100644
--- a/src/bin/edi_filepanel.c
+++ b/src/bin/edi_filepanel.c
@@ -39,10 +39,13 @@ static const char *_root_path;
 static regex_t _filter_regex;
 static Eina_Bool _filter_set = EINA_FALSE;
 static Edi_Dir_Data *_root_dir;
+static const char *_path_select_pending;
 
 static Elm_Object_Item * _file_listing_item_find(const char *path);
 static void _file_listing_fill(Edi_Dir_Data *dir, Elm_Object_Item *parent_it);
 static void _file_listing_empty(Edi_Dir_Data *dir, Elm_Object_Item *parent_it);
+static void _edi_filepanel_select_next_best_path(const char *path);
+static Eina_Bool _edi_filepanel_select_pending_path_try(void);
 
 static Eina_Bool
 _file_path_hidden(const char *path, Eina_Bool filter)
@@ -922,6 +925,7 @@ _on_list_expanded(void *data EINA_UNUSED,
 
    edi_filepanel_scm_status_update();
    _file_listing_fill(sd, it);
+   _edi_filepanel_select_pending_path_try();
 }
 
 static void
@@ -940,6 +944,130 @@ static Elm_Object_Item *_file_listing_item_find(const char *path)
    return  eina_hash_find(_list_items, path);
 }
 
+static Eina_Bool
+_path_is_in_project(const char *path)
+{
+   size_t rootlen = strlen(edi_project_get());
+
+   if (strncmp(path, edi_project_get(), rootlen))
+     return EINA_FALSE;
+
+   return path[rootlen] == '\0' || path[rootlen] == '/';
+}
+
+static Eina_Bool
+_select_item_path(const char *path)
+{
+   Elm_Object_Item *item;
+
+   item = _file_listing_item_find(path);
+   if (!item)
+     return EINA_FALSE;
+
+   if (!elm_genlist_item_selected_get(item))
+     elm_genlist_item_selected_set(item, EINA_TRUE);
+
+   elm_genlist_item_bring_in(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
+   return EINA_TRUE;
+}
+
+static Eina_Bool
+_expand_to_path(const char *path)
+{
+   Elm_Object_Item *item;
+   char *dir;
+   char *cursor;
+   char *sep;
+   size_t rootlen;
+   Eina_Bool ready = EINA_TRUE;
+
+   if (!_path_is_in_project(path))
+     return EINA_TRUE;
+
+   dir = strdup(path);
+   if (!dir)
+     return EINA_TRUE;
+
+   sep = strrchr(dir, '/');
+   if (!sep)
+     {
+        free(dir);
+        return EINA_TRUE;
+     }
+   *sep = '\0';
+
+   rootlen = strlen(edi_project_get());
+   if (strlen(dir) <= rootlen)
+     {
+        free(dir);
+        return EINA_TRUE;
+     }
+
+   for (cursor = dir + rootlen + 1; *cursor; cursor++)
+     {
+        if (*cursor != '/')
+          continue;
+
+        *cursor = '\0';
+        item = _file_listing_item_find(dir);
+        *cursor = '/';
+        if (!item)
+          {
+             ready = EINA_FALSE;
+             break;
+          }
+
+        if (elm_genlist_item_type_get(item) == ELM_GENLIST_ITEM_TREE &&
+            !elm_genlist_item_expanded_get(item))
+          {
+             elm_genlist_item_expanded_set(item, EINA_TRUE);
+             ready = EINA_FALSE;
+             break;
+          }
+     }
+
+   if (ready)
+     {
+        item = _file_listing_item_find(dir);
+        if (!item)
+          ready = EINA_FALSE;
+        else if (elm_genlist_item_type_get(item) == ELM_GENLIST_ITEM_TREE &&
+                 !elm_genlist_item_expanded_get(item))
+          {
+             elm_genlist_item_expanded_set(item, EINA_TRUE);
+             ready = EINA_FALSE;
+          }
+     }
+
+   free(dir);
+   return ready;
+}
+
+static Eina_Bool
+_edi_filepanel_select_pending_path_try(void)
+{
+   if (!_path_select_pending)
+     return EINA_FALSE;
+
+   if (_select_item_path(_path_select_pending))
+     {
+        eina_stringshare_del(_path_select_pending);
+        _path_select_pending = NULL;
+        return EINA_TRUE;
+     }
+
+   if (!_path_is_in_project(_path_select_pending))
+     {
+        _edi_filepanel_select_next_best_path(_path_select_pending);
+        eina_stringshare_del(_path_select_pending);
+        _path_select_pending = NULL;
+     }
+   else
+     _expand_to_path(_path_select_pending);
+
+   return EINA_FALSE;
+}
+
 static void
 _file_listing_item_insert(const char *path, Eina_Bool isdir, Elm_Object_Item *parent_it)
 {
@@ -1001,6 +1129,9 @@ _ls_main_cb(void *data, Eio_File *handler, const Eina_File_Direct_Info *info)
 //   _signal_first(lreq);
 
    _file_listing_item_insert(info->path, info->type == EINA_FILE_DIR, lreq->parent_it);
+
+   if (_path_select_pending && !strcmp(info->path, _path_select_pending))
+     _edi_filepanel_select_pending_path_try();
 }
 
 static void
@@ -1009,6 +1140,8 @@ _ls_done_cb(void *data, Eio_File *handler EINA_UNUSED)
    Listing_Request *lreq = data;
 
    edi_filepanel_scm_status_update();
+   _edi_filepanel_select_pending_path_try();
+
    _listing_request_cleanup(lreq);
 }
 
@@ -1201,6 +1334,9 @@ edi_filepanel_refresh_all(void)
    _root_dir = calloc(1, sizeof(Edi_Dir_Data));
    _root_dir->path = edi_project_get();
 
+   eina_stringshare_del(_path_select_pending);
+   _path_select_pending = NULL;
+
    _file_listing_fill(_root_dir, NULL);
    elm_genlist_realized_items_update(_list);
 }
@@ -1208,20 +1344,15 @@ edi_filepanel_refresh_all(void)
 void
 edi_filepanel_select_path(const char *path)
 {
-   Elm_Object_Item *item;
-
-   item = _file_listing_item_find(path);
-   if (!item)
+   if (_select_item_path(path))
      {
-        _edi_filepanel_select_next_best_path(path);
+        eina_stringshare_del(_path_select_pending);
+        _path_select_pending = NULL;
         return;
      }
 
-   if (elm_genlist_item_selected_get(item))
-     return;
-
-   elm_genlist_item_selected_set(item, EINA_TRUE);
-   elm_genlist_item_bring_in(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
+   eina_stringshare_replace(&_path_select_pending, path);
+   _edi_filepanel_select_pending_path_try();
 }
 
 void
diff --git a/src/bin/edi_main.c b/src/bin/edi_main.c
index d09e526..39c25fb 100644
--- a/src/bin/edi_main.c
+++ b/src/bin/edi_main.c
@@ -45,6 +45,7 @@ static Evas_Object *_edi_logpanel, *_edi_consolepanel, *_edi_testpanel, *_edi_se
 static Elm_Object_Item *_edi_logpanel_item, *_edi_consolepanel_item, *_edi_testpanel_item, *_edi_searchpanel_item, *_edi_taskspanel_item, *_edi_debugpanel_item;
 static Elm_Object_Item *_edi_selected_bottompanel;
 static Evas_Object *_edi_filepanel, *_edi_filepanel_icon;
+static const char *_edi_filepanel_selected_path;
 
 static Evas_Object *_edi_toolbar_save, *_edi_toolbar_undo, *_edi_toolbar_redo, *_edi_toolbar_build, *_edi_toolbar_test, *_edi_toolbar_clean;
 static Evas_Object *_edi_toolbar_run, *_edi_toolbar_terminate, *_edi_toolbar_hbx, *_edi_toolbar_vbx, *_edi_toolbar_main_box;
@@ -266,6 +267,7 @@ static void
 _edi_toggle_file_panel(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
 {
    Evas_Object *panel;
+   const char *selected;
    double size;
 
    panel = (Evas_Object *)data;
@@ -275,9 +277,16 @@ _edi_toggle_file_panel(void *data, Evas_Object *obj EINA_UNUSED, void *event_inf
      {
         elm_icon_standard_set(_edi_filepanel_icon, "go-previous");
         _edi_slide_panel_new(_edi_leftpanes, panel, _edi_project_config->gui.leftsize, EINA_TRUE, EINA_TRUE);
+
+        if (_edi_filepanel_selected_path)
+          edi_filepanel_select_path(_edi_filepanel_selected_path);
      }
    else
      {
+        selected = edi_filepanel_selected_path_get(panel);
+        if (selected)
+          eina_stringshare_replace(&_edi_filepanel_selected_path, selected);
+
         elm_icon_standard_set(_edi_filepanel_icon, "go-next");
         _edi_slide_panel_new(_edi_leftpanes, panel, _edi_project_config->gui.leftsize, EINA_FALSE, EINA_TRUE);
      }
@@ -2047,6 +2056,8 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
    elm_run();
 
  end:
+   eina_stringshare_del(_edi_filepanel_selected_path);
+   _edi_filepanel_selected_path = NULL;
    _edi_log_shutdown();
    edi_listen_shutdown();
    elm_shutdown();

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

Reply via email to