mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 06:37:38 +03:00
feat: remember parent folder index in menu when ascending folders (#260)
## Summary Adds feature to file selection activity for better user navigation when ascending folders. The activity now remembers the index of the parent folder instead of always resetting to the first element. I don't have any means of testing this, so if someone could test it that'd be great Resolves #259
This commit is contained in:
parent
b792b792bf
commit
0edb2baced
@ -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()) {
|
||||
@ -132,9 +131,16 @@ void FileSelectionActivity::loop() {
|
||||
// Short press: go up one directory, or go home if at root
|
||||
if (mappedInput.getHeldTime() < GO_HOME_MS) {
|
||||
if (basepath != "/") {
|
||||
const std::string oldPath = basepath;
|
||||
|
||||
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 +200,9 @@ 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;
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user