mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-06-22 05:44:31 -04:00
Fileman empty directory bugfix
Ajouté trames + config collier LGE
This commit is contained in:
parent
9f587e6085
commit
30db22828c
5 changed files with 218 additions and 119 deletions
|
@ -39,15 +39,24 @@ void FileManBaseView::load_directory_contents(const std::filesystem::path& dir_p
|
|||
auto filtering = (bool)extension_filter.size();
|
||||
|
||||
// List directories and files, put directories up top
|
||||
if (dir_path.string().length())
|
||||
entry_list.push_back({ u"..", 0, true });
|
||||
|
||||
for (const auto& entry : std::filesystem::directory_iterator(dir_path, u"*")) {
|
||||
if (std::filesystem::is_regular_file(entry.status())) {
|
||||
if (entry.path().string().length()) {
|
||||
auto entry_extension = entry.path().extension().string();
|
||||
|
||||
for (auto &c: entry_extension)
|
||||
c = toupper(c);
|
||||
bool matched = true;
|
||||
if (filtering) {
|
||||
auto entry_extension = entry.path().extension().string();
|
||||
|
||||
if ((entry_extension == extension_filter) || !filtering)
|
||||
for (auto &c: entry_extension)
|
||||
c = toupper(c);
|
||||
|
||||
if (entry_extension != extension_filter)
|
||||
matched = false;
|
||||
}
|
||||
|
||||
if (matched)
|
||||
entry_list.push_back({ entry.path(), (uint32_t)entry.size(), false });
|
||||
}
|
||||
} else if (std::filesystem::is_directory(entry.status())) {
|
||||
|
@ -57,15 +66,26 @@ void FileManBaseView::load_directory_contents(const std::filesystem::path& dir_p
|
|||
}
|
||||
|
||||
std::filesystem::path FileManBaseView::get_selected_path() {
|
||||
std::string selected_path_str = current_path.string();
|
||||
auto selected_path_str = current_path.string();
|
||||
auto entry_path = entry_list[menu_view.highlighted_index()].entry_path.string();
|
||||
|
||||
if (selected_path_str.back() != '/')
|
||||
selected_path_str += '/';
|
||||
selected_path_str += (entry_list[menu_view.highlighted_index()].entry_path.string());
|
||||
if (entry_path == "..") {
|
||||
selected_path_str = get_parent_dir().string();
|
||||
} else {
|
||||
if (selected_path_str.back() != '/')
|
||||
selected_path_str += '/';
|
||||
|
||||
selected_path_str += entry_path;
|
||||
}
|
||||
|
||||
return selected_path_str;
|
||||
}
|
||||
|
||||
std::filesystem::path FileManBaseView::get_parent_dir() {
|
||||
auto current_path_str = current_path.string();
|
||||
return current_path.string().substr(0, current_path_str.find_last_of('/'));
|
||||
}
|
||||
|
||||
FileManBaseView::FileManBaseView(
|
||||
NavigationView& nav,
|
||||
std::string filter
|
||||
|
@ -83,12 +103,8 @@ FileManBaseView::FileManBaseView(
|
|||
&button_exit
|
||||
});
|
||||
|
||||
// Go back one level on left
|
||||
menu_view.on_left = [&nav, this]() {
|
||||
std::string current_path_str = current_path.string();
|
||||
|
||||
current_path_str = current_path_str.substr(0, current_path_str.find_last_of('/'));
|
||||
load_directory_contents(current_path_str);
|
||||
load_directory_contents(get_parent_dir());
|
||||
refresh_list();
|
||||
};
|
||||
|
||||
|
@ -107,73 +123,66 @@ void FileManBaseView::focus() {
|
|||
}
|
||||
|
||||
void FileManBaseView::refresh_list() {
|
||||
if (!entry_list.size()) {
|
||||
// Hide widgets, show warning
|
||||
if (on_refresh_widgets)
|
||||
on_refresh_widgets(true);
|
||||
} else {
|
||||
// Hide warning, show widgets
|
||||
if (on_refresh_widgets)
|
||||
on_refresh_widgets(false);
|
||||
if (on_refresh_widgets)
|
||||
on_refresh_widgets(false);
|
||||
|
||||
menu_view.clear();
|
||||
|
||||
menu_view.clear();
|
||||
for (size_t n = 0; n < entry_list.size(); n++) {
|
||||
auto entry = &entry_list[n];
|
||||
auto entry_name = entry->entry_path.filename().string().substr(0, 20);
|
||||
|
||||
for (size_t n = 0; n < entry_list.size(); n++) {
|
||||
auto entry = &entry_list[n];
|
||||
auto entry_name = entry->entry_path.filename().string().substr(0, 20);
|
||||
if (entry->is_directory) {
|
||||
|
||||
if (entry->is_directory) {
|
||||
|
||||
menu_view.add_item({
|
||||
entry_name,
|
||||
ui::Color::yellow(),
|
||||
&bitmap_icon_dir,
|
||||
[this](){
|
||||
if (on_select_entry)
|
||||
on_select_entry();
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
auto file_size = entry->size;
|
||||
size_t suffix_index = 0;
|
||||
|
||||
while (file_size >= 1024) {
|
||||
file_size /= 1024;
|
||||
suffix_index++;
|
||||
menu_view.add_item({
|
||||
entry_name,
|
||||
ui::Color::yellow(),
|
||||
&bitmap_icon_dir,
|
||||
[this](){
|
||||
if (on_select_entry)
|
||||
on_select_entry();
|
||||
}
|
||||
if (suffix_index > 4)
|
||||
suffix_index = 4;
|
||||
|
||||
std::string size_str = to_string_dec_uint(file_size) + suffix[suffix_index];
|
||||
|
||||
auto entry_extension = entry->entry_path.extension().string();
|
||||
for (auto &c: entry_extension)
|
||||
c = toupper(c);
|
||||
|
||||
// Associate extension to icon and color
|
||||
size_t c;
|
||||
for (c = 0; c < file_types.size() - 1; c++) {
|
||||
if (entry_extension == file_types[c].extension)
|
||||
break;
|
||||
}
|
||||
|
||||
menu_view.add_item({
|
||||
entry_name + std::string(21 - entry_name.length(), ' ') + size_str,
|
||||
file_types[c].color,
|
||||
file_types[c].icon,
|
||||
[this](){
|
||||
if (on_select_entry)
|
||||
on_select_entry();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
auto file_size = entry->size;
|
||||
size_t suffix_index = 0;
|
||||
|
||||
while (file_size >= 1024) {
|
||||
file_size /= 1024;
|
||||
suffix_index++;
|
||||
}
|
||||
if (suffix_index > 4)
|
||||
suffix_index = 4;
|
||||
|
||||
std::string size_str = to_string_dec_uint(file_size) + suffix[suffix_index];
|
||||
|
||||
auto entry_extension = entry->entry_path.extension().string();
|
||||
for (auto &c: entry_extension)
|
||||
c = toupper(c);
|
||||
|
||||
// Associate extension to icon and color
|
||||
size_t c;
|
||||
for (c = 0; c < file_types.size() - 1; c++) {
|
||||
if (entry_extension == file_types[c].extension)
|
||||
break;
|
||||
}
|
||||
|
||||
menu_view.add_item({
|
||||
entry_name + std::string(21 - entry_name.length(), ' ') + size_str,
|
||||
file_types[c].color,
|
||||
file_types[c].icon,
|
||||
[this](){
|
||||
if (on_select_entry)
|
||||
on_select_entry();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
menu_view.set_highlighted(0); // Refresh
|
||||
}
|
||||
|
||||
menu_view.set_highlighted(0); // Refresh
|
||||
}
|
||||
|
||||
/*void FileSaveView::on_save_name() {
|
||||
|
@ -200,8 +209,6 @@ FileSaveView::FileSaveView(
|
|||
}*/
|
||||
|
||||
void FileLoadView::refresh_widgets(const bool v) {
|
||||
menu_view.hidden(v);
|
||||
text_empty.hidden(!v);
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
|
@ -215,8 +222,7 @@ FileLoadView::FileLoadView(
|
|||
};
|
||||
|
||||
add_children({
|
||||
&menu_view,
|
||||
&text_empty
|
||||
&menu_view
|
||||
});
|
||||
|
||||
// Resize menu view to fill screen
|
||||
|
@ -254,8 +260,6 @@ void FileManagerView::refresh_widgets(const bool v) {
|
|||
button_rename.hidden(v);
|
||||
button_new_dir.hidden(v);
|
||||
button_delete.hidden(v);
|
||||
menu_view.hidden(v);
|
||||
text_empty.hidden(!v);
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
|
@ -273,7 +277,6 @@ FileManagerView::FileManagerView(
|
|||
|
||||
add_children({
|
||||
&menu_view,
|
||||
&text_empty,
|
||||
&labels,
|
||||
&text_date,
|
||||
&button_rename,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue