rimmed pushed a commit to branch master.

http://git.enlightenment.org/tools/eflete.git/commit/?id=cedf88788f63da6d13d5002517f739fe40f9de52

commit cedf88788f63da6d13d5002517f739fe40f9de52
Author: Vyacheslav Reutskiy <v.reuts...@samsung.com>
Date:   Fri Nov 6 12:00:49 2015 +0200

    project_export: remake the full source code export
    
    Change-Id: I266792969250a4b2e76af4c4653c0b82f6984f41
---
 src/bin/project_manager/project_manager.c | 248 ++++++++++--------------------
 src/bin/project_manager/project_manager.h |   8 +-
 src/bin/ui/connector.c                    |   2 +
 src/bin/ui/popup.c                        |   2 +-
 src/bin/ui/project_export.c               |  54 +++++++
 5 files changed, 147 insertions(+), 167 deletions(-)

diff --git a/src/bin/project_manager/project_manager.c 
b/src/bin/project_manager/project_manager.c
index ab8f0ec..a264262 100644
--- a/src/bin/project_manager/project_manager.c
+++ b/src/bin/project_manager/project_manager.c
@@ -36,22 +36,8 @@
 #define PROJECT_KEY_LICENSE      "edje/license"
 #define PROJECT_KEY_COMMENT      "edje/comment"
 
-#define S3 "   "
-#define TOP_LEVEL_NUMBER 9
-#define GROUP "   group "
-
 static Eet_Compression compess_level = EET_COMPRESSION_HI;
 
