[fix] Ensure "Open last/previous" point to existing files (#4367)

This commit is contained in:
poire-z
2018-11-28 21:14:07 +01:00
committed by Frans de Jonge
parent 7841351a81
commit 2b9694d7d2
4 changed files with 33 additions and 13 deletions

View File

@@ -186,29 +186,35 @@ function ReaderMenu:setUpdateItemTable()
end,
}
local previous_file
local readhistory = require("readhistory")
for i=2, #readhistory.hist do -- skip first one which is current book
if lfs.attributes(readhistory.hist[i].file, "mode") == "file" then
previous_file = readhistory.hist[i].file
break
local getPreviousFile = function()
local previous_file = nil
local readhistory = require("readhistory")
for i=2, #readhistory.hist do -- skip first one which is current book
-- skip deleted items kept in history
if lfs.attributes(readhistory.hist[i].file, "mode") == "file" then
previous_file = readhistory.hist[i].file
break
end
end
return previous_file
end
self.menu_items.open_previous_document = {
text_func = function()
local previous_file = getPreviousFile()
if not G_reader_settings:isTrue("open_last_menu_show_filename") or not previous_file then
return _("Open previous document")
end
local path, file_name = util.splitFilePathName(previous_file); -- luacheck: no unused
local path, file_name = util.splitFilePathName(previous_file) -- luacheck: no unused
return T(_("Previous: %1"), file_name)
end,
enabled_func = function()
return previous_file ~= nil
return getPreviousFile() ~= nil
end,
callback = function()
self.ui:switchDocument(previous_file)
self.ui:switchDocument(getPreviousFile())
end,
hold_callback = function()
local previous_file = getPreviousFile()
UIManager:show(ConfirmBox:new{
text = T(_("Would you like to open the previous document: %1?"), previous_file),
ok_text = _("OK"),