ajwillia-ms pushed a commit to branch master. http://git.enlightenment.org/tools/edi.git/commit/?id=37759291c540bcf1b3db493ed632fcfa0eb45d1e
commit 37759291c540bcf1b3db493ed632fcfa0eb45d1e Author: Al Poole <nets...@gmail.com> Date: Tue May 30 08:30:24 2017 +0100 edi_file_screens: refactor UI create/rm/rdir and add directory and file renaming method. Summary: Add this to the filepanel menus also. Reviewers: ajwillia.ms Differential Revision: https://phab.enlightenment.org/D4920 --- src/bin/Makefile.am | 2 + src/bin/edi_file.c | 187 --------------------- src/bin/edi_file.h | 21 +-- src/bin/edi_filepanel.c | 25 ++- src/bin/edi_main.c | 7 +- src/bin/{edi_file.c => screens/edi_file_screens.c} | 145 ++++++++++++---- src/bin/{edi_file.h => screens/edi_file_screens.h} | 29 ++-- 7 files changed, 154 insertions(+), 262 deletions(-) diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index 60169a6..97a3d66 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -26,6 +26,7 @@ language/edi_language_provider.h \ editor/edi_editor.h \ edi_content_provider.h \ screens/edi_screens.h \ +screens/edi_file_screens.h \ edi_filepanel.h \ edi_file.h \ edi_logpanel.h \ @@ -46,6 +47,7 @@ screens/edi_welcome.c \ screens/edi_about.c \ screens/edi_settings_font.c \ screens/edi_settings.c \ +screens/edi_file_screens.c \ edi_filepanel.c \ edi_file.c \ edi_logpanel.c \ diff --git a/src/bin/edi_file.c b/src/bin/edi_file.c index 1a06d8b..fe7ada0 100644 --- a/src/bin/edi_file.c +++ b/src/bin/edi_file.c @@ -1,11 +1,7 @@ #include "Edi.h" -#include "mainview/edi_mainview.h" #include "edi_file.h" #include "edi_private.h" -static Evas_Object *_parent_obj, *_popup, *_popup_dir, *_edi_file_message_popup; -static const char *_directory_path; - Eina_Bool edi_file_path_hidden(const char *path) { @@ -21,186 +17,3 @@ edi_file_path_hidden(const char *path) return EINA_FALSE; } -static void -_edi_file_message_close_cb(void *data EINA_UNUSED, - Evas_Object *obj EINA_UNUSED, - void *event_info EINA_UNUSED) -{ - Evas_Object *popup = data; - evas_object_del(popup); -} - -static void -_edi_file_message_open(const char *message) -{ - Evas_Object *popup, *button; - - _edi_file_message_popup = popup = elm_popup_add(_parent_obj); - elm_object_part_text_set(popup, "title,text", - message); - - button = elm_button_add(popup); - elm_object_text_set(button, "Ok"); - elm_object_part_content_set(popup, "button1", button); - evas_object_smart_callback_add(button, "clicked", - _edi_file_message_close_cb, popup); - - evas_object_show(popup); -} - -static void -_edi_file_popup_cancel_cb(void *data, Evas_Object *obj EINA_UNUSED, - void *event_info EINA_UNUSED) -{ - evas_object_del((Evas_Object *)data); - eina_stringshare_del(_directory_path); - _directory_path = NULL; -} - -static void -_edi_file_create_file_cb(void *data, - Evas_Object *obj EINA_UNUSED, - void *event_info EINA_UNUSED) -{ - const char *name; - char *path; - const char *directory = _directory_path; - FILE *f; - - if (!ecore_file_is_dir(directory)) - return; - - name = elm_entry_entry_get((Evas_Object *) data); - if (!name || strlen(name) == 0) - { - _edi_file_message_open("Please enter a file name."); - return; - } - - path = edi_path_append(directory, name); - if ((ecore_file_exists(path) && ecore_file_is_dir(path)) || - !ecore_file_exists(path)) - { - f = fopen(path, "w"); - if (f) - { - fclose(f); - edi_mainview_open_path(path); - } - else - _edi_file_message_open("Unable to write file."); - } - - eina_stringshare_del(_directory_path); - _directory_path = NULL; - - evas_object_del(_popup); - free(path); -} - -static void -_edi_file_create_dir_cb(void *data, - Evas_Object *obj EINA_UNUSED, - void *event_info EINA_UNUSED) -{ - const char *name; - char *path; - const char *directory = _directory_path; - - if (!ecore_file_is_dir(directory)) return; - - name = elm_entry_entry_get((Evas_Object *) data); - if (!name || strlen(name) == 0) - { - _edi_file_message_open("Please enter a directory name."); - return; - } - - path = edi_path_append(directory, name); - - mkdir(path, 0755); - - eina_stringshare_del(_directory_path); - _directory_path = NULL; - - evas_object_del(_popup_dir); - free(path); -} - -void -edi_file_create_file(Evas_Object *parent, const char *directory) -{ - Evas_Object *popup, *box, *input, *button; - - _parent_obj = parent; - _popup = popup = elm_popup_add(parent); - elm_object_part_text_set(popup, "title,text", - "Enter new file name"); - _directory_path = eina_stringshare_add(directory); - - box = elm_box_add(popup); - elm_box_horizontal_set(box, EINA_FALSE); - elm_object_content_set(popup, box); - - input = elm_entry_add(box); - elm_entry_single_line_set(input, EINA_TRUE); - evas_object_size_hint_weight_set(input, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_size_hint_align_set(input, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_show(input); - elm_box_pack_end(box, input); - - button = elm_button_add(popup); - elm_object_text_set(button, "cancel"); - elm_object_part_content_set(popup, "button1", button); - evas_object_smart_callback_add(button, "clicked", - _edi_file_popup_cancel_cb, popup); - - button = elm_button_add(popup); - elm_object_text_set(button, "create"); - elm_object_part_content_set(popup, "button2", button); - evas_object_smart_callback_add(button, "clicked", - _edi_file_create_file_cb, input); - - evas_object_show(popup); - elm_object_focus_set(input, EINA_TRUE); -} - -void -edi_file_create_dir(Evas_Object *parent, const char *directory) -{ - Evas_Object *popup, *box, *input, *button; - - _parent_obj = parent; - _directory_path = eina_stringshare_add(directory); - - _popup_dir = popup = elm_popup_add(parent); - elm_object_part_text_set(popup, "title,text", - "Enter new directory name"); - - box = elm_box_add(popup); - elm_box_horizontal_set(box, EINA_FALSE); - elm_object_content_set(popup, box); - - input = elm_entry_add(box); - elm_entry_single_line_set(input, EINA_TRUE); - evas_object_size_hint_weight_set(input, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_size_hint_align_set(input, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_show(input); - elm_box_pack_end(box, input); - - button = elm_button_add(popup); - elm_object_text_set(button, "cancel"); - elm_object_part_content_set(popup, "button1", button); - evas_object_smart_callback_add(button, "clicked", - _edi_file_popup_cancel_cb, popup); - - button = elm_button_add(popup); - elm_object_text_set(button, "create"); - elm_object_part_content_set(popup, "button2", button); - evas_object_smart_callback_add(button, "clicked", - _edi_file_create_dir_cb, input); - - evas_object_show(popup); - elm_object_focus_set(input, EINA_TRUE); -} - diff --git a/src/bin/edi_file.h b/src/bin/edi_file.h index 233c8b3..2c0e587 100644 --- a/src/bin/edi_file.h +++ b/src/bin/edi_file.h @@ -18,7 +18,7 @@ extern "C" { * * @{ * - * Management of file/dir creation with the UI + * Management of file/dir actions. * */ @@ -32,25 +32,6 @@ extern "C" { Eina_Bool edi_file_path_hidden(const char *path); /** - * Create a file add dialogue and add it to the parent obj. - * - * @param parent The object into which the UI will load. - * @param directory The directory root of which file is created. - * @ingroup UI - */ - -void edi_file_create_file(Evas_Object *parent, const char *directory); - -/** - * Create a directory add dialogue and add it to the parent obj. - * - * @param parent The object into which the UI will load. - * @param directory The directory root of which directory is created. - * @ingroup UI - */ - -void edi_file_create_dir(Evas_Object *parent, const char *directory); -/** * @} */ diff --git a/src/bin/edi_filepanel.c b/src/bin/edi_filepanel.c index bf9b3bd..aff6a6b 100644 --- a/src/bin/edi_filepanel.c +++ b/src/bin/edi_filepanel.c @@ -16,7 +16,7 @@ #include "edi_file.h" #include "edi_content_provider.h" #include "mainview/edi_mainview.h" - +#include "screens/edi_file_screens.h" #include "edi_private.h" typedef struct _Edi_Dir_Data @@ -134,6 +134,15 @@ _item_menu_open_as_image_cb(void *data, Evas_Object *obj EINA_UNUSED, } static void +_item_menu_rename_cb(void *data, Evas_Object *obj EINA_UNUSED, + void *event_info EINA_UNUSED) +{ + Edi_Dir_Data *sd = data; + + edi_file_screens_rename(_main_win, sd->path); +} + +static void _item_menu_del_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { @@ -182,6 +191,7 @@ _item_menu_create(Evas_Object *win, Edi_Dir_Data *sd) _item_menu_filetype_create(menu, menu_it, "text", _item_menu_open_as_text_cb, sd); _item_menu_filetype_create(menu, menu_it, "code", _item_menu_open_as_code_cb, sd); _item_menu_filetype_create(menu, menu_it, "image", _item_menu_open_as_image_cb, sd); + menu_it = elm_menu_item_add(menu, NULL, "document-save-as", "rename", _item_menu_rename_cb, sd); menu_it = elm_menu_item_add(menu, NULL, "edit-delete", "delete", _item_menu_del_cb, sd); } @@ -231,7 +241,7 @@ _item_menu_create_file_cb(void *data, Evas_Object *obj EINA_UNUSED, if (!sd->isdir) return; - edi_file_create_file(_main_win, sd->path); + edi_file_screens_create_file(_main_win, sd->path); } static void @@ -244,7 +254,7 @@ _item_menu_create_dir_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, if (!sd->isdir) return; - edi_file_create_dir(_main_win, sd->path); + edi_file_screens_create_dir(_main_win, sd->path); } static void @@ -257,8 +267,13 @@ _item_menu_dir_create(Evas_Object *win, Edi_Dir_Data *sd) elm_menu_item_add(menu, NULL, "folder-new", "create directory here", _item_menu_create_dir_cb, sd); if (ecore_file_app_installed("terminology")) elm_menu_item_add(menu, NULL, "terminal", "open terminal here", _item_menu_open_terminal_cb, sd); - if (ecore_file_dir_is_empty(sd->path)) - elm_menu_item_add(menu, NULL, "edit-delete", "remove directory", _item_menu_rmdir_cb, sd); + + if (strcmp(sd->path, edi_project_get())) + { + elm_menu_item_add(menu, NULL, "document-save-as", "rename", _item_menu_rename_cb, sd); + if (ecore_file_dir_is_empty(sd->path)) + elm_menu_item_add(menu, NULL, "edit-delete", "remove directory", _item_menu_rmdir_cb, sd); + } } static void diff --git a/src/bin/edi_main.c b/src/bin/edi_main.c index 38a05d8..e442fcf 100644 --- a/src/bin/edi_main.c +++ b/src/bin/edi_main.c @@ -25,6 +25,7 @@ #include "edi_content_provider.h" #include "mainview/edi_mainview.h" #include "screens/edi_screens.h" +#include "screens/edi_file_screens.h" #include "edi_private.h" @@ -582,7 +583,7 @@ _tb_new_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSE elm_toolbar_item_selected_set(elm_toolbar_selected_item_get(obj), EINA_FALSE); - edi_file_create_file(_edi_main_win, path); + edi_file_screens_create_file(_edi_main_win, path); } static void @@ -728,7 +729,7 @@ _edi_menu_new_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, else path = edi_project_get(); - edi_file_create_file(_edi_main_win, path); + edi_file_screens_create_file(_edi_main_win, path); } static void @@ -742,7 +743,7 @@ _edi_menu_new_dir_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, else path = edi_project_get(); - edi_file_create_dir(_edi_main_win, path); + edi_file_screens_create_dir(_edi_main_win, path); } static void diff --git a/src/bin/edi_file.c b/src/bin/screens/edi_file_screens.c similarity index 53% copy from src/bin/edi_file.c copy to src/bin/screens/edi_file_screens.c index 1a06d8b..6b1aebe 100644 --- a/src/bin/edi_file.c +++ b/src/bin/screens/edi_file_screens.c @@ -1,28 +1,13 @@ #include "Edi.h" #include "mainview/edi_mainview.h" -#include "edi_file.h" +#include "edi_file_screens.h" #include "edi_private.h" -static Evas_Object *_parent_obj, *_popup, *_popup_dir, *_edi_file_message_popup; +static Evas_Object *_parent_obj, *_popup, *_popup_dir, *_edi_file_screens_message_popup; static const char *_directory_path; -Eina_Bool -edi_file_path_hidden(const char *path) -{ - Edi_Build_Provider *provider; - - provider = edi_build_provider_for_project_get(); - if (provider && provider->file_hidden_is(path)) - return EINA_TRUE; - - if (ecore_file_file_get(path)[0] == '.') - return EINA_TRUE; - - return EINA_FALSE; -} - static void -_edi_file_message_close_cb(void *data EINA_UNUSED, +_edi_file_screens_message_close_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { @@ -31,11 +16,11 @@ _edi_file_message_close_cb(void *data EINA_UNUSED, } static void -_edi_file_message_open(const char *message) +_edi_file_screens_message_open(const char *message) { Evas_Object *popup, *button; - _edi_file_message_popup = popup = elm_popup_add(_parent_obj); + _edi_file_screens_message_popup = popup = elm_popup_add(_parent_obj); elm_object_part_text_set(popup, "title,text", message); @@ -43,13 +28,13 @@ _edi_file_message_open(const char *message) elm_object_text_set(button, "Ok"); elm_object_part_content_set(popup, "button1", button); evas_object_smart_callback_add(button, "clicked", - _edi_file_message_close_cb, popup); + _edi_file_screens_message_close_cb, popup); evas_object_show(popup); } static void -_edi_file_popup_cancel_cb(void *data, Evas_Object *obj EINA_UNUSED, +_edi_file_screens_popup_cancel_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { evas_object_del((Evas_Object *)data); @@ -58,7 +43,7 @@ _edi_file_popup_cancel_cb(void *data, Evas_Object *obj EINA_UNUSED, } static void -_edi_file_create_file_cb(void *data, +_edi_file_screens_create_file_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { @@ -73,7 +58,7 @@ _edi_file_create_file_cb(void *data, name = elm_entry_entry_get((Evas_Object *) data); if (!name || strlen(name) == 0) { - _edi_file_message_open("Please enter a file name."); + _edi_file_screens_message_open("Please enter a file name."); return; } @@ -88,7 +73,7 @@ _edi_file_create_file_cb(void *data, edi_mainview_open_path(path); } else - _edi_file_message_open("Unable to write file."); + _edi_file_screens_message_open("Unable to write file."); } eina_stringshare_del(_directory_path); @@ -99,7 +84,7 @@ _edi_file_create_file_cb(void *data, } static void -_edi_file_create_dir_cb(void *data, +_edi_file_screens_create_dir_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { @@ -112,7 +97,7 @@ _edi_file_create_dir_cb(void *data, name = elm_entry_entry_get((Evas_Object *) data); if (!name || strlen(name) == 0) { - _edi_file_message_open("Please enter a directory name."); + _edi_file_screens_message_open("Please enter a directory name."); return; } @@ -127,8 +112,102 @@ _edi_file_create_dir_cb(void *data, free(path); } +static void +_edi_file_screens_rename_cb(void *data, + Evas_Object *obj, + void *event_info EINA_UNUSED) +{ + Evas_Object *entry; + const char *name, *existing_path, *directory; + char *path; + + directory = _directory_path; + existing_path = (char *) data; + + entry = evas_object_data_get(obj, "input"); + + name = elm_entry_entry_get(entry); + if (!name || strlen(name) == 0) + { + _edi_file_screens_message_open("Please enter a valid name."); + return; + } + + path = edi_path_append(directory, name); + + if (ecore_file_exists(path)) + { + if (ecore_file_is_dir(path)) + _edi_file_screens_message_open("Directory with that name already exists."); + else + _edi_file_screens_message_open("File with that name already exists."); + return; + } + + eina_stringshare_del(_directory_path); + _directory_path = NULL; + + if (strcmp(existing_path, path)) + { + if (!ecore_file_is_dir(existing_path)) + edi_mainview_item_close_path(existing_path); + ecore_file_mv(existing_path, path); + } + + evas_object_del(_popup); + free(path); +} + +void +edi_file_screens_rename(Evas_Object *parent, const char *path) +{ + Evas_Object *popup, *box, *input, *button; + const char *leaf; + + _parent_obj = parent; + _popup = popup = elm_popup_add(parent); + + if (ecore_file_is_dir(path)) + elm_object_part_text_set(popup, "title,text", + "Rename directory"); + else + elm_object_part_text_set(popup, "title,text", + "Rename file"); + leaf = ecore_file_file_get(path); + _directory_path = eina_stringshare_add(ecore_file_dir_get(path)); + + box = elm_box_add(popup); + elm_box_horizontal_set(box, EINA_FALSE); + elm_object_content_set(popup, box); + + input = elm_entry_add(box); + elm_entry_single_line_set(input, EINA_TRUE); + elm_entry_editable_set(input, EINA_TRUE); + elm_object_text_set(input, leaf); + 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); + evas_object_show(input); + elm_box_pack_end(box, input); + + button = elm_button_add(popup); + elm_object_text_set(button, "cancel"); + elm_object_part_content_set(popup, "button1", button); + evas_object_smart_callback_add(button, "clicked", + _edi_file_screens_popup_cancel_cb, popup); + + button = elm_button_add(popup); + evas_object_data_set(button, "input", input); + elm_object_text_set(button, "rename"); + elm_object_part_content_set(popup, "button2", button); + evas_object_smart_callback_add(button, "clicked", + _edi_file_screens_rename_cb, path); + + evas_object_show(popup); + elm_object_focus_set(input, EINA_TRUE); +} + void -edi_file_create_file(Evas_Object *parent, const char *directory) +edi_file_screens_create_file(Evas_Object *parent, const char *directory) { Evas_Object *popup, *box, *input, *button; @@ -153,20 +232,20 @@ edi_file_create_file(Evas_Object *parent, const char *directory) elm_object_text_set(button, "cancel"); elm_object_part_content_set(popup, "button1", button); evas_object_smart_callback_add(button, "clicked", - _edi_file_popup_cancel_cb, popup); + _edi_file_screens_popup_cancel_cb, popup); button = elm_button_add(popup); elm_object_text_set(button, "create"); elm_object_part_content_set(popup, "button2", button); evas_object_smart_callback_add(button, "clicked", - _edi_file_create_file_cb, input); + _edi_file_screens_create_file_cb, input); evas_object_show(popup); elm_object_focus_set(input, EINA_TRUE); } void -edi_file_create_dir(Evas_Object *parent, const char *directory) +edi_file_screens_create_dir(Evas_Object *parent, const char *directory) { Evas_Object *popup, *box, *input, *button; @@ -192,13 +271,13 @@ edi_file_create_dir(Evas_Object *parent, const char *directory) elm_object_text_set(button, "cancel"); elm_object_part_content_set(popup, "button1", button); evas_object_smart_callback_add(button, "clicked", - _edi_file_popup_cancel_cb, popup); + _edi_file_screens_popup_cancel_cb, popup); button = elm_button_add(popup); elm_object_text_set(button, "create"); elm_object_part_content_set(popup, "button2", button); evas_object_smart_callback_add(button, "clicked", - _edi_file_create_dir_cb, input); + _edi_file_screens_create_dir_cb, input); evas_object_show(popup); elm_object_focus_set(input, EINA_TRUE); diff --git a/src/bin/edi_file.h b/src/bin/screens/edi_file_screens.h similarity index 55% copy from src/bin/edi_file.h copy to src/bin/screens/edi_file_screens.h index 233c8b3..645795c 100644 --- a/src/bin/edi_file.h +++ b/src/bin/screens/edi_file_screens.h @@ -1,5 +1,5 @@ -#ifndef __EDI_FILE_H__ -#define __EDI_FILE_H__ +#ifndef __EDI_FILE_SCREENS_H__ +#define __EDI_FILE_SCREENS_H__ #include <Elementary.h> @@ -9,7 +9,7 @@ extern "C" { /** * @file - * @brief These routines used for managing Edi file actions. + * @brief These routines used for managing Edi file actions from UI. */ /** @@ -23,15 +23,6 @@ extern "C" { */ /** - * Check the path is not hidden according to project rules. - * - * @param path The file path to check. - * @ingroup Lookup - */ - -Eina_Bool edi_file_path_hidden(const char *path); - -/** * Create a file add dialogue and add it to the parent obj. * * @param parent The object into which the UI will load. @@ -39,7 +30,7 @@ Eina_Bool edi_file_path_hidden(const char *path); * @ingroup UI */ -void edi_file_create_file(Evas_Object *parent, const char *directory); +void edi_file_screens_create_file(Evas_Object *parent, const char *directory); /** * Create a directory add dialogue and add it to the parent obj. @@ -49,7 +40,17 @@ void edi_file_create_file(Evas_Object *parent, const char *directory); * @ingroup UI */ -void edi_file_create_dir(Evas_Object *parent, const char *directory); +void edi_file_screens_create_dir(Evas_Object *parent, const char *directory); + +/** + * Create a dialogue for renaming item and add it to the parent obj + * + * @param parent The object into which the UI will load + * @param path The path of the file or directory to rename + * @ingroup UI + */ + +void edi_file_screens_rename(Evas_Object *parent, const char *path); /** * @} */ --