new file: create in selected directory

When the filepanel selected item is a directory place new
files in that location rather than project root.
This commit is contained in:
Andy Williams 2015-07-17 10:30:25 -07:00
parent 1c7e2b3873
commit 93ee90a302
7 changed files with 51 additions and 10 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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);
/**
* @}
*/

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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);
/**
* @}
*/