diff --git a/firmware/application/apps/ui_fileman.cpp b/firmware/application/apps/ui_fileman.cpp index cb359878..a4b007fe 100644 --- a/firmware/application/apps/ui_fileman.cpp +++ b/firmware/application/apps/ui_fileman.cpp @@ -402,6 +402,7 @@ void FileSaveView::refresh_widgets() { void FileManagerView::refresh_widgets(const bool v) { button_rename.hidden(v); button_delete.hidden(v); + button_clean.hidden(v); button_cut.hidden(v); button_copy.hidden(v); button_paste.hidden(v); @@ -449,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!"); + nav_.display_modal("Delete", "Directory not empty;\nUse \"clean\" button\nto clean it first"); return; } @@ -474,6 +475,51 @@ 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"); + return; + } +} + void FileManagerView::on_new_dir() { name_buffer = ""; text_prompt(nav_, name_buffer, max_filename_length, [this](std::string& dir_name) { @@ -560,6 +606,7 @@ FileManagerView::FileManagerView( &text_date, &button_rename, &button_delete, + &button_clean, &button_cut, &button_copy, &button_paste, @@ -606,6 +653,11 @@ FileManagerView::FileManagerView( on_delete(); }; + button_clean.on_select = [this]() { + if (selected_is_valid()) + on_clean(); + }; + button_cut.on_select = [this]() { if (selected_is_valid() && !get_selected_entry().is_directory) { clipboard_path = get_selected_full_path(); diff --git a/firmware/application/apps/ui_fileman.hpp b/firmware/application/apps/ui_fileman.hpp index 24a145eb..38017c78 100644 --- a/firmware/application/apps/ui_fileman.hpp +++ b/firmware/application/apps/ui_fileman.hpp @@ -207,6 +207,7 @@ class FileManagerView : public FileManBaseView { void refresh_widgets(const bool v); void on_rename(std::string_view hint); void on_delete(); + void on_clean(); void on_paste(); void on_new_dir(); void on_new_file(); @@ -227,11 +228,17 @@ class FileManagerView : public FileManBaseView { Color::dark_blue()}; NewButton button_delete{ - {4 * 8, 29 * 8, 4 * 8, 32}, + {9 * 8, 34 * 8, 4 * 8, 32}, {}, &bitmap_icon_trash, Color::red()}; + NewButton button_clean{ + {13 * 8, 34 * 8, 4 * 8, 32}, + {}, + &bitmap_icon_scanner, + Color::red()}; + NewButton button_cut{ {9 * 8, 29 * 8, 4 * 8, 32}, {}, @@ -269,20 +276,22 @@ class FileManagerView : public FileManBaseView { Color::orange()}; NewButton button_rename_timestamp{ - {4 * 8, 34 * 8, 4 * 8, 32}, + + {4 * 8, 29 * 8, 4 * 8, 32}, {}, &bitmap_icon_options_datetime, Color::orange(), /*vcenter*/ true}; NewButton button_open_iq_trim{ - {9 * 8, 34 * 8, 4 * 8, 32}, + + {4 * 8, 34 * 8, 4 * 8, 32}, {}, &bitmap_icon_trim, Color::orange()}; NewButton button_show_hidden_files{ - {13 * 8, 34 * 8, 4 * 8, 32}, + {17 * 8, 34 * 8, 4 * 8, 32}, {}, &bitmap_icon_hide, Color::dark_grey()};