[gegl] make get_item_path_no useful from lua



commit a8f77716c12104b620279d3dfbedd7b856a910c0
Author: Øyvind Kolås <pippin gimp org>
Date:   Sat Apr 27 22:40:20 2019 +0200

    make get_item_path_no useful from lua

 bin/ui-core.c   | 54 +++++++++++++++++++++++++++++++++++++++---------------
 bin/ui-viewer.c | 22 +++-------------------
 bin/ui.h        |  2 +-
 3 files changed, 43 insertions(+), 35 deletions(-)
---
diff --git a/bin/ui-core.c b/bin/ui-core.c
index 6df4615a3..0b4237bf8 100644
--- a/bin/ui-core.c
+++ b/bin/ui-core.c
@@ -3747,12 +3747,33 @@ static GeglNode *node_find_by_id (GeState *o, GeglNode *iter,
   return NULL;
 }
 
+char *get_item_path_no (GeState *o, int child_no)
+{
+  char *ret;
+  if (o->is_dir)
+    {
+      char *basename = meta_get_child (o, o->path, child_no);
+      ret = g_strdup_printf ("%s/%s", o->path, basename);
+      g_free (basename);
+    }
+  else
+    {
+      char *dirname = g_path_get_dirname (o->path);
+      char *basename = meta_get_child (o, dirname, child_no);
+      ret = g_strdup_printf ("%s/%s", dirname, basename);
+      g_free (dirname);
+      g_free (basename);
+    }
+  return ret;
+}
+
+
 char *get_item_path (GeState *o)
 {
   char *path = NULL;
   if (o->is_dir)
   {
-    path = meta_child_no_path (o, NULL, o->entry_no);
+    path = get_item_path_no (o, o->entry_no);
     if (g_file_test (path, G_FILE_TEST_IS_DIR))
     {
       g_free (path);
@@ -3788,20 +3809,23 @@ int get_item_no (GeState *o)
   else
   {
     int no = 0;
-    char *basename = g_path_get_basename (o->path);
-    o->entry_no = 0;
-    for (GList *iter = o->index; iter && !o->entry_no; iter = iter->next, no++)
-    {
-      IndexItem *item = iter->data;
-      if (!strcmp (item->name, basename))
-        o->entry_no = no;
-    }
-    for (GList *iter = o->paths; iter && !o->entry_no; iter = iter->next, no++)
+    if (o->entry_no <= 0)
     {
-      if (!strcmp (iter->data, o->path))
-        o->entry_no = no;
+      char *basename = g_path_get_basename (o->path);
+      o->entry_no = 0;
+      for (GList *iter = o->index; iter && !o->entry_no; iter = iter->next, no++)
+      {
+        IndexItem *item = iter->data;
+        if (!strcmp (item->name, basename))
+          o->entry_no = no;
+      }
+      for (GList *iter = o->paths; iter && !o->entry_no; iter = iter->next, no++)
+      {
+        if (!strcmp (iter->data, o->path))
+          o->entry_no = no;
+      }
+      g_free (basename);
     }
-    g_free (basename);
   }
   return o->entry_no;
 }
@@ -7188,7 +7212,7 @@ int cmd_next (COMMAND_ARGS) /* "next", 0, "", "next sibling element in current c
     //o->entry_no = 0;
 
   {
-    char *new_path = meta_child_no_path (o, NULL, o->entry_no);
+    char *new_path = get_item_path_no (o, o->entry_no);
     g_free (o->path);
     o->path = new_path;
     ui_load_path (o);
@@ -7271,7 +7295,7 @@ int cmd_prev (COMMAND_ARGS) /* "prev", 0, "", "previous sibling element in curre
     o->entry_no--;
 
   {
-    char *new_path = meta_child_no_path (o, NULL, o->entry_no);
+    char *new_path = get_item_path_no (o, o->entry_no);
     g_free (o->path);
     o->path = new_path;
     ui_load_path (o);
diff --git a/bin/ui-viewer.c b/bin/ui-viewer.c
index 74f546f8f..8795fe572 100644
--- a/bin/ui-viewer.c
+++ b/bin/ui-viewer.c
@@ -43,7 +43,7 @@ static void entry_load (MrgEvent *event, void *data1, void *data2)
     argvs_eval ("save");
 
   o->entry_no = GPOINTER_TO_INT(data2);
-  newpath = meta_child_no_path (o, NULL, o->entry_no);
+  newpath = get_item_path_no (o, o->entry_no);
   g_free (o->path);
   o->path = newpath;
   ui_load_path (o);
@@ -237,22 +237,6 @@ static void on_thumbbar_scroll (MrgEvent *event, void *data1, void *data2)
   mrg_event_stop_propagate (event);
 }
 
-char *meta_child_no_path (GeState *o, const char *path, int child_no)
-{
-  char *basename = meta_get_child (o, path, child_no);
-  char *ret;
-  if (o->is_dir)
-    ret = g_strdup_printf ("%s/%s", o->path, basename);
-  else
-    {
-      char *dirname = g_path_get_dirname (o->path);
-      ret = g_strdup_printf ("%s/%s", dirname, basename);
-      g_free (dirname);
-    }
-  g_free (basename);
-  return ret;
-}
-
 static void draw_thumb_bar (GeState *o)
 {
   Mrg *mrg = o->mrg;
@@ -301,7 +285,7 @@ static void draw_thumb_bar (GeState *o)
     //for (iter = curr; iter && x < width; iter = iter->next)
     while (x < width && entry_no < entries)
     {
-      char *upath = meta_child_no_path (o, NULL, entry_no);
+      char *upath = get_item_path_no (o, entry_no);
       char *path = ui_suffix_path (upath);
       char *thumbpath = ui_get_thumb_path (upath);
       int w, h;
@@ -348,7 +332,7 @@ static void draw_thumb_bar (GeState *o)
     entry_no = o->entry_no-1;
     while (x > -dim && entry_no >= 0)
     {
-      char *upath = meta_child_no_path (o, NULL, entry_no);
+      char *upath = get_item_path_no (o, entry_no);
       char *path = ui_suffix_path (upath);
       char *thumbpath = ui_get_thumb_path (upath);
       int w, h;
diff --git a/bin/ui.h b/bin/ui.h
index 7632c80ec..8dd5c6cc7 100644
--- a/bin/ui.h
+++ b/bin/ui.h
@@ -282,7 +282,7 @@ meta_swap_children (GeState    *state,
                     int         child_no2,
                     const char *child_name2);
 
-char *meta_child_no_path (GeState *o, const char *path, int child_no);
+char *get_item_path_no (GeState *o, int child_no);
 
 void   ui_viewer           (GeState *o);
 void   ui_collection       (GeState *o);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]