Skip to content

Commit

Permalink
support "clean" files (#1983)
Browse files Browse the repository at this point in the history
* init for clean files
* textual
* icons position
  • Loading branch information
zxkmm authored Mar 13, 2024
1 parent 999f9e2 commit 14f42d1
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 5 deletions.
54 changes: 53 additions & 1 deletion firmware/application/apps/ui_fileman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand All @@ -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<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");
return;
}
}

void FileManagerView::on_new_dir() {
name_buffer = "";
text_prompt(nav_, name_buffer, max_filename_length, [this](std::string& dir_name) {
Expand Down Expand Up @@ -560,6 +606,7 @@ FileManagerView::FileManagerView(
&text_date,
&button_rename,
&button_delete,
&button_clean,
&button_cut,
&button_copy,
&button_paste,
Expand Down Expand Up @@ -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();
Expand Down
17 changes: 13 additions & 4 deletions firmware/application/apps/ui_fileman.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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},
{},
Expand Down Expand Up @@ -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()};
Expand Down

0 comments on commit 14f42d1

Please sign in to comment.