BookMap/PageBrowser: update upper instance when leaving lower one

BookMap and PageBrowser instances can be stacked; when
toggling a bookmark in a lower PageBrowser and closing it,
make sure the bookmark is shown in the BookMap we get back to.
Also consider TOC and hidden flows as a thing that can be
edited and needs refreshing, so we're ready for next commits
about custom TOC and custom hidden flows.
Also update Reader footer when closing the last BookMap
or PageBrowser.
reviewable/pr10990/r1
poire-z 7 months ago
parent 2b75ef108e
commit 5406fdf2e0

@ -760,25 +760,11 @@ function BookMapWidget:init()
-- on some events (ie. TocUpdated, PageUpdate, AddHhighlight...)
-- Get some info that shouldn't change across calls to update()
self.nb_pages = self.ui.document:getPageCount()
self.ui.toc:fillToc()
self.cur_page = self.ui.toc.pageno
self.max_toc_depth = self.ui.toc.toc_depth
-- Get bookmarks and highlights from ReaderBookmark
self.bookmarked_pages = self.ui.bookmark:getBookmarkedPages()
-- Get read page from the statistics plugin if enabled
self.statistics_enabled = self.ui.statistics and self.ui.statistics:isEnabled()
self.read_pages = self.ui.statistics and self.ui.statistics:getCurrentBookReadPages()
self.current_session_duration = self.ui.statistics and (os.time() - self.ui.statistics.start_current_period)
-- Hidden flows, for first page display, and to draw them gray
self.has_hidden_flows = self.ui.document:hasHiddenFlows()
if self.has_hidden_flows and #self.ui.document.flows > 0 then
self.hidden_flows = {}
-- Pick into credocument internal data to build a table
-- of {first_page_number, last_page_number) for each flow
for flow, tab in ipairs(self.ui.document.flows) do
table.insert(self.hidden_flows, { tab[1], tab[1]+tab[2]-1 })
end
end
-- Reference page numbers, for first row page display
self.page_labels = nil
if self.ui.pagemap and self.ui.pagemap:wantsPageLabels() then
@ -787,10 +773,39 @@ function BookMapWidget:init()
-- Location stack
self.previous_locations = self.ui.link:getPreviousLocationPages()
-- Update stuff that may be updated by the user while in PageBrowser
self:updateEditableStuff()
self.editable_stuff_edited = false -- reset this
-- Compute settings-dependant sizes and options, and build the inner widgets
self:update()
end
function BookMapWidget:updateEditableStuff(update_view)
-- Toc, bookmarks and hidden flows may be edited
self.ui.toc:fillToc()
self.max_toc_depth = self.ui.toc.toc_depth
-- Get bookmarks and highlights from ReaderBookmark
self.bookmarked_pages = self.ui.bookmark:getBookmarkedPages()
self.hidden_flows = nil
self.has_hidden_flows = self.ui.document:hasHiddenFlows()
if self.has_hidden_flows and #self.ui.document.flows > 0 then
self.hidden_flows = {}
-- Pick into credocument internal data to build a table
-- of {first_page_number, last_page_number) for each flow
for flow, tab in ipairs(self.ui.document.flows) do
table.insert(self.hidden_flows, { tab[1], tab[1]+tab[2]-1 })
end
end
-- Keep a flag so we can propagate the fact that editable stuff
-- has been updated to our parent/launcher when we will close,
-- so they can update themselves too.
self.editable_stuff_edited = true
if update_view then
self:update()
end
end
function BookMapWidget:update()
if not self.focus_page then -- Initial display
-- Focus (show at the middle of screen) on the BookMapRow that contains
@ -1362,6 +1377,9 @@ function BookMapWidget:onClose(close_all_parents)
-- will do the cleanup below.
self.launcher:onClose(true)
else
if self.editable_stuff_edited then
self.launcher:updateEditableStuff(true)
end
UIManager:setDirty(self.launcher, "ui")
end
else
@ -1377,8 +1395,9 @@ function BookMapWidget:onClose(close_all_parents)
collectgarbage()
collectgarbage()
end)
-- As we're getting back to Reader, do a full flashing refresh to remove
-- any ghost trace of thumbnails or black page slots
-- As we're getting back to Reader, update the footer and do a full flashing
-- refresh to remove any ghost trace of thumbnails or black page slots
UIManager:broadcastEvent(Event:new("UpdateFooter"))
UIManager:setDirty(self.ui.dialog, "full")
end
return true

