[gnome-builder/wip/file-loader: 3/5] project-files: add ide_project_files_add_file()
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/file-loader: 3/5] project-files: add ide_project_files_add_file()
- Date: Mon, 13 Apr 2015 08:08:31 +0000 (UTC)
commit 9767c4fc878234010cb90bcbe86af4a7983fd4f9
Author: Christian Hergert <christian hergert me>
Date: Mon Apr 13 01:05:28 2015 -0700
project-files: add ide_project_files_add_file()
This simplifies the process of adding a file to the files tree after the
initial creation.
libide/ide-project-files.c | 81 ++++++++++++++++++++++++++++++++++++++++++++
libide/ide-project-files.h | 3 ++
2 files changed, 84 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-project-files.c b/libide/ide-project-files.c
index ae69b18..be37d07 100644
--- a/libide/ide-project-files.c
+++ b/libide/ide-project-files.c
@@ -16,8 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "ide-context.h"
#include "ide-project-file.h"
#include "ide-project-files.h"
+#include "ide-vcs.h"
typedef struct
{
@@ -136,3 +138,82 @@ ide_project_files_get_file_for_path (IdeProjectFiles *self,
return file;
}
+
+void
+ide_project_files_add_file (IdeProjectFiles *self,
+ IdeProjectFile *file)
+{
+ IdeProjectItem *item = (IdeProjectItem *)self;
+ g_autoptr(GFile) parent = NULL;
+ g_autofree gchar *path = NULL;
+ IdeContext *context;
+ IdeVcs *vcs;
+ GFile *workdir;
+ GFile *gfile;
+ gchar **parts;
+ gsize i;
+
+ g_return_if_fail (IDE_IS_PROJECT_FILES (self));
+ g_return_if_fail (IDE_IS_PROJECT_FILE (file));
+
+ context = ide_object_get_context (IDE_OBJECT (self));
+ vcs = ide_context_get_vcs (context);
+ workdir = ide_vcs_get_working_directory (vcs);
+
+ gfile = ide_project_file_get_file (file);
+ parent = g_file_get_parent (gfile);
+ path = g_file_get_relative_path (workdir, parent);
+
+ if (path == NULL)
+ {
+ ide_project_item_append (IDE_PROJECT_ITEM (self), IDE_PROJECT_ITEM (file));
+ return;
+ }
+
+ parts = g_strsplit (path, G_DIR_SEPARATOR_S, 0);
+
+ for (i = 0; parts [i]; i++)
+ {
+ IdeProjectItem *found;
+
+ found = ide_project_files_find_child (item, parts [i]);
+
+ if (found == NULL)
+ {
+ g_autoptr(GFileInfo) file_info = NULL;
+ g_autofree gchar *child_path = NULL;
+ IdeProjectItem *child;
+ const gchar *item_path;
+ g_autoptr(GFile) item_file = NULL;
+
+ file_info = g_file_info_new ();
+ g_file_info_set_file_type (file_info, G_FILE_TYPE_DIRECTORY);
+ g_file_info_set_display_name (file_info, parts [i]);
+ g_file_info_set_name (file_info, parts [i]);
+
+ item_path = ide_project_file_get_path (IDE_PROJECT_FILE (item));
+ child_path = g_strjoin (G_DIR_SEPARATOR_S, item_path, parts [i], NULL);
+ item_file = g_file_get_child (workdir, child_path);
+
+ child = g_object_new (IDE_TYPE_PROJECT_FILE,
+ "context", context,
+ "parent", item,
+ "path", path,
+ "file", item_file,
+ "file-info", file_info,
+ NULL);
+ ide_project_item_append (item, child);
+
+ item = child;
+ }
+ else
+ {
+ item = found;
+ }
+ }
+
+ ide_project_item_append (item, IDE_PROJECT_ITEM (file));
+
+ g_strfreev (parts);
+
+}
diff --git a/libide/ide-project-files.h b/libide/ide-project-files.h
index c09bf4f..d96269e 100644
--- a/libide/ide-project-files.h
+++ b/libide/ide-project-files.h
@@ -19,6 +19,7 @@
#ifndef IDE_PROJECT_FILES_H
#define IDE_PROJECT_FILES_H
+#include "ide-project-file.h"
#include "ide-project-item.h"
G_BEGIN_DECLS
@@ -35,6 +36,8 @@ struct _IdeProjectFiles
IdeFile *ide_project_files_get_file_for_path (IdeProjectFiles *self,
const gchar *path);
+void ide_project_files_add_file (IdeProjectFiles *self,
+ IdeProjectFile *file);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]