From 59dfe5b50bd65522b01508ae47d7d3ee5331fa69 Mon Sep 17 00:00:00 2001 From: zxkmmOnHaseeWSL Date: Wed, 26 Apr 2023 12:54:07 +0800 Subject: [PATCH 1/4] implemented issue#917 --- firmware/application/apps/ui_fileman.cpp | 12 ++++++++++-- firmware/application/apps/ui_fileman.hpp | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/firmware/application/apps/ui_fileman.cpp b/firmware/application/apps/ui_fileman.cpp index 9271bc92..42ef2f82 100644 --- a/firmware/application/apps/ui_fileman.cpp +++ b/firmware/application/apps/ui_fileman.cpp @@ -267,14 +267,15 @@ void FileManagerView::on_refactor(NavigationView& nav) { std::string destination_path = current_path.string(); if (destination_path.back() != '/') destination_path += '/'; - destination_path = destination_path + buffer; + + destination_path = get_selected_path().string().back() != '/' ? destination_path + buffer + extension_buffer : destination_path + buffer; rename_file(get_selected_path(), destination_path); //rename the selected file auto selected_path = get_selected_path(); auto extension = selected_path.extension().string(); - if (!extension.empty() && selected_path.string().back() != '/' && extension.substr(1) == "C16") { + if (!extension.empty() && selected_path.string().back() != '/' && extension.substr(1) == "C16") { //substr(1) is for ignore the dot // Rename its partner ( C16 <-> TXT ) file. auto partner_file_path = selected_path.string().substr(0, selected_path.string().size() - 4) + ".TXT"; destination_path = destination_path.substr(0, destination_path.size() - 4) + ".TXT"; @@ -359,6 +360,13 @@ FileManagerView::FileManagerView( button_refactor.on_select = [this, &nav](Button&) { name_buffer = entry_list[menu_view.highlighted_index()].entry_path.filename().string().substr(0, max_filename_length); + size_t pos = name_buffer.find_last_of("."); + + if (pos != std::string::npos) { + extension_buffer = name_buffer.substr(pos); + name_buffer = name_buffer.substr(0, pos); + } + on_refactor(nav); }; diff --git a/firmware/application/apps/ui_fileman.hpp b/firmware/application/apps/ui_fileman.hpp index 261295e8..cfea0848 100644 --- a/firmware/application/apps/ui_fileman.hpp +++ b/firmware/application/apps/ui_fileman.hpp @@ -143,6 +143,7 @@ public: private: std::string name_buffer { }; + std::string extension_buffer { }; void refresh_widgets(const bool v); void on_rename(NavigationView& nav); From 47482d1e58153ba82a01cc464b11b7bb74427bb0 Mon Sep 17 00:00:00 2001 From: zxkmmOnHaseeWSL Date: Wed, 26 Apr 2023 13:22:50 +0800 Subject: [PATCH 2/4] fixed var.clear --- firmware/application/apps/ui_fileman.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/firmware/application/apps/ui_fileman.cpp b/firmware/application/apps/ui_fileman.cpp index 42ef2f82..88aede53 100644 --- a/firmware/application/apps/ui_fileman.cpp +++ b/firmware/application/apps/ui_fileman.cpp @@ -289,6 +289,8 @@ void FileManagerView::on_refactor(NavigationView& nav) { load_directory_contents(current_path); refresh_list(); + extension_buffer.clear(); + destination_path.clear(); }); } From 6e01a1d0dcdf5bbe6e11756621e17290dd2df1fa Mon Sep 17 00:00:00 2001 From: zxkmmOnHaseeWSL Date: Wed, 26 Apr 2023 16:20:05 +0800 Subject: [PATCH 3/4] change ?: to if else --- firmware/application/apps/ui_fileman.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/firmware/application/apps/ui_fileman.cpp b/firmware/application/apps/ui_fileman.cpp index 88aede53..be07fb8e 100644 --- a/firmware/application/apps/ui_fileman.cpp +++ b/firmware/application/apps/ui_fileman.cpp @@ -264,11 +264,16 @@ void FileManagerView::on_rename(NavigationView& nav) { void FileManagerView::on_refactor(NavigationView& nav) { text_prompt(nav, name_buffer, max_filename_length, [this](std::string& buffer) { + std::string destination_path = current_path.string(); if (destination_path.back() != '/') destination_path += '/'; - destination_path = get_selected_path().string().back() != '/' ? destination_path + buffer + extension_buffer : destination_path + buffer; + if(get_selected_path().string().back() != '/'){ + destination_path = destination_path + buffer + extension_buffer; + }else if(get_selected_path().string().back() == '/'){ + destination_path = destination_path + buffer; + } rename_file(get_selected_path(), destination_path); //rename the selected file @@ -289,9 +294,9 @@ void FileManagerView::on_refactor(NavigationView& nav) { load_directory_contents(current_path); refresh_list(); - extension_buffer.clear(); - destination_path.clear(); + }); + } void FileManagerView::on_delete() { From 9cddab9a5e88edba6f38dd879cb75c98c6716001 Mon Sep 17 00:00:00 2001 From: zxkmmOnHaseeWSL Date: Wed, 26 Apr 2023 19:09:38 +0800 Subject: [PATCH 4/4] fix mistakenly remane dir as file -- credit:Gull --- firmware/application/apps/ui_fileman.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/firmware/application/apps/ui_fileman.cpp b/firmware/application/apps/ui_fileman.cpp index be07fb8e..ed40ddf8 100644 --- a/firmware/application/apps/ui_fileman.cpp +++ b/firmware/application/apps/ui_fileman.cpp @@ -266,20 +266,21 @@ void FileManagerView::on_refactor(NavigationView& nav) { text_prompt(nav, name_buffer, max_filename_length, [this](std::string& buffer) { std::string destination_path = current_path.string(); - if (destination_path.back() != '/') + if (destination_path.back() != '/')//if the path is not ended with '/', add '/' destination_path += '/'; - if(get_selected_path().string().back() != '/'){ - destination_path = destination_path + buffer + extension_buffer; - }else if(get_selected_path().string().back() == '/'){ - destination_path = destination_path + buffer; - } - - rename_file(get_selected_path(), destination_path); //rename the selected file - auto selected_path = get_selected_path(); auto extension = selected_path.extension().string(); + if(extension.empty()){// Is Dir + destination_path = destination_path + buffer; + extension_buffer = ""; + }else{//is File + destination_path = destination_path + buffer + extension_buffer; + } + + rename_file(get_selected_path(), destination_path); //rename the selected file + if (!extension.empty() && selected_path.string().back() != '/' && extension.substr(1) == "C16") { //substr(1) is for ignore the dot // Rename its partner ( C16 <-> TXT ) file. auto partner_file_path = selected_path.string().substr(0, selected_path.string().size() - 4) + ".TXT";