move toc related methods to readertoc.lua

pull/2/merge
Qingping Hou 12 years ago
parent cf048e286d
commit a1a9b5e9b0

@ -3,6 +3,7 @@ ReaderToc = InputContainer:new{
ShowToc = { {"T"}, doc = "show Table of Content menu"},
},
dimen = Geom:new{ w = G_width-20, h = G_height-20},
current_page = 0,
}
function ReaderToc:cleanUpTocTitle(title)
@ -13,6 +14,41 @@ function ReaderToc:onSetDimensions(dimen)
self.dimen = dimen
end
--function ReaderToc:fillToc()
--self.toc = self.doc:getToc()
--end
-- getTocTitleByPage wrapper, so specific reader
-- can tranform pageno according its need
function ReaderToc:getTocTitleByPage(pageno)
return self:_getTocTitleByPage(pageno)
end
function ReaderToc:_getTocTitleByPage(pageno)
if not self.toc then
-- build toc when needed.
self:fillToc()
end
-- no table of content
if #self.toc == 0 then
return ""
end
local pre_entry = self.toc[1]
for _k,_v in ipairs(self.toc) do
if _v.page > pageno then
break
end
pre_entry = _v
end
return self:cleanUpTocTitle(pre_entry.title)
end
function ReaderToc:getTocTitleOfCurrentPage()
return self:getTocTitleByPage(self.pageno)
end
function ReaderToc:onShowToc()
function callback(item)
self.ui:handleEvent(Event:new("PageUpdate", item.page))
@ -34,3 +70,8 @@ function ReaderToc:onShowToc()
UIManager:show(toc_menu)
end
function ReaderToc:onPageUpdate(new_page_no)
self.current_page = new_page_no
end

Loading…
Cancel
Save