forked from enlightenment/edi
examples: extract example from git to create new projects
This commit is contained in:
parent
1b7acee711
commit
e170fdee19
|
@ -41,7 +41,7 @@ _exe_del(void *d EINA_UNUSED, int t EINA_UNUSED, void *event_info EINA_UNUSED)
|
|||
|
||||
static const Ecore_Getopt optdesc = {
|
||||
"edi_build",
|
||||
"%prog [options] [build|clean|create|test]",
|
||||
"%prog [options] [build|clean|test|create|example]",
|
||||
PACKAGE_VERSION,
|
||||
COPYRIGHT,
|
||||
"BSD with advertisement clause",
|
||||
|
@ -112,6 +112,14 @@ _edi_build_create_start(int argc, int arg0, char **argv)
|
|||
_edi_build_create_done_cb);
|
||||
}
|
||||
|
||||
static void
|
||||
_edi_build_example_start(int argc, int arg0, char **argv)
|
||||
{
|
||||
elm_init(argc, argv);
|
||||
edi_create_example(argv[arg0 + 1], argv[arg0 + 2], argv[arg0 + 3],
|
||||
_edi_build_create_done_cb);
|
||||
}
|
||||
|
||||
EAPI_MAIN int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
|
@ -172,6 +180,20 @@ main(int argc, char **argv)
|
|||
|
||||
_edi_build_create_start(argc, args, argv);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
goto end;
|
||||
}
|
||||
if (!strncmp("example", build_type, 7))
|
||||
{
|
||||
if (argc - args != 4)
|
||||
{
|
||||
fprintf(stderr, _("example requires 3 additional parameters:\n"));
|
||||
fprintf(stderr, " example_name, parent_path, project_name\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
_edi_build_example_start(argc, args, argv);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
goto end;
|
||||
}
|
||||
|
|
|
@ -201,7 +201,8 @@ _edi_welcome_project_new_input_row_add(const char *text, const char *placeholder
|
|||
evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
elm_table_pack(parent, label, 0, row, 1, 1);
|
||||
evas_object_show(label);
|
||||
if (show)
|
||||
evas_object_show(label);
|
||||
|
||||
input = elm_entry_add(parent);
|
||||
elm_entry_scrollable_set(input, EINA_TRUE);
|
||||
|
@ -209,13 +210,15 @@ _edi_welcome_project_new_input_row_add(const char *text, const char *placeholder
|
|||
evas_object_size_hint_weight_set(input, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(input, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
elm_table_pack(parent, input, 1, row, _EDI_WELCOME_PROJECT_NEW_TABLE_WIDTH - 1, 1);
|
||||
evas_object_show(input);
|
||||
if (show)
|
||||
evas_object_show(input);
|
||||
|
||||
if (placeholder)
|
||||
{
|
||||
elm_object_text_set(input, placeholder);
|
||||
}
|
||||
_create_inputs[row] = input;
|
||||
return input;
|
||||
}
|
||||
|
||||
Edi_Template *
|
||||
|
@ -337,10 +340,14 @@ _edi_welcome_project_new_create_cb(void *data EINA_UNUSED, Evas_Object *obj EINA
|
|||
user = elm_object_text_get(_create_inputs[3]);
|
||||
email = elm_object_text_get(_create_inputs[4]);
|
||||
|
||||
if (template && path && path[0] && name && name[0])
|
||||
if (path && path[0] && name && name[0])
|
||||
{
|
||||
if (!template->is_template)
|
||||
edi_create_example(template->path, path, name,
|
||||
_edi_welcome_project_new_create_done_cb);
|
||||
else
|
||||
edi_create_project(template->path, path, name, url, user, email,
|
||||
_edi_welcome_project_new_create_done_cb);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -385,7 +392,7 @@ _edi_welcome_user_fullname_get(const char *username, char *fullname, size_t max)
|
|||
static void
|
||||
_edi_welcome_project_details(Evas_Object *naviframe, Edi_Template *template)
|
||||
{
|
||||
Evas_Object *content, *button;
|
||||
Evas_Object *content, *button, *input;
|
||||
Elm_Object_Item *item;
|
||||
int row = 0;
|
||||
char fullname[1024];
|
||||
|
@ -400,13 +407,16 @@ _edi_welcome_project_details(Evas_Object *naviframe, Edi_Template *template)
|
|||
if (!username)
|
||||
username = getenv("USERNAME");
|
||||
_edi_welcome_project_new_directory_row_add(_("Parent Path"), row++, content);
|
||||
_edi_welcome_project_new_input_row_add(_("Project Name"), NULL, row++, content);
|
||||
_edi_welcome_project_new_input_row_add(_("Project URL"), NULL, row++, content);
|
||||
input = _edi_welcome_project_new_input_row_add(_("Project Name"), NULL, EINA_TRUE, row++, content);
|
||||
if (!template->is_template)
|
||||
elm_object_text_set(input, template->edje_id);
|
||||
|
||||
_edi_welcome_project_new_input_row_add(_("Project URL"), NULL, template->is_template, row++, content);
|
||||
if (_edi_welcome_user_fullname_get(username, fullname, sizeof(fullname)))
|
||||
_edi_welcome_project_new_input_row_add(_("Creator Name"), fullname, row++, content);
|
||||
_edi_welcome_project_new_input_row_add(_("Creator Name"), fullname, template->is_template, row++, content);
|
||||
else
|
||||
_edi_welcome_project_new_input_row_add(_("Creator Name"), username, row++, content);
|
||||
_edi_welcome_project_new_input_row_add(_("Creator Email"), NULL, row++, content);
|
||||
_edi_welcome_project_new_input_row_add(_("Creator Name"), username, template->is_template, row++, content);
|
||||
_edi_welcome_project_new_input_row_add(_("Creator Email"), NULL, template->is_template, row++, content);
|
||||
|
||||
button = elm_button_add(content);
|
||||
elm_object_text_set(button, _("Create"));
|
||||
|
@ -499,7 +509,6 @@ _edi_welcome_project_new_cb(void *data, Evas_Object *obj EINA_UNUSED, void *even
|
|||
Evas_Object *content, *button, *naviframe;
|
||||
Evas_Object *table, *list, *rect, *hbox;
|
||||
Elm_Object_Item *item;
|
||||
char path[PATH_MAX];
|
||||
Edi_Template *template, *example;
|
||||
Elm_Genlist_Item_Class *ith, *itc;
|
||||
|
||||
|
@ -667,9 +676,9 @@ _edi_welcome_project_clone_cb(void *data, Evas_Object *obj EINA_UNUSED, void *ev
|
|||
evas_object_size_hint_weight_set(content, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_show(content);
|
||||
|
||||
_edi_welcome_project_new_input_row_add(_("Source Control URL"), NULL, row++, content);
|
||||
_edi_welcome_project_new_input_row_add(_("Source Control URL"), NULL, EINA_TRUE, row++, content);
|
||||
_edi_welcome_project_new_directory_row_add(_("Parent Path"), row++, content);
|
||||
_edi_welcome_project_new_input_row_add(_("Project Name"), NULL, row++, content);
|
||||
_edi_welcome_project_new_input_row_add(_("Project Name"), NULL, EINA_TRUE, row++, content);
|
||||
|
||||
pb = elm_progressbar_add(content);
|
||||
evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
#include "edi_private.h"
|
||||
|
||||
#define EXAMPLES_GIT_URL "https://git.enlightenment.org/tools/examples.git"
|
||||
|
||||
typedef struct _Edi_Create
|
||||
{
|
||||
char *path, *temp, *name, *skelfile;
|
||||
|
@ -21,6 +23,15 @@ typedef struct _Edi_Create
|
|||
int filters;
|
||||
} Edi_Create;
|
||||
|
||||
typedef struct _Edi_Create_Example
|
||||
{
|
||||
char *path, *name;
|
||||
|
||||
Edi_Create_Cb callback;
|
||||
|
||||
} Edi_Create_Example;
|
||||
|
||||
|
||||
static Edi_Create *_edi_create_data;
|
||||
|
||||
static const char *
|
||||
|
@ -345,3 +356,61 @@ edi_create_project(const char *template_name, const char *parentdir,
|
|||
free(cmd);
|
||||
}
|
||||
|
||||
static void
|
||||
_edi_create_example_done_cb(void *data, Eio_File *file EINA_UNUSED)
|
||||
{
|
||||
Edi_Create_Example *create = data;
|
||||
|
||||
if (create->callback)
|
||||
create->callback(create->path, EINA_TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
_edi_create_example_extract_dir(char *examples_path, Edi_Create_Example *create)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
|
||||
eina_file_path_join(path, sizeof(path), examples_path, create->name);
|
||||
|
||||
eio_dir_copy(path, create->path, NULL, NULL, _edi_create_example_done_cb,
|
||||
_edi_create_error_cb, create);
|
||||
|
||||
free(examples_path);
|
||||
}
|
||||
|
||||
EAPI void
|
||||
edi_create_example(const char *example_name, const char *parentdir,
|
||||
const char *name, Edi_Create_Cb func)
|
||||
{
|
||||
char dest[PATH_MAX], examplepath[PATH_MAX];
|
||||
int status = 0;
|
||||
Edi_Create_Example *data;
|
||||
|
||||
snprintf(dest, sizeof(dest), "%s/%s", parentdir, name);
|
||||
snprintf(examplepath, sizeof(examplepath), "%s/%s/examples.git",
|
||||
efreet_cache_home_get(), PACKAGE_NAME);
|
||||
|
||||
data = calloc(1, sizeof(Edi_Create_Example));
|
||||
data->path = strdup(dest);
|
||||
data->name = strdup(example_name);
|
||||
data->callback = func;
|
||||
|
||||
INF("Extracting example project \"%s\" at path %s\n", example_name, dest);
|
||||
|
||||
if (ecore_file_exists(examplepath))
|
||||
ERR("TODO: UPDATE NOT IMPLEMENTED");
|
||||
// status = edi_scm_git_update(examplepath);
|
||||
else
|
||||
status = edi_scm_git_clone(EXAMPLES_GIT_URL, examplepath);
|
||||
|
||||
if (status)
|
||||
{
|
||||
ERR("git error: [%d]\n", status);
|
||||
|
||||
if (func)
|
||||
func(dest, EINA_FALSE);
|
||||
}
|
||||
else
|
||||
_edi_create_example_extract_dir(strdup(examplepath), data);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,15 @@ edi_create_project(const char *template_name, const char *parentdir,
|
|||
const char *name, const char *url, const char *user,
|
||||
const char *email, Edi_Create_Cb func);
|
||||
|
||||
/**
|
||||
* Create a new project from an example.
|
||||
*
|
||||
* @ingroup Creation
|
||||
*/
|
||||
EAPI void
|
||||
edi_create_example(const char *example_name, const char *parentdir,
|
||||
const char *name, Edi_Create_Cb func);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#ifndef EDI_PRIVATE_H
|
||||
# define EDI_PRIVATE_H
|
||||
|
||||
#include <Eina.h>
|
||||
#include <Efreet.h>
|
||||
|
||||
extern int _edi_lib_log_dom;
|
||||
char *edi_create_escape_quotes(const char *in);
|
||||
|
||||
|
|
Loading…
Reference in New Issue