[gnome-builder] libide: add helper to get IdeFile for GFile
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide: add helper to get IdeFile for GFile
- Date: Tue, 24 Mar 2015 00:17:02 +0000 (UTC)
commit 257c40e48da4f840211e2ad05a0d05f30f87d413
Author: Christian Hergert <christian hergert me>
Date: Thu Mar 12 21:37:13 2015 -0700
libide: add helper to get IdeFile for GFile
libide/ide-project.c | 37 +++++++++++++++++++++++++++++++++++++
libide/ide-project.h | 2 ++
2 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-project.c b/libide/ide-project.c
index 66d3d22..143963d 100644
--- a/libide/ide-project.c
+++ b/libide/ide-project.c
@@ -162,6 +162,7 @@ ide_project_set_root (IdeProject *project,
/**
* ide_project_get_file_for_path:
+ * @path: A relative path from the project root.
*
* Retrieves an #IdeFile for the path specified. #IdeFile provides access to
* language specific features via ide_file_get_language().
@@ -236,6 +237,42 @@ ide_project_get_file_for_path (IdeProject *self,
return file;
}
+/**
+ * ide_project_get_project_file:
+ * @self: A #IdeProject.
+ * @gfile: A #GFile.
+ *
+ * Gets a new #IdeFile representing @gfile.
+ *
+ * Returns: (transfer full): An #IdeFile.
+ */
+IdeFile *
+ide_project_get_project_file (IdeProject *self,
+ GFile *gfile)
+{
+ g_autofree gchar *relpath = NULL;
+ IdeContext *context;
+ IdeVcs *vcs;
+ GFile *workdir;
+
+ g_return_val_if_fail (IDE_IS_PROJECT (self), NULL);
+ g_return_val_if_fail (G_IS_FILE (gfile), NULL);
+
+ context = ide_object_get_context (IDE_OBJECT (self));
+ vcs = ide_context_get_vcs (context);
+ workdir = ide_vcs_get_working_directory (vcs);
+
+ relpath = g_file_get_relative_path (workdir, gfile);
+ if (relpath)
+ return ide_project_get_file_for_path (self, relpath);
+
+ return g_object_new (IDE_TYPE_FILE,
+ "context", context,
+ "path", g_file_get_path (gfile),
+ "file", gfile,
+ NULL);
+}
+
static void
ide_project_finalize (GObject *object)
{
diff --git a/libide/ide-project.h b/libide/ide-project.h
index f4f8211..6b38b51 100644
--- a/libide/ide-project.h
+++ b/libide/ide-project.h
@@ -36,6 +36,8 @@ 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]