rimmed pushed a commit to branch master. http://git.enlightenment.org/tools/eflete.git/commit/?id=ee2eb647329c884603723c36fd70707c926908e5
commit ee2eb647329c884603723c36fd70707c926908e5 Author: Andrii Kroitor <an.kroi...@samsung.com> Date: Tue Apr 12 10:54:25 2016 +0300 eflete: refactor comandline options Removed flags -o, --import-edj and --replace. Open and import actions are now recognized by file extenstion. Added more checks. Now you cann't start eflete with incorrect options combination. Creating main window only after pasing all checks. --- src/bin/main.c | 114 ++++++++++++++++++++++++++++++++--------------- src/bin/ui/main_window.c | 1 - 2 files changed, 79 insertions(+), 36 deletions(-) diff --git a/src/bin/main.c b/src/bin/main.c index 6148554..84cc731 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -28,27 +28,33 @@ #include "tabs_private.h" #include "config.h" -static char *open = NULL; -static char *import_edj = NULL; +static char *file = NULL; static char *pro_name = NULL; static char *pro_path = NULL; -static Eina_Bool pro_replace = false; + +#define _ERR_EXIT(MSG, ...) \ +do { \ + printf(_("ERROR: ")); \ + printf(MSG, ## __VA_ARGS__); \ + printf(_("\nERROR: invalid options found. See --help.\n")); \ + return 1; \ +} while (0); static const Ecore_Getopt options = { PACKAGE_NAME, - "%prog [options]", + "%prog [OPTION]... [FILE]\n" + " if FILE is *.pro: open project\n" + " if FILE is *.edj: import edj\n" + , VERSION, - "(C) 2013-2014 Samsung Electronics.", + "(C) 2013-2016 Samsung Electronics.", "GNU Library General Public License version 2", - N_("This application was written for Enlightenment, to use EFL\n" - "and design to create and modify Elementary widgets styles.\n"), + "This application was written for Enlightenment, to use EFL\n" + "and design to create and modify Elementary widgets styles.\n", EINA_TRUE, { - ECORE_GETOPT_STORE_STR('o', "open", N_("Eflete project file")), - ECORE_GETOPT_STORE_STR(0, "import-edj", N_("Import the edj file as new project")), ECORE_GETOPT_STORE_STR(0, "name", N_("Name for new project that would be created in import process")), ECORE_GETOPT_STORE_STR(0, "path", N_("Path for project")), - ECORE_GETOPT_STORE_TRUE(0, "replace", N_("Replace existing project")), ECORE_GETOPT_STORE_TRUE('r', "reopen", "reopen last project"), ECORE_GETOPT_VERSION ('v', "version"), ECORE_GETOPT_COPYRIGHT('c', "copyright"), @@ -92,14 +98,26 @@ _open_project(void *data __UNUSED__) _setup_open_splash, _teardown_open_splash, _cancel_open_splash, - (void *)eina_stringshare_add(open)); + (void *)eina_stringshare_add(file)); evas_object_show(ap.splash); } static void _import_edj(void *data __UNUSED__) { - tabs_menu_import_edj_data_set(pro_name, pro_path, import_edj); + const char *name; + Eina_Tmpstr *proj_name; + if (pro_name) + { + tabs_menu_import_edj_data_set(pro_name, pro_path, file); + } + else + { + name = ecore_file_file_get(file); + proj_name = eina_tmpstr_add_length(name, strlen(name) - 4); + tabs_menu_import_edj_data_set(proj_name, pro_path, file); + eina_tmpstr_del(proj_name); + } tabs_menu_tab_open(TAB_HOME_IMPORT_EDJ); } @@ -109,13 +127,11 @@ elm_main(int argc, char **argv) Eina_Bool info_only = false, reopen = false; Config *config; Recent *r; + int pos; Ecore_Getopt_Value values[] = { - ECORE_GETOPT_VALUE_STR(open), - ECORE_GETOPT_VALUE_STR(import_edj), ECORE_GETOPT_VALUE_STR(pro_name), ECORE_GETOPT_VALUE_STR(pro_path), - ECORE_GETOPT_VALUE_BOOL(pro_replace), ECORE_GETOPT_VALUE_BOOL(reopen), ECORE_GETOPT_VALUE_BOOL(info_only), ECORE_GETOPT_VALUE_BOOL(info_only), @@ -132,7 +148,15 @@ elm_main(int argc, char **argv) enventor_init(argc, argv); #endif - ecore_getopt_parse(&options, values, argc, argv); + pos = ecore_getopt_parse(&options, values, argc, argv); + if (pos < 0) + return 1; + if (pos < argc - 1) + _ERR_EXIT(_("Only one file should be specified.")); + + if (pos == argc -1) + file = argv[pos]; + if (!info_only) { #ifdef HAVE_CONFIG_H @@ -141,46 +165,66 @@ elm_main(int argc, char **argv) CRIT("Could not find 'eflete_config.h'"); #endif - if (!ui_main_window_add()) - { - app_shutdown(); - return -1; - } + config_load(); if (reopen) { + if (file) + _ERR_EXIT(_("--reopen is given but file specified.")); + if (pro_name) + _ERR_EXIT(_("--reopen is given but --name specified.")); + if (pro_path) + _ERR_EXIT(_("--repoen is given but --path specified.")); + config = config_get(); if (!config->recents) - { - ERR(_("There are no previously opened projects yet.")); - return 1; - } + _ERR_EXIT(_("There are no previously opened projects yet.")); + r = eina_list_data_get(config->recents); - open = r->path; + file = r->path; ecore_job_add(_open_project, NULL); goto run; } - if (open) + if (file) { - if ((eina_str_has_suffix(open, ".pro")) && - (ecore_file_exists(open))) + if (!ecore_file_exists(file)) + _ERR_EXIT(_("File '%s' doesn't exists."), file); + if (ecore_file_is_dir(file)) + _ERR_EXIT(_("'%s' is a directory."), file); + + if (eina_str_has_suffix(file, ".pro")) { + if (pro_name) + _ERR_EXIT(_("*.pro file is given but --name specified.")); + if (pro_path) + _ERR_EXIT(_("*.pro file is given but --path specified.")); + ecore_job_add(_open_project, NULL); goto run; } - else + else if (eina_str_has_suffix(file, ".edj")) { - ERR(_("Can not open file '%s'. Wrong path or file format."), open); - return 1; + ecore_job_add(_import_edj, NULL); + goto run; } + else + _ERR_EXIT(_("Wrong file extension.")); } - if (import_edj) + else { - ecore_job_add(_import_edj, NULL); - goto run; + TODO("Remove this after adding new project creation when --name is given without filename"); + if (pro_name) + _ERR_EXIT(_("no file is given but --name specified.")); + if (pro_path) + _ERR_EXIT(_("no file is given but --path specified.")); } run: + if (!ui_main_window_add()) + { + app_shutdown(); + return -1; + } evas_object_show(ap.win); elm_run(); #ifdef HAVE_ENVENTOR diff --git a/src/bin/ui/main_window.c b/src/bin/ui/main_window.c index de08bd2..004f86e 100644 --- a/src/bin/ui/main_window.c +++ b/src/bin/ui/main_window.c @@ -106,7 +106,6 @@ ui_main_window_add(void) Config *config; Evas_Object *bg, *project_navigator, *tabs, *toolbar; - config_load(); config = config_get(); elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); --