mirror of
https://github.com/koreader/koreader
synced 2024-11-10 01:10:34 +00:00
Annotations: fix page numbers (#12324)
This commit is contained in:
parent
f3c0af49c2
commit
27e2efcbd2
@ -299,7 +299,7 @@ function FileManager:setupLayout()
|
||||
file_manager:showOpenWithDialog(file)
|
||||
end,
|
||||
},
|
||||
filemanagerutil.genBookInformationButton(doc_settings_or_file or file, self.book_props, close_dialog_callback),
|
||||
filemanagerutil.genBookInformationButton(doc_settings_or_file, self.book_props, close_dialog_callback),
|
||||
})
|
||||
if has_provider then
|
||||
table.insert(buttons, {
|
||||
|
@ -25,12 +25,8 @@ function ReaderAnnotation:buildAnnotation(bm, highlights, init)
|
||||
if chapter == nil then
|
||||
chapter = self.ui.toc:getTocTitleByPage(bm.page)
|
||||
end
|
||||
if self.ui.rolling then
|
||||
pageno = self.document:getPageFromXPointer(bm.page)
|
||||
pageref = self:getPageRef(bm.page, pageno)
|
||||
else
|
||||
pageno = bm.page
|
||||
end
|
||||
pageno = self.ui.rolling and self.document:getPageFromXPointer(bm.page) or bm.page
|
||||
pageref = self:getPageRef(bm.page, pageno)
|
||||
end
|
||||
if self.ui.paging and bm.pos0 and not bm.pos0.page then
|
||||
-- old single-page reflow highlights do not have page in position
|
||||
@ -120,13 +116,9 @@ function ReaderAnnotation:onReadSettings(config)
|
||||
end
|
||||
self.annotations = annotations
|
||||
if needs_update or needs_sort then
|
||||
if self.ui.rolling then
|
||||
self.ui:registerPostInitCallback(function()
|
||||
self:updateAnnotations(needs_update, needs_sort)
|
||||
end)
|
||||
else
|
||||
self.ui:registerPostReaderReadyCallback(function()
|
||||
self:updateAnnotations(needs_update, needs_sort)
|
||||
end
|
||||
end)
|
||||
config:delSetting("annotations_externally_modified")
|
||||
end
|
||||
else -- first run
|
||||
@ -219,10 +211,12 @@ function ReaderAnnotation:migrateToAnnotations(config)
|
||||
self.annotations = self:getAnnotationsFromBookmarksHighlights(bookmarks, highlights, true)
|
||||
end
|
||||
|
||||
function ReaderAnnotation:onDocumentRerendered()
|
||||
function ReaderAnnotation:setNeedsUpdateFlag()
|
||||
self.needs_update = true
|
||||
end
|
||||
|
||||
ReaderAnnotation.onDocumentRerendered = ReaderAnnotation.setNeedsUpdateFlag
|
||||
|
||||
function ReaderAnnotation:onCloseDocument()
|
||||
self:updatePageNumbers()
|
||||
end
|
||||
@ -235,10 +229,9 @@ end
|
||||
-- items handling
|
||||
|
||||
function ReaderAnnotation:updatePageNumbers(force_update)
|
||||
if self.ui.paging then return end
|
||||
if force_update or self.needs_update then -- triggered by ReaderRolling on document layout change
|
||||
if force_update or self.needs_update then
|
||||
for _, item in ipairs(self.annotations) do
|
||||
item.pageno = self.document:getPageFromXPointer(item.page)
|
||||
item.pageno = self.ui.rolling and self.document:getPageFromXPointer(item.page) or item.page
|
||||
item.pageref = self:getPageRef(item.page, item.pageno)
|
||||
end
|
||||
end
|
||||
@ -405,12 +398,8 @@ end
|
||||
|
||||
function ReaderAnnotation:addItem(item)
|
||||
item.datetime = os.date("%Y-%m-%d %H:%M:%S")
|
||||
if self.ui.rolling then
|
||||
item.pageno = self.document:getPageFromXPointer(item.page)
|
||||
item.pageref = self:getPageRef(item.page, item.pageno)
|
||||
else
|
||||
item.pageno = item.page
|
||||
end
|
||||
item.pageno = self.ui.rolling and self.document:getPageFromXPointer(item.page) or item.page
|
||||
item.pageref = self:getPageRef(item.page, item.pageno)
|
||||
local index = self:getInsertionIndex(item)
|
||||
table.insert(self.annotations, index, item)
|
||||
return index
|
||||
@ -418,18 +407,21 @@ end
|
||||
|
||||
-- info
|
||||
|
||||
function ReaderAnnotation:getPageRef(xp, pn) -- same as ReaderBookmark:getBookmarkPageString()
|
||||
local pageref
|
||||
if self.ui.pagemap:wantsPageLabels() then
|
||||
pageref = self.ui.pagemap:getXPointerPageLabel(xp, true)
|
||||
elseif self.ui.document:hasHiddenFlows() then
|
||||
pageref = tostring(self.ui.document:getPageNumberInFlow(pn))
|
||||
local flow = self.ui.document:getPageFlow(pn)
|
||||
if flow > 0 then
|
||||
pageref = T("[%1]%2", pageref, flow)
|
||||
end
|
||||
function ReaderAnnotation:getPageRef(pn_or_xp, pn)
|
||||
-- same as ReaderBookmark:getBookmarkPageString(page)
|
||||
-- but gets pn (page number already calculated in the caller)
|
||||
-- and returns nil if there are no reference pages and hidden flows
|
||||
if self.ui.pagemap and self.ui.pagemap:wantsPageLabels() then
|
||||
return self.ui.pagemap:getXPointerPageLabel(pn_or_xp, true)
|
||||
end
|
||||
if self.document:hasHiddenFlows() then
|
||||
local page = self.document:getPageNumberInFlow(pn)
|
||||
local flow = self.document:getPageFlow(pn)
|
||||
if flow > 0 then
|
||||
return T("[%1]%2", page, flow)
|
||||
end
|
||||
return tostring(page)
|
||||
end
|
||||
return pageref
|
||||
end
|
||||
|
||||
function ReaderAnnotation:hasAnnotations()
|
||||
|
@ -586,16 +586,15 @@ end
|
||||
function ReaderBookmark:getBookmarkPageString(page)
|
||||
if self.ui.rolling then
|
||||
if self.ui.pagemap and self.ui.pagemap:wantsPageLabels() then
|
||||
page = self.ui.pagemap:getXPointerPageLabel(page, true)
|
||||
else
|
||||
page = self.ui.document:getPageFromXPointer(page)
|
||||
if self.ui.document:hasHiddenFlows() then
|
||||
local flow = self.ui.document:getPageFlow(page)
|
||||
page = self.ui.document:getPageNumberInFlow(page)
|
||||
if flow > 0 then
|
||||
page = T("[%1]%2", page, flow)
|
||||
end
|
||||
end
|
||||
return self.ui.pagemap:getXPointerPageLabel(page, true)
|
||||
end
|
||||
page = self.ui.document:getPageFromXPointer(page)
|
||||
end
|
||||
if self.ui.document:hasHiddenFlows() then
|
||||
local flow = self.ui.document:getPageFlow(page)
|
||||
page = self.ui.document:getPageNumberInFlow(page)
|
||||
if flow > 0 then
|
||||
page = T("[%1]%2", page, flow)
|
||||
end
|
||||
end
|
||||
return tostring(page)
|
||||
|
@ -117,6 +117,7 @@ function ReaderHandMade:onToggleHandmadeFlows()
|
||||
self:setupFlows()
|
||||
-- Have footer updated, so we may see this took effect
|
||||
self.view.footer:onUpdateFooter(self.view.footer_visible)
|
||||
self.ui.annotation:setNeedsUpdateFlag()
|
||||
end
|
||||
|
||||
function ReaderHandMade:addToMainMenu(menu_items)
|
||||
@ -259,6 +260,7 @@ Hidden flows are shown with gray or hatched background in Book map and Page brow
|
||||
self.ui:handleEvent(Event:new("InitScrollPageStates"))
|
||||
-- The footer may be visible, so have it update its dependant items
|
||||
self.view.footer:onUpdateFooter(self.view.footer_visible)
|
||||
self.ui.annotation:setNeedsUpdateFlag()
|
||||
if touchmenu_instance then
|
||||
touchmenu_instance:updateItems()
|
||||
end
|
||||
@ -282,6 +284,7 @@ Hidden flows are shown with gray or hatched background in Book map and Page brow
|
||||
self.ui:handleEvent(Event:new("InitScrollPageStates"))
|
||||
-- The footer may be visible, so have it update its dependant items
|
||||
self.view.footer:onUpdateFooter(self.view.footer_visible)
|
||||
self.ui.annotation:setNeedsUpdateFlag()
|
||||
if touchmenu_instance then
|
||||
touchmenu_instance:updateItems()
|
||||
end
|
||||
@ -552,6 +555,7 @@ function ReaderHandMade:isInHiddenFlow(pageno)
|
||||
end
|
||||
|
||||
function ReaderHandMade:toggleHiddenFlow(pageno)
|
||||
self.ui.annotation:setNeedsUpdateFlag()
|
||||
local idx, is_match = self:_getItemIndex(self.flow_points, pageno)
|
||||
if is_match then
|
||||
-- Just remove the item (it feels we can, and that we don't
|
||||
|
@ -1030,6 +1030,8 @@ function ReaderRolling:updatePos(force)
|
||||
if self.ui.document:isRerenderingDelayed(true) then
|
||||
-- Partial rerendering is enabled, rerendering is delayed
|
||||
logger.dbg(" but rendering delayed, will do partial renderings on draw")
|
||||
-- annotation page numbers must be updated after self.ui:reloadDocument()
|
||||
self.ui.doc_settings:makeTrue("annotations_externally_modified")
|
||||
self:handleRenderingDelayed()
|
||||
return
|
||||
end
|
||||
|
@ -645,14 +645,8 @@ function ReaderSearch:onShowFindAllResults(not_cached)
|
||||
table.insert(text, item.next_text) -- append context after the word
|
||||
item.text = table.concat(text)
|
||||
|
||||
local pageno, pageref
|
||||
if self.ui.rolling then
|
||||
pageno = self.ui.document:getPageFromXPointer(item.start)
|
||||
pageref = self.ui.annotation:getPageRef(item.start, pageno)
|
||||
else
|
||||
pageno = item.start
|
||||
end
|
||||
item.mandatory = pageref or pageno
|
||||
local pageno = self.ui.rolling and self.ui.document:getPageFromXPointer(item.start) or item.start
|
||||
item.mandatory = self.ui.annotation:getPageRef(item.start, pageno) or pageno
|
||||
item.mandatory_dim_func = function()
|
||||
return pageno > self.ui:getCurrentPage()
|
||||
end
|
||||
@ -743,12 +737,9 @@ function ReaderSearch:showAllResultsMenuDialog()
|
||||
{
|
||||
{
|
||||
text_func = function()
|
||||
local current_page = self.ui:getCurrentPage()
|
||||
if self.ui.rolling then
|
||||
local current_xp = self.ui.rolling:getLastProgress()
|
||||
current_page = self.ui.annotation:getPageRef(current_xp, current_page) or current_page
|
||||
end
|
||||
return T(_("Current page: %1"), current_page)
|
||||
local pn = self.ui:getCurrentPage()
|
||||
local pn_or_xp = self.ui.rolling and self.ui.rolling:getLastProgress() or pn
|
||||
return T(_("Current page: %1"), self.ui.annotation:getPageRef(pn_or_xp, pn) or pn)
|
||||
end,
|
||||
callback = function()
|
||||
UIManager:close(button_dialog)
|
||||
|
Loading…
Reference in New Issue
Block a user