From e1cc0b1ad0ebe93dbd1c9f7c805a6fbdd0254c5a Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Wed, 16 Aug 2023 03:00:46 -0500 Subject: [PATCH] Show file count in each directory, and moved "Too many files" message (#1376) * Added file_count() function * Show file count in each directory; moved "Too many files!" warning --- firmware/application/apps/ui_fileman.cpp | 22 +++++++++++++--------- firmware/application/apps/ui_fileman.hpp | 10 +--------- firmware/application/file.cpp | 11 +++++++++++ firmware/application/file.hpp | 2 ++ 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/firmware/application/apps/ui_fileman.cpp b/firmware/application/apps/ui_fileman.cpp index 323110b6..fb3405e5 100644 --- a/firmware/application/apps/ui_fileman.cpp +++ b/firmware/application/apps/ui_fileman.cpp @@ -185,7 +185,6 @@ FileManBaseView::FileManBaseView( extension_filter{filter} { add_children({&labels, &text_current, - &text_info, &button_exit}); button_exit.on_select = [this, &nav](Button&) { @@ -250,8 +249,10 @@ void FileManBaseView::refresh_list() { auto entry_name = truncate(entry.path, 20); if (entry.is_directory) { + auto size_str = (entry.path == parent_dir_path) ? "" : to_string_dec_uint(file_count(entry.path)); + menu_view.add_item( - {entry_name, + {entry_name + std::string(21 - entry_name.length(), ' ') + size_str, ui::Color::yellow(), &bitmap_icon_dir, [this](KeyEvent key) { @@ -278,7 +279,6 @@ void FileManBaseView::refresh_list() { break; } - text_info.set(menu_view.item_count() >= max_items_shown ? "Too many files!" : ""); menu_view.set_highlighted(prev_highlight); } @@ -342,7 +342,6 @@ FileSaveView::FileSaveView( file_{ file } { add_children({ - &labels, &text_path, &button_edit_path, &text_name, @@ -546,7 +545,6 @@ FileManagerView::FileManagerView( add_children({ &menu_view, - &labels, &text_date, &button_rename, &button_delete, @@ -560,10 +558,16 @@ FileManagerView::FileManagerView( }); menu_view.on_highlight = [this]() { - if (selected_is_valid()) - text_date.set(to_string_FAT_timestamp(file_created_date(get_selected_full_path()))); - else - text_date.set(""); + if (menu_view.highlighted_index() >= max_items_shown - 1) { + text_date.set_style(&Styles::red); + text_date.set("Too many files!"); + } else { + text_date.set_style(&Styles::grey); + if (selected_is_valid()) + text_date.set((is_directory(get_selected_full_path()) ? "Created " : "Modified ") + to_string_FAT_timestamp(file_created_date(get_selected_full_path()))); + else + text_date.set(""); + } }; refresh_list(); diff --git a/firmware/application/apps/ui_fileman.hpp b/firmware/application/apps/ui_fileman.hpp index 3eadd749..2ada96b7 100644 --- a/firmware/application/apps/ui_fileman.hpp +++ b/firmware/application/apps/ui_fileman.hpp @@ -115,11 +115,6 @@ class FileManBaseView : public View { {0, 2 * 8, 240, 26 * 8}, true}; - // HACK: for item count limit. - Text text_info{ - {1 * 8, 35 * 8, 15 * 8, 16}, - ""}; - Button button_exit{ {22 * 8, 34 * 8, 8 * 8, 32}, "Exit"}; @@ -218,11 +213,8 @@ class FileManagerView : public FileManBaseView { // True if the selected entry is a real file item. bool selected_is_valid() const; - Labels labels{ - {{0, 26 * 8}, "Created ", Color::light_grey()}}; - Text text_date{ - {8 * 8, 26 * 8, 19 * 8, 16}, + {0 * 8, 26 * 8, 28 * 8, 16}, ""}; NewButton button_rename{ diff --git a/firmware/application/file.cpp b/firmware/application/file.cpp index 95f1966b..e44db141 100644 --- a/firmware/application/file.cpp +++ b/firmware/application/file.cpp @@ -579,6 +579,17 @@ bool is_empty_directory(const path& file_path) { return !((result == FR_OK) && (filinfo.fname[0] != (TCHAR)'\0')); } +int file_count(const path& directory) { + int count{0}; + + for (auto& entry : std::filesystem::directory_iterator(directory, (const TCHAR*)u"*")) { + (void)entry; // avoid unused warning + ++count; + } + + return count; +} + space_info space(const path& p) { DWORD free_clusters{0}; FATFS* fs; diff --git a/firmware/application/file.hpp b/firmware/application/file.hpp index afe6db1b..d2f83962 100644 --- a/firmware/application/file.hpp +++ b/firmware/application/file.hpp @@ -250,6 +250,8 @@ bool file_exists(const path& file_path); bool is_directory(const path& file_path); bool is_empty_directory(const path& file_path); +int file_count(const path& dir_path); + space_info space(const path& p); } /* namespace filesystem */