mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Hide non-linear fragments
Add option to hide (skip) non-linear fragments, only working in 1-page mode. Tweaks mostly to footer, toc and skim code to make it clear(er) which pages belong to linear or non-linear fragments.
This commit is contained in:
@@ -55,7 +55,8 @@ local ReaderRolling = InputContainer:new{
|
||||
-- With visible_pages=2, in 2-pages mode, ensure the first
|
||||
-- page is always odd or even (odd is logical to avoid a
|
||||
-- same page when turning first 2-pages set of document)
|
||||
odd_or_even_first_page = 1 -- 1 = odd, 2 = even, nil or others = free
|
||||
odd_or_even_first_page = 1, -- 1 = odd, 2 = even, nil or others = free
|
||||
hide_nonlinear_flows = nil,
|
||||
}
|
||||
|
||||
function ReaderRolling:init()
|
||||
@@ -206,7 +207,7 @@ function ReaderRolling:onReadSettings(config)
|
||||
self.setupXpointer = function()
|
||||
self.xpointer = self.ui.document:getXPointer()
|
||||
if self.view.view_mode == "page" then
|
||||
self.ui:handleEvent(Event:new("PageUpdate", 1))
|
||||
self.ui:handleEvent(Event:new("PageUpdate", self.ui.document:getNextPage(0)))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -230,6 +231,12 @@ function ReaderRolling:onReadSettings(config)
|
||||
G_reader_settings:readSetting("copt_visible_pages") or 1
|
||||
self.ui.document:setVisiblePageCount(self.visible_pages)
|
||||
|
||||
self.hide_nonlinear_flows = config:readSetting("hide_nonlinear_flows")
|
||||
if self.hide_nonlinear_flows == nil then
|
||||
self.hide_nonlinear_flows = G_reader_settings:isTrue("hide_nonlinear_flows")
|
||||
end
|
||||
self.ui.document:setHideNonlinearFlows(self.hide_nonlinear_flows)
|
||||
|
||||
-- Set a callback to allow showing load and rendering progress
|
||||
-- (this callback will be cleaned up by cre.cpp closeDocument(),
|
||||
-- no need to handle it in :onCloseDocument() here.)
|
||||
@@ -302,10 +309,14 @@ function ReaderRolling:onSaveSettings()
|
||||
self.ui.doc_settings:saveSetting("show_overlap_enable", self.show_overlap_enable)
|
||||
self.ui.doc_settings:saveSetting("inverse_reading_order", self.inverse_reading_order)
|
||||
self.ui.doc_settings:saveSetting("visible_pages", self.visible_pages)
|
||||
self.ui.doc_settings:saveSetting("hide_nonlinear_flows", self.hide_nonlinear_flows)
|
||||
end
|
||||
|
||||
function ReaderRolling:onReaderReady()
|
||||
self:setupTouchZones()
|
||||
if self.hide_nonlinear_flows then
|
||||
self.ui.document:cacheFlows()
|
||||
end
|
||||
self.setupXpointer()
|
||||
end
|
||||
|
||||
@@ -457,6 +468,31 @@ You can set how many lines are shown.]])
|
||||
help_text = _([[When page overlap is enabled, some lines from the previous pages are shown on the next page.]]),
|
||||
sub_item_table = page_overlap_menu,
|
||||
}
|
||||
if self.ui.document:hasNonLinearFlows() then
|
||||
local hide_nonlinear_text = _("When this option is enabled, if a document contains non-linear fragments, they will be hidden from the normal page flow, but they are still accessible through links, Toc or Go to. This currently works only in single-page, non-scrolling mode.")
|
||||
menu_items.hide_nonlinear_flows = {
|
||||
text = _("Hide non-linear fragments"),
|
||||
enabled_func = function()
|
||||
return self.view.view_mode == "page" and self.ui.document:getVisiblePageCount() == 1
|
||||
end,
|
||||
checked_func = function() return self.hide_nonlinear_flows end,
|
||||
callback = function()
|
||||
self:onToggleHideNonlinear()
|
||||
end,
|
||||
hold_callback = function()
|
||||
UIManager:show(ConfirmBox:new{
|
||||
text = T(
|
||||
hide_nonlinear_text .. _("\n\nSet default hide non-linear fragments to %1?"),
|
||||
self.hide_nonlinear_flows and _("enabled") or _("disabled")
|
||||
),
|
||||
ok_callback = function()
|
||||
G_reader_settings:saveSetting("hide_nonlinear_flows", self.hide_nonlinear_flows)
|
||||
end,
|
||||
})
|
||||
end,
|
||||
help_text = hide_nonlinear_text,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function ReaderRolling:getLastPercent()
|
||||
@@ -526,8 +562,18 @@ end
|
||||
function ReaderRolling:onGotoNextChapter()
|
||||
local visible_page_count = self.ui.document:getVisiblePageCount()
|
||||
local pageno = self.current_page + (visible_page_count > 1 and 1 or 0)
|
||||
local new_page = self.ui.toc:getNextChapter(pageno, 0)
|
||||
if new_page then
|
||||
local new_page
|
||||
if self.ui.document:hasHiddenFlows() then
|
||||
-- Find next chapter start
|
||||
new_page = self.ui.document:getNextPage(pageno)
|
||||
while new_page > 0 do
|
||||
if self.ui.toc:isChapterStart(new_page) then break end
|
||||
new_page = self.ui.document:getNextPage(new_page)
|
||||
end
|
||||
else
|
||||
new_page = self.ui.toc:getNextChapter(pageno) or 0
|
||||
end
|
||||
if new_page > 0 then
|
||||
self.ui.link:addCurrentLocationToStack()
|
||||
self:onGotoPage(new_page)
|
||||
end
|
||||
@@ -536,8 +582,18 @@ end
|
||||
|
||||
function ReaderRolling:onGotoPrevChapter()
|
||||
local pageno = self.current_page
|
||||
local new_page = self.ui.toc:getPreviousChapter(pageno, 0)
|
||||
if new_page then
|
||||
local new_page
|
||||
if self.ui.document:hasHiddenFlows() then
|
||||
-- Find previous chapter start
|
||||
new_page = self.ui.document:getPrevPage(pageno)
|
||||
while new_page > 0 do
|
||||
if self.ui.toc:isChapterStart(new_page) then break end
|
||||
new_page = self.ui.document:getPrevPage(new_page)
|
||||
end
|
||||
else
|
||||
new_page = self.ui.toc:getPreviousChapter(pageno) or 0
|
||||
end
|
||||
if new_page > 0 then
|
||||
self.ui.link:addCurrentLocationToStack()
|
||||
self:onGotoPage(new_page)
|
||||
end
|
||||
@@ -721,7 +777,23 @@ function ReaderRolling:onGotoViewRel(diff)
|
||||
else
|
||||
diff = math.floor(diff)
|
||||
end
|
||||
self:_gotoPage(self.current_page + diff*page_count)
|
||||
local new_page = self.current_page
|
||||
if self.ui.document:hasHiddenFlows() then
|
||||
local test_page
|
||||
for i=1, math.abs(diff*page_count) do
|
||||
if diff > 0 then
|
||||
test_page = self.ui.document:getNextPage(new_page)
|
||||
else
|
||||
test_page = self.ui.document:getPrevPage(new_page)
|
||||
end
|
||||
if test_page > 0 then
|
||||
new_page = test_page
|
||||
end
|
||||
end
|
||||
else
|
||||
new_page = new_page + diff*page_count
|
||||
end
|
||||
self:_gotoPage(new_page)
|
||||
if diff > 0 and old_page == self.current_page then
|
||||
self.ui:handleEvent(Event:new("EndOfBook"))
|
||||
end
|
||||
@@ -783,12 +855,13 @@ function ReaderRolling:updatePos()
|
||||
local new_height = self.ui.document.info.doc_height
|
||||
local new_page = self.ui.document.info.number_of_pages
|
||||
if self.old_doc_height ~= new_height or self.old_page ~= new_page then
|
||||
if self.hide_nonlinear_flows then
|
||||
self.ui.document:cacheFlows()
|
||||
end
|
||||
self:_gotoXPointer(self.xpointer)
|
||||
self.old_doc_height = new_height
|
||||
self.old_page = new_page
|
||||
self.ui:handleEvent(Event:new("UpdateToc"))
|
||||
self.view.footer:setTocMarkers(true)
|
||||
self.view.footer:onUpdateFooter()
|
||||
end
|
||||
self:updateTopStatusBarMarkers()
|
||||
UIManager:setDirty(self.view.dialog, "partial")
|
||||
@@ -808,7 +881,6 @@ function ReaderRolling:onChangeViewMode()
|
||||
self.old_doc_height = self.ui.document.info.doc_height
|
||||
self.old_page = self.ui.document.info.number_of_pages
|
||||
self.ui:handleEvent(Event:new("UpdateToc"))
|
||||
self.view.footer:setTocMarkers(true)
|
||||
if self.xpointer then
|
||||
self:_gotoXPointer(self.xpointer)
|
||||
-- Ensure a whole screen refresh is always enqueued
|
||||
@@ -1310,6 +1382,20 @@ Note that %1 (out of %2) xpaths from your bookmarks and highlights have been nor
|
||||
})
|
||||
end
|
||||
|
||||
function ReaderRolling:onToggleHideNonlinear()
|
||||
self.hide_nonlinear_flows = not self.hide_nonlinear_flows
|
||||
self.ui.document:setHideNonlinearFlows(self.hide_nonlinear_flows)
|
||||
-- The document may change due to forced pagebreaks between flows being
|
||||
-- added or removed, so we need to find our location
|
||||
self:onUpdatePos()
|
||||
-- Even if the document doesn't change, we must ensure that the
|
||||
-- flow and call caches are cleared, to get the right page numbers,
|
||||
-- which may have changed, and the correct flow structure. Also,
|
||||
-- the footer needs updating, and TOC markers may come or go.
|
||||
self.ui.document:cacheFlows()
|
||||
self.ui:handleEvent(Event:new("UpdateToc"))
|
||||
end
|
||||
|
||||
-- Duplicated in ReaderPaging
|
||||
function ReaderRolling:onToggleReadingOrder()
|
||||
self.inverse_reading_order = not self.inverse_reading_order
|
||||
|
||||
Reference in New Issue
Block a user