[gtksourceview] utils: add support for resource:// directories



commit 5e639caf2d0c6f48fd30f6a982a69de8bb8e0f24
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jan 27 17:02:39 2022 -0800

    utils: add support for resource:// directories

 gtksourceview/gtksourceutils.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
---
diff --git a/gtksourceview/gtksourceutils.c b/gtksourceview/gtksourceutils.c
index 00b9017a..9207be30 100644
--- a/gtksourceview/gtksourceutils.c
+++ b/gtksourceview/gtksourceutils.c
@@ -273,6 +273,41 @@ build_file_listing (const gchar *item,
                return filenames;
 
        }
+
+       if (g_str_has_prefix (item, "resource://"))
+       {
+               const char *path = item + strlen ("resource://");
+               char **children;
+
+               children = g_resources_enumerate_children (path, 0, NULL);
+
+               if (children != NULL)
+               {
+                       for (guint i = 0; children[i] != NULL; i++)
+                       {
+                               if (g_str_has_suffix (children[i], suffix))
+                               {
+                                       char *full_path = g_build_path ("/", item, children[i], NULL);
+                                       const char *resource_full_path = full_path + strlen ("resource://");
+                                       gsize size = 0;
+
+                                       if (g_resources_get_info (resource_full_path, 0, &size, NULL, NULL) 
&& size > 0)
+                                       {
+                                               filenames = g_slist_prepend (filenames, full_path);
+                                       }
+                                       else
+                                       {
+                                               g_free (full_path);
+                                       }
+                               }
+                       }
+               }
+
+               g_strfreev (children);
+
+               return filenames;
+       }
+
        dir = g_dir_open (item, 0, NULL);
 
        if (dir == NULL)


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