Merge pull request #1825 from koreader/houqp-master

fix #1796
pull/1828/head
Huang Xin 8 years ago
commit 37a0765897

@ -20,6 +20,40 @@ function FileManagerHistory:init()
self.ui.menu:registerToMainMenu(self)
end
function FileManagerHistory:addToMainMenu(tab_item_table)
-- insert table to info tab of filemanager menu
table.insert(tab_item_table.info, {
text = self.hist_menu_title,
callback = function()
self:onShowHist()
end,
})
end
function FileManagerHistory:updateItemTable()
local ReaderUI = require("apps/reader/readerui")
self.hist = {}
for f in lfs.dir(history_dir) do
local path = joinPath(history_dir, f)
if lfs.attributes(path, "mode") == "file" then
local name = DocSettings:getNameFromHistory(f)
table.insert(self.hist, {
date = lfs.attributes(path, "modification"),
text = name,
histfile = f,
callback = function()
ReaderUI:showReader(
DocSettings:getPathFromHistory(f).. "/" .. name)
end
})
end
end
table.sort(self.hist, function(v1, v2) return v1.date > v2.date end)
self.hist_menu:swithItemTable(self.hist_menu_title, self.hist)
end
function FileManagerHistory:onSetDimensions(dimen)
self.dimen = dimen
end
@ -68,38 +102,4 @@ function FileManagerHistory:onShowHist()
return true
end
function FileManagerHistory:addToMainMenu(tab_item_table)
-- insert table to info tab of filemanager menu
table.insert(tab_item_table.info, {
text = self.hist_menu_title,
callback = function()
self:onShowHist()
end,
})
end
function FileManagerHistory:updateItemTable()
local ReaderUI = require("apps/reader/readerui")
self.hist = {}
for f in lfs.dir(history_dir) do
local path = joinPath(history_dir, f)
if lfs.attributes(path, "mode") == "file" then
local name = DocSettings:getNameFromHistory(f)
table.insert(self.hist, {
date = lfs.attributes(path, "modification"),
text = name,
histfile = f,
callback = function()
ReaderUI:showReader(
DocSettings:getPathFromHistory(f).. "/" .. name)
end
})
end
end
table.sort(self.hist, function(v1, v2) return v1.date > v2.date end)
self.hist_menu:swithItemTable(self.hist_menu_title, self.hist)
end
return FileManagerHistory

@ -16,18 +16,18 @@ local ReaderMenu = InputContainer:new{
function ReaderMenu:init()
self.tab_item_table = {
setting = {
icon = "resources/icons/appbar.settings.png",
},
navi = {
icon = "resources/icons/appbar.page.corner.bookmark.png",
},
info = {
icon = "resources/icons/appbar.pokeball.png",
},
typeset = {
icon = "resources/icons/appbar.page.text.png",
},
setting = {
icon = "resources/icons/appbar.settings.png",
},
info = {
icon = "resources/icons/appbar.pokeball.png",
},
plugins = {
icon = "resources/icons/appbar.tools.png",
},

@ -77,6 +77,9 @@ function ReaderView:init()
self.ui:registerPostInitCallback(function()
self.ui.menu:registerToMainMenu(self.footer)
end)
self.emitHintPageEvent = function()
self.ui:handleEvent(Event:new("HintPage", self.hinting))
end
end
function ReaderView:resetDimArea()
@ -273,9 +276,7 @@ function ReaderView:drawScrollPages(bb, x, y)
pos.y = pos.y + self.page_gap.height
end
end
UIManager:scheduleIn(0, function()
self.ui:handleEvent(Event:new("HintPage", self.hinting))
end)
UIManager:nextTick(self.emitHintPageEvent)
end
function ReaderView:getCurrentPageList()
@ -347,9 +348,7 @@ function ReaderView:drawSinglePage(bb, x, y)
self.state.rotation,
self.state.gamma,
self.render_mode)
UIManager:scheduleIn(0, function()
self.ui:handleEvent(Event:new("HintPage", self.hinting))
end)
UIManager:nextTick(self.emitHintPageEvent)
end
function ReaderView:getSinglePagePosition(pos)
@ -748,4 +747,10 @@ function ReaderView:genOverlapStyleMenu()
}
end
function ReaderView:onCloseDocument()
self.hinting = false
-- stop any in fly HintPage event
UIManager:unschedule(self.emitHintPageEvent)
end
return ReaderView

@ -390,6 +390,10 @@ function ReaderUI:doShowReader(file)
running_instance = reader
end
function ReaderUI:_getRunningInstance()
return running_instance
end
function ReaderUI:unlockDocumentWithPassword(document, try_again)
DEBUG("show input password dialog")
self.password_dialog = InputDialog:new{
@ -488,7 +492,9 @@ function ReaderUI:onClose()
UIManager:close(self.dialog, "full")
-- serialize last used items for later launch
Cache:serialize()
running_instance = nil
if running_instance == self then
running_instance = nil
end
return true
end

@ -198,6 +198,10 @@ function UIManager:scheduleIn(seconds, action)
self:schedule(when, action)
end
function UIManager:nextTick(action)
return self:scheduleIn(0, action)
end
-- unschedule an execution task
-- in order to unschedule anonymous functions, store a reference
-- for example:

@ -34,4 +34,14 @@ describe("Readerui module", function()
readerui:closeDocument()
assert(readerui.document == nil)
end)
it("should not reset running_instance by mistake", function()
ReaderUI:doShowReader(sample_epub)
local new_readerui = ReaderUI:_getRunningInstance()
assert.is.truthy(new_readerui.document)
ReaderUI:new{
document = DocumentRegistry:openDocument(sample_epub)
}:onClose()
assert.is.truthy(new_readerui.document)
new_readerui:onClose()
end)
end)

@ -0,0 +1,42 @@
require("commonrequire")
local DocumentRegistry = require("document/documentregistry")
local Blitbuffer = require("ffi/blitbuffer")
local ReaderUI = require("apps/reader/readerui")
local UIManager = require("ui/uimanager")
describe("Readerview module", function()
it("should stop hinting on document close event", function()
local sample_epub = "spec/front/unit/data/leaves.epub"
local readerui = ReaderUI:new{
document = DocumentRegistry:openDocument(sample_epub),
}
for i = #UIManager._task_queue, 1, -1 do
local task = UIManager._task_queue[i]
if task.action == readerui.view.emitHintPageEvent then
error("UIManager's task queue should be emtpy.")
end
end
local bb = Blitbuffer.new(1000, 1000)
readerui.view:drawSinglePage(bb, 0, 0)
local found = false
for i = #UIManager._task_queue, 1, -1 do
local task = UIManager._task_queue[i]
if task.action == readerui.view.emitHintPageEvent then
found = true
end
end
assert.is.truthy(found)
readerui:onClose()
assert.is.falsy(readerui.view.hinting)
for i = #UIManager._task_queue, 1, -1 do
local task = UIManager._task_queue[i]
if task.action == readerui.view.emitHintPageEvent then
error("UIManager's task queue should be emtpy.")
end
end
end)
end)
Loading…
Cancel
Save