@ -163,25 +163,11 @@ function PageBrowserWidget:init()
self.max_nb_cols = 6
-- Get some info that shouldn't change across calls to update() and updateLayout()
self.ui.toc:fillToc()
self.max_toc_depth = self.ui.toc.toc_depth
self.nb_pages = self.ui.document:getPageCount()
self.cur_page = self.ui.toc.pageno
-- Get bookmarks and highlights from ReaderBookmark
self.bookmarked_pages = self.ui.bookmark:getBookmarkedPages()
-- Get read page from the statistics plugin if enabled
self.read_pages = self.ui.statistics and self.ui.statistics:getCurrentBookReadPages()
self.current_session_duration = self.ui.statistics and (os.time() - self.ui.statistics.start_current_period)
-- Hidden flows, for first page display, and to draw them gray
self.has_hidden_flows = self.ui.document:hasHiddenFlows()
if self.has_hidden_flows and #self.ui.document.flows > 0 then
self.hidden_flows = {}
-- Pick into credocument internal data to build a table
-- of {first_page_number, last_page_number) for each flow
for flow, tab in ipairs(self.ui.document.flows) do
table.insert(self.hidden_flows, { tab[1], tab[1]+tab[2]-1 })
end
end
-- Reference page numbers, for first row page display
self.page_labels = nil
if self.ui.pagemap and self.ui.pagemap:wantsPageLabels() then
@ -190,11 +176,43 @@ function PageBrowserWidget:init()
-- Location stack
self.previous_locations = self.ui.link:getPreviousLocationPages()
-- Update stuff that may be updated by the user while in PageBrowser
self:updateEditableStuff()
self.editable_stuff_edited = false -- reset this
-- Compute settings-dependant sizes and options, and build the inner widgets
-- (this will call self:update())
self:updateLayout()
end
function PageBrowserWidget:updateEditableStuff(update_view)
-- Toc, bookmarks and hidden flows may be edited
-- Note: we update everything to keep things simpler, but we could provide flags to
-- let us know what stuff has been updated and only do their related work.
self.ui.toc:fillToc()
self.max_toc_depth = self.ui.toc.toc_depth
-- Get bookmarks and highlights from ReaderBookmark
self.bookmarked_pages = self.ui.bookmark:getBookmarkedPages()
-- Hidden flows, for first page display, and to draw them gray
self.hidden_flows = nil
self.has_hidden_flows = self.ui.document:hasHiddenFlows()
if self.has_hidden_flows and #self.ui.document.flows > 0 then
self.hidden_flows = {}
-- Pick into credocument internal data to build a table
-- of {first_page_number, last_page_number) for each flow
for flow, tab in ipairs(self.ui.document.flows) do
table.insert(self.hidden_flows, { tab[1], tab[1]+tab[2]-1 })
end
end
-- Keep a flag so we can propagate the fact that editable stuff
-- has been updated to our parent/launcher when we will close,
-- so they can update themselves too.
self.editable_stuff_edited = true
if update_view then
self:updateLayout()
end
end
function PageBrowserWidget:updateLayout()
-- We start with showing all toc levels (we could use book_map_toc_depth,
-- but we might want to have it different here).
@ -1053,6 +1071,9 @@ function PageBrowserWidget:onClose(close_all_parents)
-- will do the cleanup below.
self.launcher:onClose(true)
else
if self.editable_stuff_edited then
self.launcher:updateEditableStuff(true)
end
UIManager:setDirty(self.launcher, "ui")
end
else
@ -1068,8 +1089,9 @@ function PageBrowserWidget:onClose(close_all_parents)
collectgarbage()
collectgarbage()
end)
-- As we're getting back to Reader, do a full flashing refresh to remove
-- any ghost trace of thumbnails or black page slots
-- As we're getting back to Reader, update the footer and do a full flashing
-- refresh to remove any ghost trace of thumbnails or black page slots
UIManager:broadcastEvent(Event:new("UpdateFooter"))
UIManager:setDirty(self.ui.dialog, "full")
end
return true
@ -1468,9 +1490,7 @@ function PageBrowserWidget:onHold(arg, ges)
-- we may get (and cache) a thumbnail showing the wrong
-- bookmark state...
self.ui.bookmark:toggleBookmark(page)
-- Update our cached bookmarks info and ensure the bottom ribbon is redrawn
self.bookmarked_pages = self.ui.bookmark:getBookmarkedPages()
self:updateLayout()
self:updateEditableStuff(true)
return true
end
break

Loading…
Cancel
Save