mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-25 15:29:37 -05:00
Merge pull request #94 from euquiq/fix-fileman-freeze-no-or-empty-sd
Fixes File manager freezing on absent or empty SD
This commit is contained in:
commit
e7de39d130
@ -92,31 +92,37 @@ FileManBaseView::FileManBaseView(
|
|||||||
) : nav_ (nav),
|
) : nav_ (nav),
|
||||||
extension_filter { filter }
|
extension_filter { filter }
|
||||||
{
|
{
|
||||||
load_directory_contents(current_path);
|
|
||||||
|
|
||||||
if (!entry_list.size())
|
|
||||||
empty_root = true;
|
|
||||||
|
|
||||||
add_children({
|
add_children({
|
||||||
&labels,
|
&labels,
|
||||||
&text_current,
|
&text_current,
|
||||||
&button_exit
|
&button_exit
|
||||||
});
|
});
|
||||||
|
|
||||||
menu_view.on_left = [&nav, this]() {
|
|
||||||
load_directory_contents(get_parent_dir());
|
|
||||||
refresh_list();
|
|
||||||
};
|
|
||||||
|
|
||||||
button_exit.on_select = [this, &nav](Button&) {
|
button_exit.on_select = [this, &nav](Button&) {
|
||||||
nav.pop();
|
nav.pop();
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
if (!sdcIsCardInserted(&SDCD1)) {
|
||||||
|
empty_root=true;
|
||||||
|
text_current.set("NO SD CARD!");
|
||||||
|
} else {
|
||||||
|
load_directory_contents(current_path);
|
||||||
|
if (!entry_list.size())
|
||||||
|
{
|
||||||
|
empty_root = true;
|
||||||
|
text_current.set("EMPTY SD CARD!");
|
||||||
|
} else {
|
||||||
|
menu_view.on_left = [&nav, this]() {
|
||||||
|
load_directory_contents(get_parent_dir());
|
||||||
|
refresh_list();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FileManBaseView::focus() {
|
void FileManBaseView::focus() {
|
||||||
if (empty_root) {
|
if (empty_root) {
|
||||||
button_exit.focus();
|
button_exit.focus();
|
||||||
nav_.display_modal("Error", "No files in root.", ABORT, nullptr);
|
|
||||||
} else {
|
} else {
|
||||||
menu_view.focus();
|
menu_view.focus();
|
||||||
}
|
}
|
||||||
@ -190,7 +196,6 @@ void FileManBaseView::refresh_list() {
|
|||||||
nav_.pop();
|
nav_.pop();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSaveView::FileSaveView(
|
FileSaveView::FileSaveView(
|
||||||
NavigationView& nav
|
NavigationView& nav
|
||||||
) : FileManBaseView(nav)
|
) : FileManBaseView(nav)
|
||||||
@ -271,57 +276,59 @@ FileManagerView::FileManagerView(
|
|||||||
NavigationView& nav
|
NavigationView& nav
|
||||||
) : FileManBaseView(nav, "")
|
) : FileManBaseView(nav, "")
|
||||||
{
|
{
|
||||||
on_refresh_widgets = [this](bool v) {
|
if (!empty_root) {
|
||||||
refresh_widgets(v);
|
on_refresh_widgets = [this](bool v) {
|
||||||
};
|
refresh_widgets(v);
|
||||||
|
};
|
||||||
|
|
||||||
add_children({
|
add_children({
|
||||||
&menu_view,
|
&menu_view,
|
||||||
&labels,
|
&labels,
|
||||||
&text_date,
|
&text_date,
|
||||||
&button_rename,
|
&button_rename,
|
||||||
&button_new_dir,
|
&button_new_dir,
|
||||||
&button_delete
|
&button_delete
|
||||||
});
|
|
||||||
|
|
||||||
menu_view.on_highlight = [this]() {
|
|
||||||
text_date.set(to_string_FAT_timestamp(file_created_date(get_selected_path())));
|
|
||||||
};
|
|
||||||
|
|
||||||
refresh_list();
|
|
||||||
|
|
||||||
on_select_entry = [this]() {
|
|
||||||
if (entry_list[menu_view.highlighted_index()].is_directory) {
|
|
||||||
load_directory_contents(get_selected_path());
|
|
||||||
refresh_list();
|
|
||||||
} else
|
|
||||||
button_rename.focus();
|
|
||||||
};
|
|
||||||
|
|
||||||
button_new_dir.on_select = [this, &nav](Button&) {
|
|
||||||
name_buffer.clear();
|
|
||||||
|
|
||||||
text_prompt(nav, name_buffer, max_filename_length, [this](std::string& buffer) {
|
|
||||||
make_new_directory(current_path.string() + '/' + buffer);
|
|
||||||
load_directory_contents(current_path);
|
|
||||||
refresh_list();
|
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
button_rename.on_select = [this, &nav](Button&) {
|
menu_view.on_highlight = [this]() {
|
||||||
name_buffer = entry_list[menu_view.highlighted_index()].entry_path.filename().string().substr(0, max_filename_length);
|
text_date.set(to_string_FAT_timestamp(file_created_date(get_selected_path())));
|
||||||
on_rename(nav);
|
};
|
||||||
};
|
|
||||||
|
|
||||||
button_delete.on_select = [this, &nav](Button&) {
|
refresh_list();
|
||||||
// Use display_modal ?
|
|
||||||
nav.push<ModalMessageView>("Delete", "Delete " + entry_list[menu_view.highlighted_index()].entry_path.filename().string() + "\nAre you sure?", YESNO,
|
on_select_entry = [this]() {
|
||||||
[this](bool choice) {
|
if (entry_list[menu_view.highlighted_index()].is_directory) {
|
||||||
if (choice)
|
load_directory_contents(get_selected_path());
|
||||||
on_delete();
|
refresh_list();
|
||||||
}
|
} else
|
||||||
);
|
button_rename.focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
button_new_dir.on_select = [this, &nav](Button&) {
|
||||||
|
name_buffer.clear();
|
||||||
|
|
||||||
|
text_prompt(nav, name_buffer, max_filename_length, [this](std::string& buffer) {
|
||||||
|
make_new_directory(current_path.string() + '/' + buffer);
|
||||||
|
load_directory_contents(current_path);
|
||||||
|
refresh_list();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
button_rename.on_select = [this, &nav](Button&) {
|
||||||
|
name_buffer = entry_list[menu_view.highlighted_index()].entry_path.filename().string().substr(0, max_filename_length);
|
||||||
|
on_rename(nav);
|
||||||
|
};
|
||||||
|
|
||||||
|
button_delete.on_select = [this, &nav](Button&) {
|
||||||
|
// Use display_modal ?
|
||||||
|
nav.push<ModalMessageView>("Delete", "Delete " + entry_list[menu_view.highlighted_index()].entry_path.filename().string() + "\nAre you sure?", YESNO,
|
||||||
|
[this](bool choice) {
|
||||||
|
if (choice)
|
||||||
|
on_delete();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user