feat: remember parent folder index in menu when ascending folders

This commit is contained in:
Justin Luque 2026-01-05 20:14:28 -05:00
parent afe9672156
commit 1456cefc1c
No known key found for this signature in database
GPG Key ID: 5D19058FC4BE922F
2 changed files with 13 additions and 1 deletions

View File

@ -29,7 +29,6 @@ void FileSelectionActivity::taskTrampoline(void* param) {
void FileSelectionActivity::loadFiles() {
files.clear();
selectorIndex = 0;
auto root = SdMan.open(basepath.c_str());
if (!root || !root.isDirectory()) {
@ -135,6 +134,11 @@ void FileSelectionActivity::loop() {
basepath.replace(basepath.find_last_of('/'), std::string::npos, "");
if (basepath.empty()) basepath = "/";
loadFiles();
auto pos = oldPath.find_last_of('/');
std::string dirName = oldPath.substr(pos + 1) + "/";
selectorIndex = findEntry(dirName);
updateRequired = true;
} else {
onGoHome();
@ -194,3 +198,10 @@ void FileSelectionActivity::render() const {
renderer.displayBuffer();
}
int FileSelectionActivity::findEntry(const std::string& name) const {
for (size_t i = 0; i < files.size(); i++)
if (files[i] == name)
return i;
return 0;
}

View File

@ -23,6 +23,7 @@ class FileSelectionActivity final : public Activity {
[[noreturn]] void displayTaskLoop();
void render() const;
void loadFiles();
int findEntry(const std::string& name) const;
public:
explicit FileSelectionActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,