From 8b1605bb49a4ea4312bb9c9c1299c039c8a26943 Mon Sep 17 00:00:00 2001 From: jonnyl2 <95502269+jonnyl2@users.noreply.github.com> Date: Wed, 30 Apr 2025 08:16:45 +0000 Subject: [PATCH] Minor changes to PageBrowser/BookMap/ReaderHandmade (#13691) ReaderHandmade new features: Long-press to bypass input dialog for adding custom TOC chapters via highlight dialog in Reader. Custom TOC input dialog initial cursor position in front of text (for new chapter entries and 'Use selected text' option): facilitating input of chapter number. Book map new features: Separate 'Page browser on tap' setting for overview mode. Larger page-slot width adjustment via long-press on -/+. Page browser new features: Adjust 2 lines/columns at once via long-press on -/+. Add unnamed Custom TOC chapters bypassing input dialog via long-press on 'Start TOC chapter here'. readerthumbnail.lua: Fix reader menu staying open on Book map (overview) launch. --- .../apps/reader/modules/readerhandmade.lua | 26 +++++++++++++++-- .../apps/reader/modules/readerthumbnail.lua | 1 + frontend/ui/widget/bookmapwidget.lua | 24 ++++++++++++++-- frontend/ui/widget/pagebrowserwidget.lua | 28 +++++++++++++++++-- 4 files changed, 71 insertions(+), 8 deletions(-) diff --git a/frontend/apps/reader/modules/readerhandmade.lua b/frontend/apps/reader/modules/readerhandmade.lua index 19241795b..34675937f 100644 --- a/frontend/apps/reader/modules/readerhandmade.lua +++ b/frontend/apps/reader/modules/readerhandmade.lua @@ -404,6 +404,11 @@ function ReaderHandMade:updateHighlightDialog() this:onClose() self:addOrEditPageTocItem(nil, nil, selected_text) end, + hold_callback = function() -- no dialog: directly creates new TOC item with selection (if none existing) + local selected_text = this.selected_text + this:onClose() + self:addOrEditPageTocItem(nil, nil, selected_text, true) + end, } end) else @@ -454,7 +459,7 @@ function ReaderHandMade:hasPageTocItem(pageno, xpointer) return is_match end -function ReaderHandMade:addOrEditPageTocItem(pageno, when_updated_callback, selected_text) +function ReaderHandMade:addOrEditPageTocItem(pageno, when_updated_callback, selected_text, no_dialog) local xpointer, title if selected_text then -- If we get selected_text, it's from the highlight dialog after text selection @@ -484,12 +489,29 @@ function ReaderHandMade:addOrEditPageTocItem(pageno, when_updated_callback, sele depth = 1, -- we only support 1-level chapters to keep the UX simple } end + if no_dialog then + if item_found then return true end -- no changes if existing TOC entry + if selected_text then -- via highlight dialog + item.title = selected_text.text + table.insert(self.toc, idx, item) + self.ui:handleEvent(Event:new("UpdateToc")) + else -- via Page browser + item.title = "" + table.insert(self.toc, idx, item) + self.ui:handleEvent(Event:new("UpdateToc")) + if when_updated_callback then + when_updated_callback() + end + end + return true + end local dialog dialog = InputDialog:new{ title = item_found and _("Edit custom TOC chapter") or _("Create new custom ToC chapter"), input = item.title, input_hint = _("TOC chapter title"), description = T(_([[On page %1.]]), pageno), + cursor_at_end = item_found and true or false, -- cursor at start for new entries for easy manual addition of chapter number buttons = { { { @@ -532,7 +554,7 @@ function ReaderHandMade:addOrEditPageTocItem(pageno, when_updated_callback, sele text = _("Use selected text"), callback = function() -- Just replace the text without saving, to allow editing/fixing it - dialog:setInputText(selected_text.text, nil, false) + dialog:setInputText(selected_text.text, nil, true) end, } or nil, } or nil, diff --git a/frontend/apps/reader/modules/readerthumbnail.lua b/frontend/apps/reader/modules/readerthumbnail.lua index f94590ee9..9e21b7bc9 100644 --- a/frontend/apps/reader/modules/readerthumbnail.lua +++ b/frontend/apps/reader/modules/readerthumbnail.lua @@ -83,6 +83,7 @@ function ReaderThumbnail:addToMainMenu(menu_items) -- Show the alternative overview mode (which is just a restricted -- variation of the main book map) with long-press (let's avoid -- adding another item in the crowded first menu). + hold_keep_menu_open = false, hold_callback = function() self:onShowBookMap(true) end, diff --git a/frontend/ui/widget/bookmapwidget.lua b/frontend/ui/widget/bookmapwidget.lua index 99d6c7305..8e8c3ee7c 100644 --- a/frontend/ui/widget/bookmapwidget.lua +++ b/frontend/ui/widget/bookmapwidget.lua @@ -1332,11 +1332,19 @@ function BookMapWidget:onShowBookMapMenu() {{ text = _("Page browser on tap"), checked_func = function() - return G_reader_settings:nilOrTrue("book_map_tap_to_page_browser") + if self.overview_mode then + return G_reader_settings:nilOrTrue("book_map_overview_tap_to_page_browser") + else + return G_reader_settings:nilOrTrue("book_map_tap_to_page_browser") + end end, align = "left", callback = function() - G_reader_settings:flipNilOrTrue("book_map_tap_to_page_browser") + if self.overview_mode then + return G_reader_settings:flipNilOrTrue("book_map_overview_tap_to_page_browser") + else + return G_reader_settings:flipNilOrTrue("book_map_tap_to_page_browser") + end end, }}, {{ @@ -1412,6 +1420,11 @@ function BookMapWidget:onShowBookMapMenu() self:update() end end, + hold_callback = function() + if self:updatePagesPerRow(50, true) then + self:update() + end + end, width = plus_minus_width, }, { @@ -1422,6 +1435,11 @@ function BookMapWidget:onShowBookMapMenu() self:update() end end, + hold_callback = function() + if self:updatePagesPerRow(-50, true) then + self:update() + end + end, width = plus_minus_width, } }, @@ -1905,7 +1923,7 @@ function BookMapWidget:onTap(arg, ges) page = row:getPageAtX(x, true) end if page then - if not G_reader_settings:nilOrTrue("book_map_tap_to_page_browser") then + if (self.overview_mode and G_reader_settings:isFalse("book_map_overview_tap_to_page_browser")) or (not self.overview_mode and G_reader_settings:isFalse("book_map_tap_to_page_browser")) then self:onClose(true) self.ui.link:addCurrentLocationToStack() self.ui:handleEvent(Event:new("GotoPage", page)) diff --git a/frontend/ui/widget/pagebrowserwidget.lua b/frontend/ui/widget/pagebrowserwidget.lua index c1ea3f996..cf99e936d 100644 --- a/frontend/ui/widget/pagebrowserwidget.lua +++ b/frontend/ui/widget/pagebrowserwidget.lua @@ -1010,6 +1010,11 @@ function PageBrowserWidget:onShowMenu() self:updateLayout() end end, + hold_callback = function() + if self:updateNbCols(-2, true) then + self:updateLayout() + end + end, width = plus_minus_width, }, { @@ -1020,6 +1025,11 @@ function PageBrowserWidget:onShowMenu() self:updateLayout() end end, + hold_callback = function() + if self:updateNbCols(2, true) then + self:updateLayout() + end + end, width = plus_minus_width, } }, @@ -1037,6 +1047,11 @@ function PageBrowserWidget:onShowMenu() self:updateLayout() end end, + hold_callback = function() + if self:updateNbRows(-2, true) then + self:updateLayout() + end + end, width = plus_minus_width, }, { @@ -1047,6 +1062,11 @@ function PageBrowserWidget:onShowMenu() self:updateLayout() end end, + hold_callback = function() + if self:updateNbRows(2, true) then + self:updateLayout() + end + end, width = plus_minus_width, } }, @@ -1730,9 +1750,11 @@ function PageBrowserWidget:onThumbnailHold(page, ges) align = "left", callback = function() UIManager:close(button_dialog) - self.ui.handmade:addOrEditPageTocItem(page, function() - self:updateEditableStuff(true) - end) + self.ui.handmade:addOrEditPageTocItem(page, function() self:updateEditableStuff(true) end) + end, + hold_callback = function() -- no dialog: adds empty TOC item if none existing + UIManager:close(button_dialog) + self.ui.handmade:addOrEditPageTocItem(page, function() self:updateEditableStuff(true) end, nil, true) end, }}) end