From f0614c882b9b47d5d4aeaef18bc0b944c4df99fb Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Wed, 13 Mar 2024 16:42:40 -0500 Subject: [PATCH] File manager "Clean" button tweaks (#1990) * File Manager "clean" button tweaks * Add files via upload --- firmware/application/apps/ui_fileman.cpp | 62 ++++++++--------------- firmware/application/apps/ui_fileman.hpp | 2 +- firmware/application/bitmap.hpp | 38 ++++++++++++++ firmware/graphics/icon_clean.png | Bin 0 -> 182 bytes 4 files changed, 60 insertions(+), 42 deletions(-) create mode 100644 firmware/graphics/icon_clean.png diff --git a/firmware/application/apps/ui_fileman.cpp b/firmware/application/apps/ui_fileman.cpp index a4b007fec..9d33be043 100644 --- a/firmware/application/apps/ui_fileman.cpp +++ b/firmware/application/apps/ui_fileman.cpp @@ -450,7 +450,7 @@ void FileManagerView::on_rename(std::string_view hint) { void FileManagerView::on_delete() { if (is_directory(get_selected_full_path()) && !is_empty_directory(get_selected_full_path())) { - nav_.display_modal("Delete", "Directory not empty;\nUse \"clean\" button\nto clean it first"); + nav_.display_modal("Delete", " Folder is not empty;\n Use \"Clean\" button to\n empty it first."); return; } @@ -476,48 +476,28 @@ void FileManagerView::on_delete() { } void FileManagerView::on_clean() { - if (is_directory(get_selected_full_path()) && !is_empty_directory(get_selected_full_path())) { - ////selected a dir, who is not empty, del sub files - nav_.push( - "Delete", "Will delete all sub files\nexclude sub-folders,\nin this folder\nAre you sure?", YESNO, - [this](bool choice) { - if (choice) { - std::vector file_list; - file_list = scan_root_files(get_selected_full_path(), u"*"); - - for (const auto& file_name : file_list) { - std::filesystem::path current_full_path = get_selected_full_path() / file_name; - delete_file(current_full_path); - } - reload_current(); - } - }); - } else if (!is_directory(get_selected_full_path()) && !is_empty_directory(get_selected_full_path())) { - ////selected a file, will del it and all others in this dir - nav_.push( - "Delete", "Will delete all files\nexclude sub-folders\nin this folder,\nAre you sure?", YESNO, - [this](bool choice) { - if (choice) { - std::vector file_list; - file_list = scan_root_files(get_selected_full_path().parent_path(), u"*"); - - for (const auto& file_name : file_list) { - std::filesystem::path current_full_path = get_selected_full_path().parent_path() / file_name; - delete_file(current_full_path); - } - reload_current(); - } - }); - - } else if (is_directory(get_selected_full_path()) && is_empty_directory(get_selected_full_path())) { - ////sel an empty dir, threw - nav_.display_modal("Forbid", "You selected an empty dir;\nUse delete button \ninstead of clean button\nto delete it"); - return; - } else { - ////edge case e.g. probably . or .. (maybe not needed?) - nav_.display_modal("Forbid", "Not able to do that"); + if (is_empty_directory(get_selected_full_path())) { + nav_.display_modal("Clean", "Folder is Empty;\nUse \"Delete\" button instead\nof \"Clean\" button to delete\nit."); return; } + + auto path_name = is_directory(get_selected_full_path()) ? get_selected_full_path() : get_selected_full_path().parent_path(); + + // selected either a single file (delete files in this directory) or a directory that is not empty (del sub files) + nav_.push( + "Clean", " ALL FILES in this folder\n (excluding sub-folders)\n will be DELETED!\n\n Delete all files?", YESNO, + [this, path_name](bool choice) { + if (choice) { + std::vector file_list; + file_list = scan_root_files(path_name, u"*"); + + for (const auto& file_name : file_list) { + std::filesystem::path current_full_path = path_name / file_name; + delete_file(current_full_path); + } + reload_current(); + } + }); } void FileManagerView::on_new_dir() { diff --git a/firmware/application/apps/ui_fileman.hpp b/firmware/application/apps/ui_fileman.hpp index 38017c786..892e2176c 100644 --- a/firmware/application/apps/ui_fileman.hpp +++ b/firmware/application/apps/ui_fileman.hpp @@ -236,7 +236,7 @@ class FileManagerView : public FileManBaseView { NewButton button_clean{ {13 * 8, 34 * 8, 4 * 8, 32}, {}, - &bitmap_icon_scanner, + &bitmap_icon_clean, Color::red()}; NewButton button_cut{ diff --git a/firmware/application/bitmap.hpp b/firmware/application/bitmap.hpp index 9e2b36337..f4b1a2c21 100644 --- a/firmware/application/bitmap.hpp +++ b/firmware/application/bitmap.hpp @@ -5797,6 +5797,44 @@ static constexpr Bitmap bitmap_icon_brightness{ {16, 16}, bitmap_icon_brightness_data}; +static constexpr uint8_t bitmap_icon_clean_data[] = { + 0x00, + 0x00, + 0xC0, + 0x01, + 0x20, + 0x02, + 0xFC, + 0x1F, + 0x00, + 0x00, + 0x08, + 0x08, + 0xE8, + 0x08, + 0xA8, + 0x09, + 0xA8, + 0x0B, + 0x28, + 0x0A, + 0x28, + 0x0A, + 0x28, + 0x0A, + 0xE8, + 0x0B, + 0x08, + 0x08, + 0xF0, + 0x07, + 0x00, + 0x00, +}; +static constexpr Bitmap bitmap_icon_clean{ + {16, 16}, + bitmap_icon_clean_data}; + } /* namespace ui */ #endif /*__BITMAP_HPP__*/ diff --git a/firmware/graphics/icon_clean.png b/firmware/graphics/icon_clean.png new file mode 100644 index 0000000000000000000000000000000000000000..62908ff97814bcc44daa746e87669cc9db8dc223 GIT binary patch literal 182 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9F5M?jcysy3fAP%y*O z#WBR9cj+WYp#usW%#;28|9|==NH(`C0itr7> z%8?PQZ(eP3e3CS!JU_t1`oa0e(9E8goebv#xg3h>TSH};r^Q+Fc6`grx>)-t=MzWG bpHuuLzt!ZnX11&a+R5PQ>gTe~DWM4f60JXN literal 0 HcmV?d00001