Skip to content

Commit

Permalink
File manager "Clean" button tweaks (#1990)
Browse files Browse the repository at this point in the history
* File Manager "clean" button tweaks

* Add files via upload
  • Loading branch information
NotherNgineer authored Mar 13, 2024
1 parent 14f42d1 commit f0614c8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 42 deletions.
62 changes: 21 additions & 41 deletions firmware/application/apps/ui_fileman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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<ModalMessageView>(
"Delete", "Will delete all sub files\nexclude sub-folders,\nin this folder\nAre you sure?", YESNO,
[this](bool choice) {
if (choice) {
std::vector<std::filesystem::path> 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<ModalMessageView>(
"Delete", "Will delete all files\nexclude sub-folders\nin this folder,\nAre you sure?", YESNO,
[this](bool choice) {
if (choice) {
std::vector<std::filesystem::path> 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<ModalMessageView>(
"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<std::filesystem::path> 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() {
Expand Down
2 changes: 1 addition & 1 deletion firmware/application/apps/ui_fileman.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
38 changes: 38 additions & 0 deletions firmware/application/bitmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__*/
Binary file added firmware/graphics/icon_clean.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f0614c8

Please sign in to comment.