From 216f8b4fb86ec8a29b061b0ac1ab50b63157397c Mon Sep 17 00:00:00 2001 From: its your bedtime <23366927+itsyourbedtime@users.noreply.github.com> Date: Mon, 7 Jun 2021 19:47:27 +0300 Subject: [PATCH] archive: file extension removed in rename menu (#511) Co-authored-by: SG --- applications/archive/archive.c | 11 +++++++++++ applications/archive/archive_views.c | 4 ++-- applications/archive/archive_views.h | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/applications/archive/archive.c b/applications/archive/archive.c index 11e7ab1e..93d8d11f 100644 --- a/applications/archive/archive.c +++ b/applications/archive/archive.c @@ -238,6 +238,15 @@ static void archive_text_input_callback(void* context, char* text) { string_cat(buffer_src, archive->browser.name); string_cat_str(buffer_dst, text); + // append extension + ArchiveViewModel* model = view_get_model(archive->view_archive_main); + ArchiveFile_t* file = + files_array_get(model->files, CLAMP(model->idx, files_array_size(model->files) - 1, 0)); + string_cat(buffer_src, known_ext[file->type]); + string_cat(buffer_dst, known_ext[file->type]); + model = NULL; + file = NULL; + common_api->rename(string_get_cstr(buffer_src), string_get_cstr(buffer_dst)); view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewMain); @@ -252,6 +261,8 @@ static void archive_enter_text_input(ArchiveApp* archive) { string_set(archive->browser.text_input_buffer, archive->browser.name); + archive_trim_file_ext(archive->browser.text_input_buffer); + char* text_input_buffer_ptr = stringi_get_cstr(archive->browser.text_input_buffer); text_input_set_header_text(archive->text_input, "Rename:"); diff --git a/applications/archive/archive_views.c b/applications/archive/archive_views.c index 0531b985..3cd66543 100644 --- a/applications/archive/archive_views.c +++ b/applications/archive/archive_views.c @@ -47,7 +47,7 @@ static void render_item_menu(Canvas* canvas, ArchiveViewModel* model) { canvas_draw_icon_name(canvas, 64, 20 + model->menu_idx * 11, I_ButtonRight_4x7); } -static void trim_file_ext(string_t name) { +void archive_trim_file_ext(string_t name) { size_t str_len = strlen(string_get_cstr(name)); char* buff_ptr = stringi_get_cstr(name); char* end = buff_ptr + str_len; @@ -88,7 +88,7 @@ static void draw_list(Canvas* canvas, ArchiveViewModel* model) { string_set(str_buff, file->name); - if(is_known_app(file->type)) trim_file_ext(str_buff); + if(is_known_app(file->type)) archive_trim_file_ext(str_buff); elements_string_fit_width(canvas, str_buff, scrollbar ? MAX_LEN_PX - 6 : MAX_LEN_PX); if(model->idx == idx) { diff --git a/applications/archive/archive_views.h b/applications/archive/archive_views.h index dbc114ce..c2055200 100644 --- a/applications/archive/archive_views.h +++ b/applications/archive/archive_views.h @@ -63,3 +63,4 @@ typedef struct { } ArchiveViewModel; void archive_view_render(Canvas* canvas, void* model); +void archive_trim_file_ext(string_t name); \ No newline at end of file