[gnome-builder] recent-projects: add helper to locate by path



commit e2a44520b45a6ea582ae365c83b3c221df7a3ec5
Author: Christian Hergert <chergert redhat com>
Date:   Fri Nov 10 00:11:14 2017 -0800

    recent-projects: add helper to locate by path
    
    This allows finding the exact project (including the project
    file like meson.build or configure.ac) given a directory.
    
    The implementation is poor, but it get this going for testing
    things quickly.

 src/libide/projects/ide-recent-projects.c |   30 ++++++++++++++++++++++++++++-
 src/libide/projects/ide-recent-projects.h |    9 +++++--
 2 files changed, 35 insertions(+), 4 deletions(-)
---
diff --git a/src/libide/projects/ide-recent-projects.c b/src/libide/projects/ide-recent-projects.c
index e14617d..ed5ed87 100644
--- a/src/libide/projects/ide-recent-projects.c
+++ b/src/libide/projects/ide-recent-projects.c
@@ -84,7 +84,6 @@ ide_recent_projects_get_bookmarks (IdeRecentProjects  *self,
   GBookmarkFile *bookmarks;
 
   g_assert (IDE_IS_RECENT_PROJECTS (self));
-  g_assert (error != NULL);
 
   bookmarks = g_bookmark_file_new ();
 
@@ -353,3 +352,32 @@ ide_recent_projects_remove (IdeRecentProjects *self,
       return;
     }
 }
+
+gchar *
+ide_recent_projects_find_by_directory (IdeRecentProjects *self,
+                                       const gchar       *directory)
+{
+  g_autoptr(GBookmarkFile) bookmarks = NULL;
+  g_auto(GStrv) uris = NULL;
+  gsize len = 0;
+
+  g_return_val_if_fail (IDE_IS_RECENT_PROJECTS (self), NULL);
+  g_return_val_if_fail (directory, NULL);
+
+  if (!g_file_test (directory, G_FILE_TEST_IS_DIR))
+    return NULL;
+
+  if (NULL == (bookmarks = ide_recent_projects_get_bookmarks (self, NULL)))
+    return NULL;
+
+  uris = g_bookmark_file_get_uris (bookmarks, &len);
+
+  for (gsize i = 0; i < len; i++)
+    {
+      /* TODO: Make a better compare that deals with trailing / */
+      if (g_str_has_prefix (uris[i], directory))
+        return g_strdup (uris[i]);
+    }
+
+  return NULL;
+}
diff --git a/src/libide/projects/ide-recent-projects.h b/src/libide/projects/ide-recent-projects.h
index cfa867f..c0f4453 100644
--- a/src/libide/projects/ide-recent-projects.h
+++ b/src/libide/projects/ide-recent-projects.h
@@ -34,9 +34,12 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (IdeRecentProjects, ide_recent_projects, IDE, RECENT_PROJECTS, GObject)
 
 IDE_AVAILABLE_IN_ALL
-IdeRecentProjects *ide_recent_projects_new    (void);
+IdeRecentProjects *ide_recent_projects_new               (void);
 IDE_AVAILABLE_IN_ALL
-void               ide_recent_projects_remove (IdeRecentProjects *self,
-                                               GList             *project_infos);
+void               ide_recent_projects_remove            (IdeRecentProjects *self,
+                                                          GList             *project_infos);
+IDE_AVAILABLE_IN_3_28
+gchar             *ide_recent_projects_find_by_directory (IdeRecentProjects *self,
+                                                          const gchar       *directory);
 
 G_END_DECLS


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