2
0
mirror of https://github.com/koreader/koreader synced 2024-11-13 19:11:25 +00:00

Merge pull request #698 from houqp/new_ui_houqp

retrive new toc when document is re-formatted
This commit is contained in:
Huang Xin 2013-01-11 08:16:57 -08:00
commit b4bad21535
4 changed files with 41 additions and 13 deletions

View File

@ -104,9 +104,8 @@ function Document:getNativePageDimensions(pageno)
end end
function Document:_readMetadata() function Document:_readMetadata()
if self.info.has_pages then self.info.number_of_pages = self._document:getPages()
self.info.number_of_pages = self._document:getPages() if not self.info.has_pages then
else
self.info.doc_height = self._document:getFullHeight() self.info.doc_height = self._document:getFullHeight()
end end
return true return true

View File

@ -2,6 +2,7 @@ require "ui/reader/readerpanning"
ReaderRolling = InputContainer:new{ ReaderRolling = InputContainer:new{
old_doc_height = nil, old_doc_height = nil,
old_page = nil,
view_mode = "page", view_mode = "page",
current_pos = 0, current_pos = 0,
-- only used for page view mode -- only used for page view mode
@ -85,6 +86,7 @@ function ReaderRolling:init()
self.doc_height = self.ui.document.info.doc_height self.doc_height = self.ui.document.info.doc_height
self.old_doc_height = self.doc_height self.old_doc_height = self.doc_height
self.old_page = self.ui.document.info.number_of_pages
end end
function ReaderRolling:onReadSettings(config) function ReaderRolling:onReadSettings(config)
@ -92,10 +94,21 @@ function ReaderRolling:onReadSettings(config)
if not soe then if not soe then
self.show_overlap_enable = soe self.show_overlap_enable = soe
end end
self:gotoPercent(config:readSetting("last_percent") or 0) -- we read last_percent just for backward compatibility
-- we have to do a real pos change in self.ui.document._document to local last_per = config:readSetting("last_percent")
-- update status information in CREngine. if last_per then
self.ui.document:gotoPos(self.current_pos) self:gotoPercent(last_per)
-- we have to do a real pos change in self.ui.document._document to
-- update status information in CREngine.
self.ui.document:gotoPos(self.current_pos)
end
local last_xp = config:readSetting("last_xpointer")
if last_xp then
self:gotoXPointer(last_xp)
-- we have to do a real jump in self.ui.document._document to
-- update status information in CREngine.
self.ui.document:gotoXPointer(last_xp)
end
if self.view_mode == "page" then if self.view_mode == "page" then
self.ui:handleEvent(Event:new("PageUpdate", self.ui.document:getCurrentPage())) self.ui:handleEvent(Event:new("PageUpdate", self.ui.document:getCurrentPage()))
end end
@ -104,7 +117,9 @@ end
function ReaderRolling:onCloseDocument() function ReaderRolling:onCloseDocument()
local cur_xp = self.ui.document:getXPointer() local cur_xp = self.ui.document:getXPointer()
local cur_pos = self.ui.document:getPosFromXPointer(cur_xp) local cur_pos = self.ui.document:getPosFromXPointer(cur_xp)
self.ui.doc_settings:saveSetting("last_percent", 10000 * cur_pos / self.doc_height) -- remove last_percent config since its deprecated
self.ui.doc_settings:saveSetting("last_percent", nil)
self.ui.doc_settings:saveSetting("last_xpointer", self.ui.document:getXPointer())
self.ui.doc_settings:saveSetting("percent_finished", cur_pos / self.doc_height) self.ui.doc_settings:saveSetting("percent_finished", cur_pos / self.doc_height)
end end
@ -172,9 +187,12 @@ function ReaderRolling:onUpdatePos()
self.ui.document:_readMetadata() self.ui.document:_readMetadata()
-- update self.current_pos if the height of document has been changed. -- update self.current_pos if the height of document has been changed.
local new_height = self.ui.document.info.doc_height local new_height = self.ui.document.info.doc_height
if self.old_doc_height ~= new_height then local new_page = self.ui.document.info.number_of_pages
if self.old_doc_height ~= new_height or self.old_page ~= new_page then
self:gotoXPointer(self.ui.document:getXPointer()) self:gotoXPointer(self.ui.document:getXPointer())
self.old_doc_height = new_height self.old_doc_height = new_height
self.old_page = new_page
self.ui:handleEvent(Event:new("UpdateToc"))
end end
return true return true
end end

View File

@ -1,4 +1,5 @@
ReaderToc = InputContainer:new{ ReaderToc = InputContainer:new{
toc = nil,
toc_menu_title = "Table of contents", toc_menu_title = "Table of contents",
} }
@ -21,6 +22,11 @@ function ReaderToc:onSetDimensions(dimen)
self.dimen = dimen self.dimen = dimen
end end
function ReaderToc:onUpdateToc()
self.toc = nil
return true
end
function ReaderToc:fillToc() function ReaderToc:fillToc()
self.toc = self.ui.document:getToc() self.toc = self.ui.document:getToc()
end end
@ -61,15 +67,19 @@ function ReaderToc:getTocTitleOfCurrentPage()
end end
function ReaderToc:onShowToc() function ReaderToc:onShowToc()
local items = self.ui.document:getToc() if not self.toc then
self:fillToc()
end
-- build menu items -- build menu items
for _,v in ipairs(items) do if self.toc and not self.toc[1].text then
v.text = (" "):rep(v.depth-1)..self:cleanUpTocTitle(v.title) for _,v in ipairs(self.toc) do
v.text = (" "):rep(v.depth-1)..self:cleanUpTocTitle(v.title)
end
end end
local toc_menu = Menu:new{ local toc_menu = Menu:new{
title = "Table of Contents", title = "Table of Contents",
item_table = items, item_table = self.toc,
ui = self.ui, ui = self.ui,
width = Screen:getWidth()-20, width = Screen:getWidth()-20,
height = Screen:getHeight(), height = Screen:getHeight(),

View File

@ -171,6 +171,7 @@ end
function ReaderView:onSetViewMode(new_mode) function ReaderView:onSetViewMode(new_mode)
self.ui.view_mode = new_mode self.ui.view_mode = new_mode
self.ui.document:setViewMode(new_mode) self.ui.document:setViewMode(new_mode)
self.ui:handleEvent(Event:new("UpdatePos"))
return true return true
end end