feat: Add dictionary word lookup feature with cached index
Implements StarDict-based dictionary lookup from the reader menu, adapted from upstream PR #857 with /.dictionary/ folder path, std::vector compatibility (PR #802), HTML definition rendering, orientation-aware button hints, side button hints with CCW text rotation, sparse index caching to SD card, pronunciation line filtering, and reorganized reader menu with bookmark stubs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -14,13 +14,27 @@
|
||||
class EpubReaderMenuActivity final : public ActivityWithSubactivity {
|
||||
public:
|
||||
// Menu actions available from the reader menu.
|
||||
enum class MenuAction { SELECT_CHAPTER, GO_TO_PERCENT, ROTATE_SCREEN, GO_HOME, SYNC, DELETE_CACHE };
|
||||
enum class MenuAction {
|
||||
ADD_BOOKMARK,
|
||||
LOOKUP,
|
||||
LOOKED_UP_WORDS,
|
||||
ROTATE_SCREEN,
|
||||
SELECT_CHAPTER,
|
||||
GO_TO_BOOKMARK,
|
||||
GO_TO_PERCENT,
|
||||
GO_HOME,
|
||||
SYNC,
|
||||
DELETE_CACHE,
|
||||
DELETE_DICT_CACHE
|
||||
};
|
||||
|
||||
explicit EpubReaderMenuActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, const std::string& title,
|
||||
const int currentPage, const int totalPages, const int bookProgressPercent,
|
||||
const uint8_t currentOrientation, const std::function<void(uint8_t)>& onBack,
|
||||
const uint8_t currentOrientation, const bool hasDictionary,
|
||||
const std::function<void(uint8_t)>& onBack,
|
||||
const std::function<void(MenuAction)>& onAction)
|
||||
: ActivityWithSubactivity("EpubReaderMenu", renderer, mappedInput),
|
||||
menuItems(buildMenuItems(hasDictionary)),
|
||||
title(title),
|
||||
pendingOrientation(currentOrientation),
|
||||
currentPage(currentPage),
|
||||
@@ -39,11 +53,7 @@ class EpubReaderMenuActivity final : public ActivityWithSubactivity {
|
||||
std::string label;
|
||||
};
|
||||
|
||||
// Fixed menu layout (order matters for up/down navigation).
|
||||
const std::vector<MenuItem> menuItems = {
|
||||
{MenuAction::SELECT_CHAPTER, "Go to Chapter"}, {MenuAction::ROTATE_SCREEN, "Reading Orientation"},
|
||||
{MenuAction::GO_TO_PERCENT, "Go to %"}, {MenuAction::GO_HOME, "Go Home"},
|
||||
{MenuAction::SYNC, "Sync Progress"}, {MenuAction::DELETE_CACHE, "Delete Book Cache"}};
|
||||
std::vector<MenuItem> menuItems;
|
||||
|
||||
int selectedIndex = 0;
|
||||
bool updateRequired = false;
|
||||
@@ -60,6 +70,26 @@ class EpubReaderMenuActivity final : public ActivityWithSubactivity {
|
||||
const std::function<void(uint8_t)> onBack;
|
||||
const std::function<void(MenuAction)> onAction;
|
||||
|
||||
static std::vector<MenuItem> buildMenuItems(bool hasDictionary) {
|
||||
std::vector<MenuItem> items;
|
||||
items.push_back({MenuAction::ADD_BOOKMARK, "Add Bookmark"});
|
||||
if (hasDictionary) {
|
||||
items.push_back({MenuAction::LOOKUP, "Lookup Word"});
|
||||
items.push_back({MenuAction::LOOKED_UP_WORDS, "Lookup Word History"});
|
||||
}
|
||||
items.push_back({MenuAction::ROTATE_SCREEN, "Reading Orientation"});
|
||||
items.push_back({MenuAction::SELECT_CHAPTER, "Table of Contents"});
|
||||
items.push_back({MenuAction::GO_TO_BOOKMARK, "Go to Bookmark"});
|
||||
items.push_back({MenuAction::GO_TO_PERCENT, "Go to %"});
|
||||
items.push_back({MenuAction::GO_HOME, "Close Book"});
|
||||
items.push_back({MenuAction::SYNC, "Sync Progress"});
|
||||
items.push_back({MenuAction::DELETE_CACHE, "Delete Book Cache"});
|
||||
if (hasDictionary) {
|
||||
items.push_back({MenuAction::DELETE_DICT_CACHE, "Delete Dictionary Cache"});
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
static void taskTrampoline(void* param);
|
||||
[[noreturn]] void displayTaskLoop();
|
||||
void renderScreen();
|
||||
|
||||
Reference in New Issue
Block a user