[gnome-builder] libide: add ide_project_files_find_child() helper
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide: add ide_project_files_find_child() helper
- Date: Mon, 23 Mar 2015 23:26:23 +0000 (UTC)
commit e1938cbf75ece2c5bc990c7be103d39052372dd0
Author: Christian Hergert <christian hergert me>
Date: Wed Feb 11 19:33:11 2015 -0800
libide: add ide_project_files_find_child() helper
This helps locate an IdeProjectItem matching the given file path.
libide/ide-project-files.c | 61 ++++++++++++++++++++++++++++++++++++++++++++
libide/ide-project-files.h | 3 ++
2 files changed, 64 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-project-files.c b/libide/ide-project-files.c
index 8ca62f8..6f0edcb 100644
--- a/libide/ide-project-files.c
+++ b/libide/ide-project-files.c
@@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "ide-project-file.h"
#include "ide-project-files.h"
G_DEFINE_TYPE (IdeProjectFiles, ide_project_files, IDE_TYPE_PROJECT_ITEM)
@@ -29,3 +30,63 @@ static void
ide_project_files_init (IdeProjectFiles *self)
{
}
+
+static IdeProjectItem *
+ide_project_files_find_child (IdeProjectItem *item,
+ const gchar *child)
+{
+ GSequence *children;
+ GSequenceIter *iter;
+
+ g_assert (IDE_IS_PROJECT_ITEM (item));
+ g_assert (child);
+
+ children = ide_project_item_get_children (item);
+ if (!children)
+ return NULL;
+
+ for (iter = g_sequence_get_begin_iter (children);
+ !g_sequence_iter_is_end (iter);
+ iter = g_sequence_iter_next (iter))
+ {
+ IdeProjectItem *item = g_sequence_get (iter);
+
+ if (IDE_IS_PROJECT_FILE (item))
+ {
+ IdeProjectFile *file = IDE_PROJECT_FILE (item);
+ const gchar *name = ide_project_file_get_name (file);
+
+ if (g_strcmp0 (name, child) == 0)
+ return item;
+ }
+ }
+
+ return NULL;
+}
+
+IdeFile *
+ide_project_files_get_file_for_path (IdeProjectFiles *self,
+ const gchar *path)
+{
+ IdeProjectItem *item = (IdeProjectItem *)self;
+ gchar **parts;
+ gsize i;
+
+ g_return_val_if_fail (IDE_IS_PROJECT_FILES (self), NULL);
+
+ parts = g_strsplit (path, G_DIR_SEPARATOR_S, 0);
+
+ for (i = 0; item && parts [i]; i++)
+ item = ide_project_files_find_child (item, parts [i]);
+
+ if (item)
+ {
+ IdeFile *file = NULL;
+
+ g_warning ("TODO: Get/find/create idefile for %s\n", ide_project_file_get_name (IDE_PROJECT_FILE
(item)));
+
+ return file;
+ }
+
+ return NULL;
+}
diff --git a/libide/ide-project-files.h b/libide/ide-project-files.h
index 7d236a5..7f5c59f 100644
--- a/libide/ide-project-files.h
+++ b/libide/ide-project-files.h
@@ -33,6 +33,9 @@ struct _IdeProjectFiles
IdeProjectItem parent_instance;
};
+IdeFile *ide_project_files_get_file_for_path (IdeProjectFiles *self,
+ const gchar *path);
+
G_END_DECLS
#endif /* IDE_PROJECT_FILES_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]