diff --git a/ChangeLog b/ChangeLog index 7cfa99b..6631679 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-07-17 ajwillia.ms (Andy Williams) + + * Create new files in the selected directory rather than project root + 2015-06-07 ajwillia.ms (Andy Williams) * Indent newlines to match whitespace in the previous line diff --git a/src/bin/edi_filepanel.c b/src/bin/edi_filepanel.c index 2660d1e..278c71d 100644 --- a/src/bin/edi_filepanel.c +++ b/src/bin/edi_filepanel.c @@ -440,3 +440,13 @@ edi_filepanel_add(Evas_Object *parent, Evas_Object *win, elm_box_pack_end(parent, list); } + +const char * +edi_filepanel_selected_path_get(Evas_Object *obj EINA_UNUSED) +{ + Elm_Object_Item *it; + + it = elm_genlist_selected_item_get(list); + return elm_object_item_data_get(it); +} + diff --git a/src/bin/edi_filepanel.h b/src/bin/edi_filepanel.h index 187a7b1..05d5969 100644 --- a/src/bin/edi_filepanel.h +++ b/src/bin/edi_filepanel.h @@ -39,6 +39,8 @@ typedef void (*edi_filepanel_item_clicked_cb)(const char *path, void edi_filepanel_add(Evas_Object *parent, Evas_Object *win, const char *path, edi_filepanel_item_clicked_cb cb); +const char *edi_filepanel_selected_path_get(Evas_Object *obj); + /** * @} */ diff --git a/src/bin/edi_main.c b/src/bin/edi_main.c index ac4ca86..6492620 100644 --- a/src/bin/edi_main.c +++ b/src/bin/edi_main.c @@ -492,10 +492,14 @@ _tb_new_create_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { - const char *path, *name; + const char *selected, *path, *name; name = elm_entry_entry_get((Evas_Object *) data); - path = edi_project_file_path_get(name); + selected = edi_filepanel_selected_path_get(_edi_filepanel); + if (selected && ecore_file_is_dir(selected)) + path = edi_path_append(selected, name); + else + path = edi_project_file_path_get(name); fclose(fopen(path, "w")); _edi_filepanel_reload(); @@ -532,6 +536,7 @@ _edi_file_new() _tb_new_create_cb, input); evas_object_show(popup); + elm_object_focus_set(input, EINA_TRUE); } static void diff --git a/src/lib/edi.c b/src/lib/edi.c index 21fc775..4aa4d6b 100644 --- a/src/lib/edi.c +++ b/src/lib/edi.c @@ -108,14 +108,7 @@ edi_project_get() EAPI const char * edi_project_file_path_get(const char *file) { - char *path; - int len; - - len = strlen(file) + strlen(edi_project_get()) + 2; - path = malloc(sizeof(char) * len); - snprintf(path, len, "%s/%s", edi_project_get(), file); - - return path; + return edi_path_append(edi_project_get(), file); } EAPI Eina_Bool diff --git a/src/lib/edi_path.c b/src/lib/edi_path.c index 591b0ce..6e661f1 100644 --- a/src/lib/edi_path.c +++ b/src/lib/edi_path.c @@ -43,4 +43,20 @@ edi_path_options_create(const char *input) return ret; } +EAPI const char * +edi_path_append(const char *path, const char *file) +{ + char *concat; + int len; + char separator = '/'; +#ifdef WIN32 + separator = '\\'; +#endif + + len = strlen(path) + strlen(file) + 2; + concat = malloc(sizeof(char) * len); + snprintf(concat, len, "%s%c%s", path, separator, file); + + return concat; +} diff --git a/src/lib/edi_path.h b/src/lib/edi_path.h index 41b3b5f..21f1329 100644 --- a/src/lib/edi_path.h +++ b/src/lib/edi_path.h @@ -40,6 +40,17 @@ typedef struct _Edi_Path_Options */ EAPI Edi_Path_Options *edi_path_options_create(const char *input); +/** + * Append a file to the end of a given path. + * + * @param path The base path to append to + * @param file The file portion to add to the path + * + * @return a newly allocated string that merges the items to a path using the + * correct separator for the current platform. + */ +EAPI const char *edi_path_append(const char *path, const char *file); + /** * @} */