[gnome-builder/gnome-builder-3-20] templates: allow reset of IdeTemplateBase



commit cb187b2ee8636a13a2900090619ce43eefb5ed57
Author: Christian Hergert <chergert redhat com>
Date:   Fri May 20 13:26:03 2016 +0300

    templates: allow reset of IdeTemplateBase
    
    This allows us to expand a template multiple-times without having to
    create a new instance of the object.
    
    Longer term, it's probably better to store the plugin info and the name
    of the template, so that we don't hold onto an object until necessary.

 libide/template/ide-template-base.c                |   13 +++++++++++++
 libide/template/ide-template-base.h                |    1 +
 .../autotools_templates/__init__.py                |    2 ++
 3 files changed, 16 insertions(+), 0 deletions(-)
---
diff --git a/libide/template/ide-template-base.c b/libide/template/ide-template-base.c
index 3191192..ad0ae15 100644
--- a/libide/template/ide-template-base.c
+++ b/libide/template/ide-template-base.c
@@ -713,3 +713,16 @@ ide_template_base_add_path (IdeTemplateBase *self,
 
   g_array_append_val (priv->files, expansion);
 }
+
+void
+ide_template_base_reset (IdeTemplateBase *self)
+{
+  IdeTemplateBasePrivate *priv = ide_template_base_get_instance_private (self);
+
+  g_return_if_fail (IDE_IS_TEMPLATE_BASE (self));
+
+  g_clear_pointer (&priv->files, g_array_unref);
+  priv->files = g_array_new (FALSE, TRUE, sizeof (FileExpansion));
+
+  priv->has_expanded = FALSE;
+}
diff --git a/libide/template/ide-template-base.h b/libide/template/ide-template-base.h
index 4ca1b73..033a238 100644
--- a/libide/template/ide-template-base.h
+++ b/libide/template/ide-template-base.h
@@ -52,6 +52,7 @@ void                 ide_template_base_expand_all_async  (IdeTemplateBase
 gboolean             ide_template_base_expand_all_finish (IdeTemplateBase       *self,
                                                           GAsyncResult          *result,
                                                           GError               **error);
+void                 ide_template_base_reset             (IdeTemplateBase       *self);
 
 G_END_DECLS
 
diff --git a/plugins/autotools-templates/autotools_templates/__init__.py 
b/plugins/autotools-templates/autotools_templates/__init__.py
index f4ba2f2..b832516 100644
--- a/plugins/autotools-templates/autotools_templates/__init__.py
+++ b/plugins/autotools-templates/autotools_templates/__init__.py
@@ -95,6 +95,8 @@ class AutotoolsTemplate(Ide.TemplateBase, Ide.ProjectTemplate):
         return self.languages
 
     def do_expand_async(self, params, cancellable, callback, data):
+        self.reset()
+
         task = Gio.Task.new(self, cancellable, callback)
 
         name = params['name'].get_string().lower()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]