-const char *top_levels[] = { "collections",
-                             "styles",
-                             "color_classes",
-                             "fonts",
-                             "images",
-                             "data",
-                             "externals",
-                             "sounds",
-                             "group",
-                             NULL};
 typedef struct
 {
    Eina_Stringshare *str;
@@ -1392,174 +1378,108 @@ pm_project_style_source_code_export(Project *pro, 
Style *style, const char *file
    return true;
 }
 
-Eina_Bool
-pm_project_source_code_export(Project *pro, const char *dir_path)
+static void
+_external_resource_export(Eina_List *resources, const char *dst)
 {
-   Eina_Stringshare *code = NULL;
-   Eina_Stringshare *group = NULL;
-   Eina_Stringshare *top_level_str[TOP_LEVEL_NUMBER];
-   Eina_Stringshare *last = NULL;
+   Eina_Strbuf *buf;
+   Eina_List *l;
+   External_Resource *res;
 
-   Eina_Stringshare *path = NULL;
-   Eina_Stringshare *path_edc_dir = NULL;
-   Eina_Stringshare *path_edc = NULL;
-   Eina_Stringshare *group_edc = NULL;
-   Eina_Stringshare *include = NULL;
-   Eina_Stringshare *gr_name = NULL;
+   buf = eina_strbuf_new();
+   EINA_LIST_FOREACH(resources, l, res)
+     {
+        eina_strbuf_append_printf(buf, "%s/%s", dst, res->name);
+        ecore_file_cp(res->source, eina_strbuf_string_get(buf));
+        eina_strbuf_reset(buf);
+     }
+   eina_strbuf_free(buf);
+}
 
-   assert(pro != NULL);
-   assert(dir_path != NULL);
-
-   Eina_Bool next = true, open_flag = true, group_start = false;
-   unsigned int i = 0, tokens_count = 0, tok_name = 0, j = 0;
-   FILE *f, *fedc = NULL, *f_top[TOP_LEVEL_NUMBER];
-   char **tmp, **tmp_name = NULL;
-   int value = -1, k = 0;
-   const char *pos = NULL;
-   char str[100];
-   Evas_Object *edje_edit_obj = pro->global_object;
-
-   path = eina_stringshare_printf("%s/%s.edc", dir_path, pro->name);
-   f = fopen(path, "w");
+static void *
+_source_code_export(void *data __UNUSED__, Eina_Thread *thread __UNUSED__)
+{
+   Eina_Stringshare *code;
+   Eina_Strbuf *buf;
+   FILE *f;
+
+   PROGRESS_SEND(_("Generate source code..."));
+
+   buf = eina_strbuf_new();
+   /* create a folder for collect the source files */
+   eina_strbuf_append_printf(buf, "%s/%s", worker.path, worker.project->name);
+   ecore_file_mkdir(eina_strbuf_string_get(buf));
+   eina_strbuf_reset(buf);
+
+   /* create and open edc file for print the source code of collection 
(project) */
+   eina_strbuf_append_printf(buf, "%s/%s/generated.edc", worker.path, 
worker.project->name);
+   f = fopen(eina_strbuf_string_get(buf), "w");
    if (!f)
      {
-        ERR("Could't open file '%s'", path);
+        ERR("Could't open file '%s'", eina_strbuf_string_get(buf))
+        END_SEND(PM_PROJECT_ERROR);
         goto exit;
      }
+   eina_strbuf_reset(buf);
 
-   path_edc_dir = eina_stringshare_printf("%s/edc", dir_path);
-   if (!ecore_file_exists(path_edc_dir))
-     ecore_file_mkdir(path_edc_dir);
+   /* get the full source code of given project */
+   ecore_thread_main_loop_begin();
+   code = edje_edit_full_source_generate(worker.project->global_object);
+   ecore_thread_main_loop_end();
 
-   for (i = 1; i < TOP_LEVEL_NUMBER - 1; i++)
+   fputs(code, f);
+   edje_edit_string_free(code);
+   if (f) fclose(f);
+
+   /* export resource */
+   if (worker.project->images)
      {
-        path = eina_stringshare_printf("%s/edc/%s.edc", dir_path, 
top_levels[i]);
-        f_top[i] = fopen(path, "w");
-        if (!f_top[i]) goto exit;
-        top_level_str[i] = eina_stringshare_printf("/* Automatically generated 
by Eflete */\n"
-                                                   "%s {\n", top_levels[i]);
-
-        /* Sounds level should be at collections */
-        if (i == 7)
-          {
-             fputs("collections {\n", f);
-             fputs(S3, f);
-          }
-        include = eina_stringshare_printf("#include \"edc/%s.edc\"\n", 
top_levels[i]);
-        fputs(include, f);
+        eina_strbuf_append_printf(buf, "%s/%s/images/", worker.path, 
worker.project->name);
+        ecore_file_mkdir(eina_strbuf_string_get(buf));
+        _external_resource_export(worker.project->images, 
eina_strbuf_string_get(buf));
+        eina_strbuf_reset(buf);
      }
-
-   code = eina_stringshare_add(edje_edit_full_source_generate(edje_edit_obj));
-   tmp = eina_str_split_full(code, "{", 0, &tokens_count);
-   if (tmp[0])
-   for (i = 0; tokens_count > 0; i++, tokens_count--)
+   if (worker.project->sounds)
      {
-        /* Generate group_name.edc */
-        if (group_start && open_flag)
-          {
-             if (!sscanf(tmp[i], " name: \"%s", str)) continue;
-             gr_name = eina_stringshare_nprintf(strlen(str) - 1, "%s", str);
-             tmp_name = eina_str_split_full(gr_name, "/", 0, &tok_name);
-             if (!tmp_name[0]) continue;
-             group_edc = eina_stringshare_add(tmp_name[0]);
-             for (j = 1; tok_name - 1 > 0; j++, tok_name--)
-               group_edc = eina_stringshare_printf("%s_%s", group_edc, 
tmp_name[j]);
-             group_edc = eina_stringshare_printf("%s.edc", group_edc);
-             free(tmp_name[0]);
-             free(tmp_name);
-             path_edc = eina_stringshare_printf("%s/%s", path_edc_dir, 
group_edc);
-             fedc = fopen(path_edc, "w");
-             if (!fedc) continue;
-             open_flag = false;
-             group_start = false;
-             eina_stringshare_del(gr_name);
-          }
-        if ((value == 0) && !(strstr(tmp[i], "sounds")))
-          {
-             if (!group)
-               group = eina_stringshare_add(tmp[i]);
-             else if ((strstr(tmp[i], GROUP)) || tokens_count == 1)
-               {
-                  pos = strrchr(tmp[i], '}');
-                  last = eina_stringshare_nprintf(pos - tmp[i] + 2, "%s", 
tmp[i]);
-                  group = eina_stringshare_printf("%s{%s", group, last);
-                  eina_stringshare_del(last);
-               }
-             else
-               group = eina_stringshare_printf("%s{%s", group, tmp[i]);
-          }
-        /* Generate top_level_name.edc and sounds */
-        else if ((value > 0) && (value < TOP_LEVEL_NUMBER))
-          {
-             for (k = 0; top_levels[k] != NULL; k++)
-               {
-                  if (k == value) continue;
-                  if (strstr(tmp[i], top_levels[k]))
-                    {
-                       pos = strrchr(tmp[i], '}');
-                       last = eina_stringshare_nprintf(pos - tmp[i] + 1, "%s", 
tmp[i]);
-                       top_level_str[value] = eina_stringshare_printf("%s{%s",
-                                                                      
top_level_str[value], last);
-                       eina_stringshare_del(last);
-                       next = false;
-                    }
-               }
-             if (next)
-               top_level_str[value] = eina_stringshare_printf("%s{%s",
-                                                              
top_level_str[value], tmp[i]);
-          }
-        for (k = 0; top_levels[k] != NULL; k++)
-          {
-             if ((value != 0) && strstr(tmp[i], top_levels[k]))
-               {
-                  if ((value == 7) && (k == 8)) value = 0;
-                  else value = k;
-                  break;
-               }
-             else if (strstr(tmp[i], top_levels[7])) value = 7;
-          }
-        if ((value == 0) && strstr(tmp[i], GROUP)) group_start = true;
-        if ((!open_flag && (strstr(tmp[i], GROUP))) || (!open_flag && 
(tokens_count == 1)))
-          {
-             if (group)
-               {
-                  fputs(GROUP"{", fedc);
-                  fputs(group, fedc);
-               }
-             include = eina_stringshare_printf(S3"#include \"edc/%s\"\n", 
group_edc);
-             fputs(include, f);
-             eina_stringshare_del(path_edc);
-             eina_stringshare_del(group_edc);
-             eina_stringshare_del(group);
-             eina_stringshare_del(include);
-             group = NULL;
-             open_flag = true;
-          }
-        next = true;
+        eina_strbuf_append_printf(buf, "%s/%s/sounds/", worker.path, 
worker.project->name);
+        ecore_file_mkdir(eina_strbuf_string_get(buf));
+        _external_resource_export(worker.project->sounds, 
eina_strbuf_string_get(buf));
+        eina_strbuf_reset(buf);
      }
-   free(tmp[0]);
-   free(tmp);
-   for (i = 1; i < TOP_LEVEL_NUMBER - 1; i++)
+   if (worker.project->fonts)
      {
-        if ((f_top[i]) && (top_level_str[i]))
-          {
-             fputs(top_level_str[i], f_top[i]);
-             fputs("}", f_top[i]);
-          }
-        fclose(f_top[i]);
-        eina_stringshare_del(top_level_str[i]);
+        eina_strbuf_append_printf(buf, "%s/%s/fonts/", worker.path, 
worker.project->name);
+        ecore_file_mkdir(eina_strbuf_string_get(buf));
+        _external_resource_export(worker.project->fonts, 
eina_strbuf_string_get(buf));
+        eina_strbuf_reset(buf);
      }
 
+   END_SEND(PM_PROJECT_SUCCESS);
 exit:
-   eina_stringshare_del(path);
-   eina_stringshare_del(path_edc_dir);
-   if (f) fclose(f);
-   if (fedc) fclose(fedc);
-   return EINA_TRUE;
+   eina_strbuf_free(buf);
+   return NULL;
+}
+
+void
+pm_project_source_code_export(Project *project,
+                              const char *path,
+                              PM_Project_Progress_Cb func_progress,
+                              PM_Project_End_Cb func_end,
+                              const void *data)
+{
+   assert(project != NULL);
+   assert(path != NULL);
+
+   WORKER_CREATE(func_progress, func_end, data, project,
+                 NULL, path, NULL, NULL, data);
+
+   if (!eina_thread_create(&worker.thread, EINA_THREAD_URGENT, -1,
+                           (void *)_source_code_export, NULL))
+     {
+        ERR("System error: can't create thread");
+        abort();
+     }
 }
-#undef S3
-#undef GROUP
-#undef TOP_LEVEL_NUMBER
+
 
 static void *
 _develop_export(void *data __UNUSED__,
diff --git a/src/bin/project_manager/project_manager.h 
b/src/bin/project_manager/project_manager.h
index f9e4e22..148e764 100644
--- a/src/bin/project_manager/project_manager.h
+++ b/src/bin/project_manager/project_manager.h
@@ -464,8 +464,12 @@ pm_project_style_source_code_export(Project *pro, Style 
*style, const char *file
  *
  * @ingroup ProjectManager.
  */
-Eina_Bool
-pm_project_source_code_export(Project *pro, const char *dir_path);
+void
+pm_project_source_code_export(Project *project,
+                              const char *path,
+                              PM_Project_Progress_Cb func_progress,
+                              PM_Project_End_Cb func_end,
+                              const void *data);
 
 /**
  * Export the edj develop file from current project. The develop edj file
diff --git a/src/bin/ui/connector.c b/src/bin/ui/connector.c
index 28a1eef..9abe920 100644
--- a/src/bin/ui/connector.c
+++ b/src/bin/ui/connector.c
@@ -824,6 +824,7 @@ project_export_edc_group(void)
    elm_win_inwin_content_set(win, fs);
 }
 
+/*
 static void
 _on_export_edc_project_done(void *data,
                             Evas_Object *obj __UNUSED__,
@@ -939,6 +940,7 @@ project_export_edc_project(void)
 
    ap.modal_editor++;
 }
+*/
 
 /*************************** Close request popup 
******************************/
 /*
diff --git a/src/bin/ui/popup.c b/src/bin/ui/popup.c
index 5c63cf7..7c9c7d4 100644
--- a/src/bin/ui/popup.c
+++ b/src/bin/ui/popup.c
@@ -153,7 +153,7 @@ _done(void *data __UNUSED__,
                                                   
elm_fileselector_path_get(fs),
                                                   
elm_fileselector_current_name_get(fs));
              else
-               selected = elm_fileselector_selected_get(fs);
+               selected = 
eina_stringshare_add(elm_fileselector_selected_get(fs));
              selected_paths = eina_list_append(selected_paths, selected);
           }
         res = ((Helper_Done_Cb)dismiss_func)(func_data, obj, selected_paths);
diff --git a/src/bin/ui/project_export.c b/src/bin/ui/project_export.c
index b24971c..3d69510 100644
--- a/src/bin/ui/project_export.c
+++ b/src/bin/ui/project_export.c
@@ -75,3 +75,57 @@ project_export_develop(void)
    ui_menu_items_list_disable_set(ap.menu, MENU_ITEMS_LIST_MAIN, true);
    popup_fileselector_edj_helper("Export to develop edj-file", NULL, NULL, 
_export_dev, NULL, false, true);
 }
+
+static Eina_Bool
+_export_source_code_setup(void *data, Splash_Status status __UNUSED__)
+{
+   Eina_Stringshare *path = (Eina_Stringshare *)data;
+
+   assert(path != NULL);
+
+   pm_project_source_code_export(ap.project,
+                                 path,
+                                 progress_print,
+                                 progress_end,
+                                 NULL);
+   return true;
+}
+
+Eina_Bool
+_export_source_code(void *data __UNUSED__,
+                    Evas_Object *obj __UNUSED__, /* this is fileselector from 
popup */
+                    void *event_info)
+{
+   Eina_List *selected = (Eina_List *)event_info;
+   Eina_Stringshare *path;
+   Eina_Strbuf *buf;
+
+   assert(selected != NULL);
+
+   path = eina_stringshare_add((const char *)eina_list_data_get(selected));
+   buf = eina_strbuf_new();
+   eina_strbuf_append_printf(buf,
+                             _("<font_size=16>A project file '%s/%s' already 
exist."
+                               "Do you want to replace it?</font_size>"),
+                             path,
+                             ap.project->name);
+   if (!exist_permission_check(path,
+                               ap.project->name,
+                               _("Export to develop edj-file"),
+                               eina_strbuf_string_get(buf)))
+     return false;
+   eina_strbuf_free(buf);
+
+   ap.splash = splash_add(ap.win, _export_source_code_setup, _export_teardown, 
NULL, (void *)path);
+   evas_object_focus_set(ap.splash, true);
+   evas_object_show(ap.splash);
+
+   return true;
+}
+
+void
+project_export_edc_project(void)
+{
+   ui_menu_items_list_disable_set(ap.menu, MENU_ITEMS_LIST_MAIN, true);
+   popup_fileselector_folder_helper("Export source code", NULL, NULL, 
_export_source_code, NULL, false, false);
+}

-- 


Reply via email to