[gnome-builder/wip/gtk4-port: 1217/1774] libide/projects: add API to expand template
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 1217/1774] libide/projects: add API to expand template
- Date: Mon, 11 Jul 2022 22:31:38 +0000 (UTC)
commit d1311b6d87f0b0e73ab876cb78d616978457de96
Author: Christian Hergert <chergert redhat com>
Date: Fri May 27 16:33:20 2022 -0700
libide/projects: add API to expand template
Still needs to be fully implemented, but gets the scaffolding in place.
src/libide/projects/ide-template-input.c | 91 ++++++++++++++++++++++++++++----
src/libide/projects/ide-template-input.h | 71 ++++++++++++++-----------
2 files changed, 120 insertions(+), 42 deletions(-)
---
diff --git a/src/libide/projects/ide-template-input.c b/src/libide/projects/ide-template-input.c
index ce0fee403..0ca2bbfb5 100644
--- a/src/libide/projects/ide-template-input.c
+++ b/src/libide/projects/ide-template-input.c
@@ -22,8 +22,10 @@
#include "config.h"
-#include <libpeas/peas.h>
#include <glib/gi18n.h>
+#include <libpeas/peas.h>
+
+#include <libide-threading.h>
#include "ide-projects-global.h"
#include "ide-project-template.h"
@@ -841,15 +843,7 @@ functify (const gchar *input)
return g_string_free (str, FALSE);
}
-/**
- * ide_template_input_to_scope:
- * @self: a #IdeTemplateInput
- *
- * Generates a #TmplScope with various state from the template input.
- *
- * Returns: (transfer full): a #TmplScope that can be used to expand templates
- */
-TmplScope *
+static TmplScope *
ide_template_input_to_scope (IdeTemplateInput *self)
{
g_autoptr(TmplScope) scope = NULL;
@@ -997,3 +991,80 @@ ide_template_input_validate (IdeTemplateInput *self)
return flags;
}
+
+void
+ide_template_input_expand_async (IdeTemplateInput *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_autoptr(IdeProjectTemplate) template = NULL;
+ g_autoptr(TmplScope) scope = NULL;
+ g_autoptr(IdeTask) task = NULL;
+
+ IDE_ENTRY;
+
+ g_return_if_fail (IDE_IS_MAIN_THREAD ());
+ g_return_if_fail (IDE_IS_TEMPLATE_INPUT (self));
+ g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ task = ide_task_new (self, cancellable, callback, user_data);
+ ide_task_set_source_tag (task, ide_template_input_expand_async);
+
+ if (ide_template_input_validate (self) != IDE_TEMPLATE_INPUT_VALID)
+ {
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_INVAL,
+ "Template input is not valid");
+ IDE_EXIT;
+ }
+
+ if (!(template = find_template (self, self->template)))
+ {
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_INVAL,
+ "Failed to locate template");
+ IDE_EXIT;
+ }
+
+ if (!(scope = ide_template_input_to_scope (self)))
+ {
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_INVAL,
+ "Failed to create scope for template");
+ IDE_EXIT;
+ }
+
+ /* TODO: Expand, VCS, etc */
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ "Work in Progress");
+
+ IDE_EXIT;
+}
+
+/**
+ * ide_template_input_expand_finish:
+ *
+ * Returns: (transfer full): a #GFile or %NULL and @error is set.
+ */
+GFile *
+ide_template_input_expand_finish (IdeTemplateInput *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ GFile *ret;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_TEMPLATE_INPUT (self));
+ g_assert (IDE_IS_TASK (result));
+
+ ret = ide_task_propagate_pointer (IDE_TASK (result), error);
+
+ IDE_RETURN (ret);
+}
diff --git a/src/libide/projects/ide-template-input.h b/src/libide/projects/ide-template-input.h
index 1b0deb14b..eec9c7365 100644
--- a/src/libide/projects/ide-template-input.h
+++ b/src/libide/projects/ide-template-input.h
@@ -48,59 +48,66 @@ G_DECLARE_FINAL_TYPE (IdeTemplateInput, ide_template_input, IDE, TEMPLATE_INPUT,
IDE_AVAILABLE_IN_ALL
IdeTemplateInput *ide_template_input_new (void);
IDE_AVAILABLE_IN_ALL
-const char *ide_template_input_get_author (IdeTemplateInput *self);
+const char *ide_template_input_get_author (IdeTemplateInput *self);
IDE_AVAILABLE_IN_ALL
-void ide_template_input_set_author (IdeTemplateInput *self,
- const char *author);
+void ide_template_input_set_author (IdeTemplateInput *self,
+ const char *author);
IDE_AVAILABLE_IN_ALL
-GFile *ide_template_input_get_directory (IdeTemplateInput *self);
+GFile *ide_template_input_get_directory (IdeTemplateInput *self);
IDE_AVAILABLE_IN_ALL
-void ide_template_input_set_directory (IdeTemplateInput *self,
- GFile *directory);
+void ide_template_input_set_directory (IdeTemplateInput *self,
+ GFile *directory);
IDE_AVAILABLE_IN_ALL
-const char *ide_template_input_get_language (IdeTemplateInput *self);
+const char *ide_template_input_get_language (IdeTemplateInput *self);
IDE_AVAILABLE_IN_ALL
-void ide_template_input_set_language (IdeTemplateInput *self,
- const char *language);
+void ide_template_input_set_language (IdeTemplateInput *self,
+ const char *language);
IDE_AVAILABLE_IN_ALL
-gboolean ide_template_input_get_use_version_control (IdeTemplateInput *self);
+gboolean ide_template_input_get_use_version_control (IdeTemplateInput *self);
IDE_AVAILABLE_IN_ALL
-void ide_template_input_set_use_version_control (IdeTemplateInput *self,
- gboolean
use_version_control);
+void ide_template_input_set_use_version_control (IdeTemplateInput *self,
+ gboolean
use_version_control);
IDE_AVAILABLE_IN_ALL
-const char *ide_template_input_get_name (IdeTemplateInput *self);
+const char *ide_template_input_get_name (IdeTemplateInput *self);
IDE_AVAILABLE_IN_ALL
-void ide_template_input_set_name (IdeTemplateInput *self,
- const char *name);
+void ide_template_input_set_name (IdeTemplateInput *self,
+ const char *name);
IDE_AVAILABLE_IN_ALL
-const char *ide_template_input_get_app_id (IdeTemplateInput *self);
+const char *ide_template_input_get_app_id (IdeTemplateInput *self);
IDE_AVAILABLE_IN_ALL
-void ide_template_input_set_app_id (IdeTemplateInput *self,
- const char *app_id);
+void ide_template_input_set_app_id (IdeTemplateInput *self,
+ const char *app_id);
IDE_AVAILABLE_IN_ALL
-const char *ide_template_input_get_project_version (IdeTemplateInput *self);
+const char *ide_template_input_get_project_version (IdeTemplateInput *self);
IDE_AVAILABLE_IN_ALL
-void ide_template_input_set_project_version (IdeTemplateInput *self,
- const char *project_version);
+void ide_template_input_set_project_version (IdeTemplateInput *self,
+ const char
*project_version);
IDE_AVAILABLE_IN_ALL
-const char *ide_template_input_get_license_name (IdeTemplateInput *self);
+const char *ide_template_input_get_license_name (IdeTemplateInput *self);
IDE_AVAILABLE_IN_ALL
-void ide_template_input_set_license_name (IdeTemplateInput *self,
- const char *license_name);
+void ide_template_input_set_license_name (IdeTemplateInput *self,
+ const char *license_name);
IDE_AVAILABLE_IN_ALL
-const char *ide_template_input_get_template (IdeTemplateInput *self);
+const char *ide_template_input_get_template (IdeTemplateInput *self);
IDE_AVAILABLE_IN_ALL
-void ide_template_input_set_template (IdeTemplateInput *self,
- const char *template);
+void ide_template_input_set_template (IdeTemplateInput *self,
+ const char *template);
IDE_AVAILABLE_IN_ALL
-GListModel *ide_template_input_get_templates_model (IdeTemplateInput *self);
+GListModel *ide_template_input_get_templates_model (IdeTemplateInput *self);
IDE_AVAILABLE_IN_ALL
-GListModel *ide_template_input_get_languages_model (IdeTemplateInput *self);
+GListModel *ide_template_input_get_languages_model (IdeTemplateInput *self);
IDE_AVAILABLE_IN_ALL
-GListModel *ide_template_input_get_licenses_model (IdeTemplateInput *self);
+GListModel *ide_template_input_get_licenses_model (IdeTemplateInput *self);
IDE_AVAILABLE_IN_ALL
-TmplScope *ide_template_input_to_scope (IdeTemplateInput *self);
+IdeTemplateInputValidation ide_template_input_validate (IdeTemplateInput *self);
IDE_AVAILABLE_IN_ALL
-IdeTemplateInputValidation ide_template_input_validate (IdeTemplateInput *self);
+void ide_template_input_expand_async (IdeTemplateInput *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+IDE_AVAILABLE_IN_ALL
+GFile *ide_template_input_expand_finish (IdeTemplateInput *self,
+ GAsyncResult *result,
+ GError **error);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]