[gnome-builder/wip/file-loader: 4/5] project: add add_file() and get_files() helpers
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/file-loader: 4/5] project: add add_file() and get_files() helpers
- Date: Mon, 13 Apr 2015 08:08:36 +0000 (UTC)
commit e7a1f1da9163a1e5f189ed5bdf4a5f65bf7c8bba
Author: Christian Hergert <christian hergert me>
Date: Mon Apr 13 01:07:31 2015 -0700
project: add add_file() and get_files() helpers
libide/ide-project.c | 72 +++++++++++++++++++++++++++++++++----------------
libide/ide-project.h | 24 +++++++++-------
2 files changed, 62 insertions(+), 34 deletions(-)
---
diff --git a/libide/ide-project.c b/libide/ide-project.c
index 3d958a0..032b8d0 100644
--- a/libide/ide-project.c
+++ b/libide/ide-project.c
@@ -160,6 +160,34 @@ ide_project_set_root (IdeProject *project,
g_object_notify_by_pspec (G_OBJECT (project), gParamSpecs [PROP_ROOT]);
}
+IdeProjectFiles *
+ide_project_get_files (IdeProject *self)
+{
+ GSequenceIter *iter;
+ GSequence *children;
+ IdeProjectItem *root;
+
+ g_return_val_if_fail (IDE_IS_PROJECT (self), NULL);
+
+ root = ide_project_get_root (self);
+ children = ide_project_item_get_children (root);
+
+ if (children == NULL)
+ 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_FILES (item))
+ return IDE_PROJECT_FILES (item);
+ }
+
+ return NULL;
+}
+
/**
* ide_project_get_file_for_path:
* @path: A relative path from the project root.
@@ -178,9 +206,7 @@ IdeFile *
ide_project_get_file_for_path (IdeProject *self,
const gchar *path)
{
- IdeProjectItem *root;
- GSequenceIter *iter;
- GSequence *children;
+ IdeProjectFiles *files;
IdeFile *file = NULL;
g_return_val_if_fail (IDE_IS_PROJECT (self), NULL);
@@ -188,27 +214,9 @@ ide_project_get_file_for_path (IdeProject *self,
ide_project_reader_lock (self);
- root = ide_project_get_root (self);
- g_assert (IDE_IS_PROJECT_ITEM (root));
-
- children = ide_project_item_get_children (root);
- g_assert (children != 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_FILES (item))
- {
- IdeProjectFiles *files;
-
- files = IDE_PROJECT_FILES (item);
- file = ide_project_files_get_file_for_path (files, path);
- break;
- }
- }
+ files = ide_project_get_files (self);
+ if (files != NULL)
+ file = ide_project_files_get_file_for_path (files, path);
ide_project_reader_unlock (self);
@@ -275,6 +283,22 @@ ide_project_get_project_file (IdeProject *self,
NULL);
}
+void
+ide_project_add_file (IdeProject *self,
+ IdeProjectFile *file)
+{
+ IdeProjectFiles *files;
+
+ g_return_if_fail (IDE_IS_PROJECT (self));
+ g_return_if_fail (IDE_IS_PROJECT_FILE (file));
+
+
+ ide_project_writer_lock (self);
+ files = ide_project_get_files (self);
+ ide_project_files_add_file (files, file);
+ ide_project_writer_unlock (self);
+}
+
static void
ide_project_finalize (GObject *object)
{
diff --git a/libide/ide-project.h b/libide/ide-project.h
index 3de18b6..3fef16f 100644
--- a/libide/ide-project.h
+++ b/libide/ide-project.h
@@ -20,6 +20,7 @@
#define IDE_PROJECT_H
#include "ide-object.h"
+#include "ide-project-files.h"
G_BEGIN_DECLS
@@ -32,16 +33,19 @@ struct _IdeProjectClass
IdeObjectClass parent;
};
-IdeProjectItem *ide_project_get_root (IdeProject *project);
-const gchar *ide_project_get_name (IdeProject *project);
-IdeFile *ide_project_get_file_for_path (IdeProject *project,
- const gchar *path);
-IdeFile *ide_project_get_project_file (IdeProject *self,
- GFile *gfile);
-void ide_project_reader_lock (IdeProject *project);
-void ide_project_reader_unlock (IdeProject *project);
-void ide_project_writer_lock (IdeProject *project);
-void ide_project_writer_unlock (IdeProject *project);
+IdeProjectItem *ide_project_get_root (IdeProject *project);
+const gchar *ide_project_get_name (IdeProject *project);
+IdeFile *ide_project_get_file_for_path (IdeProject *project,
+ const gchar *path);
+IdeFile *ide_project_get_project_file (IdeProject *self,
+ GFile *gfile);
+void ide_project_reader_lock (IdeProject *project);
+void ide_project_reader_unlock (IdeProject *project);
+void ide_project_writer_lock (IdeProject *project);
+void ide_project_writer_unlock (IdeProject *project);
+void ide_project_add_file (IdeProject *project,
+ IdeProjectFile *file);
+IdeProjectFiles *ide_project_get_files (IdeProject *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]