static void ide_project_file_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { IdeProjectFile *self = IDE_PROJECT_FILE (object); switch (prop_id) { case PROP_FILE: g_value_set_object (value, ide_project_file_get_file (self)); break; case PROP_FILE_INFO: g_value_set_object (value, ide_project_file_get_file_info (self)); break; case PROP_IS_DIRECTORY: g_value_set_boolean (value, ide_project_file_get_is_directory (self)); break; case PROP_NAME: g_value_set_string (value, ide_project_file_get_name (self)); break; case PROP_PATH: g_value_set_string (value, ide_project_file_get_path (self)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } }
/** * ide_project_files_get_file_for_path: * * Retrieves an #IdeFile for the path. If no such path exists within the * project, %NULL is returned. * * Returns: (transfer full) (nullable): An #IdeFile or %NULL. */ IdeFile * ide_project_files_get_file_for_path (IdeProjectFiles *self, const gchar *path) { IdeProjectFilesPrivate *priv = ide_project_files_get_instance_private (self); IdeProjectItem *item = (IdeProjectItem *)self; IdeFile *file = NULL; gchar **parts; gsize i; g_return_val_if_fail (IDE_IS_PROJECT_FILES (self), NULL); if ((file = g_hash_table_lookup (priv->files_by_path, path))) return g_object_ref (file); 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) { IdeContext *context; const gchar *path; GFile *gfile; context = ide_object_get_context (IDE_OBJECT (self)); gfile = ide_project_file_get_file (IDE_PROJECT_FILE (item)); path = ide_project_file_get_path (IDE_PROJECT_FILE (item)); file = g_object_new (IDE_TYPE_FILE, "context", context, "file", gfile, "path", path, NULL); if (file) g_hash_table_insert (priv->files_by_path, g_strdup (path), g_object_ref (file)); } 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); }