From 9af6616882ca3f6981fe47f2b79f609637a692a8 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sat, 27 May 2023 13:39:54 +0300 Subject: [PATCH] Archive, fix rename, show message to user --- .../archive/scenes/archive_scene_rename.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/applications/main/archive/scenes/archive_scene_rename.c b/applications/main/archive/scenes/archive_scene_rename.c index 346383162..e6c728f03 100644 --- a/applications/main/archive/scenes/archive_scene_rename.c +++ b/applications/main/archive/scenes/archive_scene_rename.c @@ -22,17 +22,21 @@ void archive_scene_rename_on_enter(void* context) { TextInput* text_input = archive->text_input; ArchiveFile_t* current = archive_get_current_file(archive->browser); - FuriString* path_name; - path_name = furi_string_alloc(); + FuriString* path_name = furi_string_alloc(); + FuriString* path_folder = furi_string_alloc(); if(current->type == ArchiveFileTypeFolder) { + // Set file ext to empty since we need to see folder name here + strcpy(archive->file_extension, ""); + // Extract folder name and copy into text_store path_extract_basename(furi_string_get_cstr(current->path), path_name); strlcpy(archive->text_store, furi_string_get_cstr(path_name), MAX_NAME_LEN); text_input_set_header_text(text_input, "Rename directory:"); } else /*if(current->type != ArchiveFileTypeUnknown) */ { + // Extract file name and copy into text_store path_extract_filename(current->path, path_name, true); strlcpy(archive->text_store, furi_string_get_cstr(path_name), MAX_NAME_LEN); - + // Extract file extension for validator and rename func path_extract_extension(current->path, archive->file_extension, MAX_EXT_LEN); text_input_set_header_text(text_input, "Rename file:"); } /*else { @@ -41,6 +45,9 @@ void archive_scene_rename_on_enter(void* context) { text_input_set_header_text(text_input, "Rename unknown file:"); }*/ + // Get current folder (for file) or previous folder (for folder) for validator + path_extract_dirname(furi_string_get_cstr(current->path), path_folder); + text_input_set_result_callback( text_input, archive_scene_rename_text_input_callback, @@ -49,7 +56,13 @@ void archive_scene_rename_on_enter(void* context) { MAX_TEXT_INPUT_LEN, false); + // Init validator to show message to user that name already exist + ValidatorIsFile* validator_is_file = validator_is_file_alloc_init( + furi_string_get_cstr(path_folder), archive->file_extension, archive->text_store); + text_input_set_validator(text_input, validator_is_file_callback, validator_is_file); + furi_string_free(path_name); + furi_string_free(path_folder); view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewTextInput); }