jackdanielz pushed a commit to branch master.

http://git.enlightenment.org/tools/erigo.git/commit/?id=5b87f8d4e7f4ccf899aa077a907a4d7b0a0c23f9

commit 5b87f8d4e7f4ccf899aa077a907a4d7b0a0c23f9
Author: Daniel Zaoui <daniel.za...@samsung.com>
Date:   Tue Nov 17 14:29:12 2015 +0200

    Fix C generation when create callbacks are used
    
    Create function return type was stored in pub_widgets although it was
    needed to be given to the user.
    A specific user function is now invoked at the end of the widget
    creation so post actions can be done (e.g store widgets structure,
    list fill...).
---
 src/lib/generator.c | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/src/lib/generator.c b/src/lib/generator.c
index 3ea9a5f..ab39b2e 100644
--- a/src/lib/generator.c
+++ b/src/lib/generator.c
@@ -18,6 +18,7 @@ typedef struct
    Eina_Strbuf *c_buf;         /* buffer for source */
    Eina_Strbuf *h_buf;         /* buffer for headers */
    Eina_List *global_entities; /* widgets ids which must be global */
+   Eina_List *created_wdgs; /* Widgets created by an automatic callback */
    char *formatted_project_name;
    char *Formatted_Project_Name;
    char *FORMATTED_PROJECT_NAME;
@@ -914,14 +915,23 @@ _wdg_cb_add_generate(Gui_Session *session, const 
Gui_Widget *wdg, const Gui_Widg
                    if (wdg)
                      {
                         const char *parent_name = NULL;
+                        const char *wdg_name = wdg_name_get(wdg);
+                        char *Wdg_Name = strdup(wdg_name), *tmp = Wdg_Name;
+                        *tmp = toupper(*tmp);
+                        while (*tmp) if (*tmp++ == '_') *tmp = toupper(*tmp);
                         Eid *parent_id = action_creation_parent_get(action);
-                        if (parent_id)
-                           parent_name = eid_name_get(parent_id);
+                        if (parent_id) parent_name = eid_name_get(parent_id);
                         eina_strbuf_append_printf(_wdg_cb_type_foo,
-                              "   g_pub_widgets.%s = %s_%s_create(%s);\n",
-                              wdg_name_get(wdg),
-                              wdg_ctx->gl_ctx->formatted_project_name, 
wdg_name_get(wdg),
+                              "   %s_%s_Widgets *wdgs = %s_%s_create(%s);\n",
+                              gl_ctx->Formatted_Project_Name, Wdg_Name,
+                              gl_ctx->formatted_project_name, wdg_name,
                               parent_name ? : "NULL");
+                        free(Wdg_Name);
+                        eina_strbuf_append_printf(_wdg_cb_type_foo,
+                              "   %s_%s_create_done(wdgs);\n",
+                              gl_ctx->formatted_project_name, wdg_name);
+                        gl_ctx->created_wdgs = eina_list_append(
+                              gl_ctx->created_wdgs, wdg_id);
                      }
                    break;
                 }
@@ -1176,6 +1186,19 @@ _ctx_generate(Global_Gen_Context *gl_ctx)
           }
      }
 
+   EINA_LIST_FOREACH(gl_ctx->created_wdgs, itr, eid)
+     {
+        char *Wdg_Name = strdup(eid_name_get(eid)), *tmp = Wdg_Name;
+        *tmp = toupper(*tmp);
+        while (*tmp) if (*tmp++ == '_') *tmp = toupper(*tmp);
+        eina_strbuf_append_printf(gl_ctx->c_buf,
+              "extern void %s_%s_create_done(%s_%s_Widgets *wdgs);\n",
+              gl_ctx->formatted_project_name, eid_name_get(eid),
+              gl_ctx->Formatted_Project_Name, Wdg_Name);
+        free(Wdg_Name);
+     }
+   if (gl_ctx->created_wdgs) eina_strbuf_append(gl_ctx->c_buf, "\n");
+
    eina_strbuf_append_printf(gl_ctx->c_buf,"%s", 
eina_strbuf_string_get(resources_buf));
    EINA_LIST_FOREACH((const Eina_List *)wdg_ctxs, itr, wdg_ctx)
      {
@@ -1291,6 +1314,7 @@ _ctx_to_file_save(const Gui_Context *ctx, 
Generator_Export_Format format, Eina_B
    gl_gen_ctx.c_buf = eina_strbuf_new();
    gl_gen_ctx.h_buf = eina_strbuf_new();
    gl_gen_ctx.global_entities = NULL;
+   gl_gen_ctx.created_wdgs = NULL;
    gl_gen_ctx.session = session_new(MODE_GENERATOR, EINA_FALSE);
    gl_gen_ctx.formatted_project_name = 
_project_name_format(gui_context_project_name_get(ctx));
    gl_gen_ctx.Formatted_Project_Name = 
strdup(gl_gen_ctx.formatted_project_name);

-- 


Reply via email to