Review comments
This commit is contained in:
@@ -260,8 +260,11 @@ void ActivityManager::goToRecentBooks(int focusIndex) {
|
|||||||
replaceActivity(std::make_unique<RecentBooksActivity>(renderer, mappedInput, focusIndex));
|
replaceActivity(std::make_unique<RecentBooksActivity>(renderer, mappedInput, focusIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActivityManager::goToGlobalBookmarks() {
|
void ActivityManager::goToGlobalBookmarks() { goToGlobalBookmarks({}); }
|
||||||
replaceActivity(std::make_unique<GlobalBookmarksActivity>(renderer, mappedInput));
|
|
||||||
|
void ActivityManager::goToGlobalBookmarks(ReturnHint hint) {
|
||||||
|
hasReturnHint = false;
|
||||||
|
replaceActivity(std::make_unique<GlobalBookmarksActivity>(renderer, mappedInput, std::move(hint)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActivityManager::goToBrowser() {
|
void ActivityManager::goToBrowser() {
|
||||||
@@ -319,6 +322,9 @@ void ActivityManager::returnFromChild() {
|
|||||||
case ReturnTo::RecentBooks:
|
case ReturnTo::RecentBooks:
|
||||||
goToRecentBooks(hint.selectIndex);
|
goToRecentBooks(hint.selectIndex);
|
||||||
break;
|
break;
|
||||||
|
case ReturnTo::GlobalBookmarks:
|
||||||
|
goToGlobalBookmarks(std::move(hint));
|
||||||
|
break;
|
||||||
case ReturnTo::Home:
|
case ReturnTo::Home:
|
||||||
default:
|
default:
|
||||||
goHome(std::move(hint.selectName), hint.selectIndex);
|
goHome(std::move(hint.selectName), hint.selectIndex);
|
||||||
|
|||||||
@@ -17,17 +17,19 @@ class RenderLock; // forward declaration
|
|||||||
|
|
||||||
// Where a "child" activity (launched via one of the replaceWith* helpers) should route
|
// Where a "child" activity (launched via one of the replaceWith* helpers) should route
|
||||||
// control when it exits successfully. See ActivityManager::returnFromChild().
|
// control when it exits successfully. See ActivityManager::returnFromChild().
|
||||||
enum class ReturnTo : uint8_t { Home, FileBrowser, RecentBooks };
|
enum class ReturnTo : uint8_t { Home, FileBrowser, RecentBooks, GlobalBookmarks };
|
||||||
|
|
||||||
// Minimal state the returning parent needs to restore its previous view (directory,
|
// Minimal state the returning parent needs to restore its previous view (directory,
|
||||||
// focused item, list index). Kept as a plain struct stored by value on the
|
// focused item, list index, or bookmark selection). Kept as a plain struct stored by
|
||||||
// ActivityManager — single instance, overwritten per transition, no heap churn
|
// value on the ActivityManager — single instance, overwritten per transition, no heap
|
||||||
// beyond the two small std::strings.
|
// churn beyond the small strings.
|
||||||
struct ReturnHint {
|
struct ReturnHint {
|
||||||
ReturnTo target = ReturnTo::Home;
|
ReturnTo target = ReturnTo::Home;
|
||||||
std::string path; // FileBrowser directory to restore
|
std::string path; // FileBrowser directory to restore
|
||||||
std::string selectName; // item to re-focus in a list (file name, book title)
|
std::string selectName; // item to re-focus in a list (file name, book title)
|
||||||
int selectIndex = -1; // e.g. Recents index
|
int selectIndex = -1; // e.g. Recents index
|
||||||
|
std::string selectionContext; // optional activity-specific restore key
|
||||||
|
int selectBookmarkIndex = -1; // optional bookmark index for GlobalBookmarks
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,9 +85,12 @@ class ActivityManager {
|
|||||||
// into the next one.
|
// into the next one.
|
||||||
bool drainInput = false;
|
bool drainInput = false;
|
||||||
|
|
||||||
// Where returnFromChild() should route to. Set by replaceWith*() helpers, cleared
|
// Where returnFromChild() should route to. Set by replaceWith*() helpers and
|
||||||
// in returnFromChild(). Cleared on any manual goHome()/goTo*() to avoid stale hints
|
// preserved across plain goTo*() chains so a chained navigation flow can still
|
||||||
// outliving the flow they were recorded for.
|
// restore its original parent state. Cleared only by returnFromChild() or by
|
||||||
|
// explicit goHome()/replaceWith*() calls, not by ordinary goTo*() transitions.
|
||||||
|
// Relevant symbols: ReturnHint, returnHint, hasReturnHint, returnFromChild(),
|
||||||
|
// goHome(), goTo*(), replaceWith*().
|
||||||
ReturnHint returnHint;
|
ReturnHint returnHint;
|
||||||
bool hasReturnHint = false;
|
bool hasReturnHint = false;
|
||||||
|
|
||||||
@@ -109,6 +114,7 @@ class ActivityManager {
|
|||||||
void goToFileBrowser(std::string path = {}, std::string focusName = {});
|
void goToFileBrowser(std::string path = {}, std::string focusName = {});
|
||||||
void goToRecentBooks(int focusIndex = -1);
|
void goToRecentBooks(int focusIndex = -1);
|
||||||
void goToGlobalBookmarks();
|
void goToGlobalBookmarks();
|
||||||
|
void goToGlobalBookmarks(ReturnHint hint);
|
||||||
void goToBrowser();
|
void goToBrowser();
|
||||||
void goToReader(std::string path);
|
void goToReader(std::string path);
|
||||||
void goToKOReaderSync();
|
void goToKOReaderSync();
|
||||||
|
|||||||
@@ -323,5 +323,5 @@ void FileBrowserActivity::render(RenderLock&&) {
|
|||||||
size_t FileBrowserActivity::findEntry(const std::string& name) const {
|
size_t FileBrowserActivity::findEntry(const std::string& name) const {
|
||||||
for (size_t i = 0; i < files.size(); i++)
|
for (size_t i = 0; i < files.size(); i++)
|
||||||
if (files[i] == name) return i;
|
if (files[i] == name) return i;
|
||||||
return 0;
|
return files.size();
|
||||||
}
|
}
|
||||||
@@ -27,6 +27,26 @@ void GlobalBookmarksActivity::onEnter() {
|
|||||||
const int first = firstSelectableIndex();
|
const int first = firstSelectableIndex();
|
||||||
selectorIndex = first >= 0 ? first : 0;
|
selectorIndex = first >= 0 ? first : 0;
|
||||||
|
|
||||||
|
if (restoreHint.target == ReturnTo::GlobalBookmarks) {
|
||||||
|
const auto& entries = GLOBAL_BOOKMARKS.getEntries();
|
||||||
|
if (!restoreHint.selectionContext.empty() && restoreHint.selectBookmarkIndex >= 0) {
|
||||||
|
for (size_t i = 0; i < rows.size(); ++i) {
|
||||||
|
const auto& row = rows[i];
|
||||||
|
if (row.isSeparator) continue;
|
||||||
|
if (row.bookmarkIndex == static_cast<size_t>(restoreHint.selectBookmarkIndex) &&
|
||||||
|
row.bookIndex < entries.size() && entries[row.bookIndex].sourcePath == restoreHint.selectionContext) {
|
||||||
|
selectorIndex = static_cast<int>(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (selectorIndex < 0 || selectorIndex >= static_cast<int>(rows.size()) || isSeparatorRow(selectorIndex)) {
|
||||||
|
const int fallback = firstSelectableIndex();
|
||||||
|
selectorIndex = fallback >= 0 ? fallback : 0;
|
||||||
|
}
|
||||||
|
restoreHint = {};
|
||||||
|
}
|
||||||
|
|
||||||
const auto total = static_cast<int>(rows.size());
|
const auto total = static_cast<int>(rows.size());
|
||||||
buttonNavigator.setSelectablePredicate([this](int index) { return !isSeparatorRow(index); }, total);
|
buttonNavigator.setSelectablePredicate([this](int index) { return !isSeparatorRow(index); }, total);
|
||||||
|
|
||||||
@@ -126,8 +146,9 @@ void GlobalBookmarksActivity::openSelected() {
|
|||||||
|
|
||||||
LOG_DBG("GBA", "Jumping to bookmark in %s at %u/%u", entry.sourcePath.c_str(), bm.spineIndex, bm.pageNumber);
|
LOG_DBG("GBA", "Jumping to bookmark in %s at %u/%u", entry.sourcePath.c_str(), bm.spineIndex, bm.pageNumber);
|
||||||
ReturnHint hint;
|
ReturnHint hint;
|
||||||
hint.target = ReturnTo::Home;
|
hint.target = ReturnTo::GlobalBookmarks;
|
||||||
hint.selectName = entry.sourcePath;
|
hint.selectionContext = entry.sourcePath;
|
||||||
|
hint.selectBookmarkIndex = static_cast<int>(row.bookmarkIndex);
|
||||||
activityManager.replaceWithReader(entry.sourcePath, std::move(hint));
|
activityManager.replaceWithReader(entry.sourcePath, std::move(hint));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ struct Rect;
|
|||||||
// header separator or a bookmark entry belonging to the preceding header.
|
// header separator or a bookmark entry belonging to the preceding header.
|
||||||
class GlobalBookmarksActivity final : public Activity {
|
class GlobalBookmarksActivity final : public Activity {
|
||||||
public:
|
public:
|
||||||
explicit GlobalBookmarksActivity(GfxRenderer& renderer, MappedInputManager& mappedInput)
|
explicit GlobalBookmarksActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, ReturnHint restoreHint = {})
|
||||||
: Activity("GlobalBookmarks", renderer, mappedInput) {}
|
: Activity("GlobalBookmarks", renderer, mappedInput), restoreHint(std::move(restoreHint)) {}
|
||||||
|
|
||||||
void onEnter() override;
|
void onEnter() override;
|
||||||
void onExit() override;
|
void onExit() override;
|
||||||
@@ -38,6 +38,7 @@ class GlobalBookmarksActivity final : public Activity {
|
|||||||
ButtonNavigator buttonNavigator;
|
ButtonNavigator buttonNavigator;
|
||||||
std::vector<Row> rows;
|
std::vector<Row> rows;
|
||||||
int selectorIndex = 0;
|
int selectorIndex = 0;
|
||||||
|
ReturnHint restoreHint;
|
||||||
|
|
||||||
void rebuildRows();
|
void rebuildRows();
|
||||||
std::string getRowTitle(int index) const;
|
std::string getRowTitle(int index) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user