[feat, UX] Gesture manager: add option - open previous document (#4641)

Fixes #4333.
pull/4644/head
Frans de Jonge 5 years ago committed by GitHub
parent 260427d226
commit 9a92792551
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -94,7 +94,12 @@ function FileManagerMenu:openLastDoc()
end end
local ReaderUI = require("apps/reader/readerui") local ReaderUI = require("apps/reader/readerui")
ReaderUI:showReader(last_file) ReaderUI:showReader(last_file)
self:onCloseFileManagerMenu()
-- only close menu if we were called from the menu
if self.menu_container then
self:onCloseFileManagerMenu()
end
local FileManager = require("apps/filemanager/filemanager") local FileManager = require("apps/filemanager/filemanager")
FileManager.instance:onClose() FileManager.instance:onClose()
end end

@ -93,6 +93,7 @@ function ReaderGesture:buildMenu(ges, default)
{_("Folder up"), "folder_up", self.is_docless}, {_("Folder up"), "folder_up", self.is_docless},
{_("Bookmarks"), "bookmarks", not self.is_docless}, {_("Bookmarks"), "bookmarks", not self.is_docless},
{_("History"), "history", true}, {_("History"), "history", true},
{_("Open previous document"), "open_previous_document", true, true},
{_("Table of contents"), "toc", not self.is_docless}, {_("Table of contents"), "toc", not self.is_docless},
{_("Reading progress"), "reading_progress", ReaderGesture.getReaderProgress ~= nil}, {_("Reading progress"), "reading_progress", ReaderGesture.getReaderProgress ~= nil},
{_("Full screen refresh"), "full_refresh", true}, {_("Full screen refresh"), "full_refresh", true},
@ -130,7 +131,8 @@ function ReaderGesture:buildMenu(ges, default)
G_reader_settings:saveSetting(self.ges_mode, gesture_manager) G_reader_settings:saveSetting(self.ges_mode, gesture_manager)
end end
if entry[2] ~= default and entry[3] then if entry[2] ~= default and entry[3] then
table.insert(return_menu, self:createSubMenu(entry[1], entry[2], ges, entry[2] == "nothing")) local sep = entry[2] == "nothing" or entry[4] == true
table.insert(return_menu, self:createSubMenu(entry[1], entry[2], ges, sep))
end end
end end
return return_menu return return_menu
@ -330,6 +332,14 @@ function ReaderGesture:gestureAction(action)
self.ui:handleEvent(Event:new("GoBackLink")) self.ui:handleEvent(Event:new("GoBackLink"))
elseif action == "folder_up" then elseif action == "folder_up" then
self.ui.file_chooser:changeToPath(string.format("%s/..", self.ui.file_chooser.path)) self.ui.file_chooser:changeToPath(string.format("%s/..", self.ui.file_chooser.path))
elseif action == "open_previous_document" then
-- FileManager
if self.ui.menu.openLastDoc and G_reader_settings:readSetting("lastfile") ~= nil then
self.ui.menu:openLastDoc()
-- ReaderUI
elseif self.ui.switchDocument and self.ui.menu then
self.ui:switchDocument(self.ui.menu:getPreviousFile())
end
elseif action == "toggle_frontlight" then elseif action == "toggle_frontlight" then
Device:getPowerDevice():toggleFrontlight() Device:getPowerDevice():toggleFrontlight()
self:onShowFLOnOff() self:onShowFLOnOff()

@ -70,6 +70,19 @@ function ReaderMenu:init()
end end
end end
function ReaderMenu:getPreviousFile()
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
function ReaderMenu:onReaderReady() function ReaderMenu:onReaderReady()
-- deligate gesture listener to readerui -- deligate gesture listener to readerui
self.ges_events = {} self.ges_events = {}
@ -191,21 +204,9 @@ function ReaderMenu:setUpdateItemTable()
self.menu_items.restart_koreader = nil self.menu_items.restart_koreader = nil
end end
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 = { self.menu_items.open_previous_document = {
text_func = function() text_func = function()
local previous_file = getPreviousFile() local previous_file = self:getPreviousFile()
if not G_reader_settings:isTrue("open_last_menu_show_filename") or not previous_file then if not G_reader_settings:isTrue("open_last_menu_show_filename") or not previous_file then
return _("Open previous document") return _("Open previous document")
end end
@ -213,13 +214,13 @@ function ReaderMenu:setUpdateItemTable()
return T(_("Previous: %1"), file_name) return T(_("Previous: %1"), file_name)
end, end,
enabled_func = function() enabled_func = function()
return getPreviousFile() ~= nil return self:getPreviousFile() ~= nil
end, end,
callback = function() callback = function()
self.ui:switchDocument(getPreviousFile()) self.ui:switchDocument(self:getPreviousFile())
end, end,
hold_callback = function() hold_callback = function()
local previous_file = getPreviousFile() local previous_file = self:getPreviousFile()
UIManager:show(ConfirmBox:new{ UIManager:show(ConfirmBox:new{
text = T(_("Would you like to open the previous document: %1?"), previous_file), text = T(_("Would you like to open the previous document: %1?"), previous_file),
ok_text = _("OK"), ok_text = _("OK"),

@ -684,6 +684,7 @@ function ReaderUI:reloadDocument(after_close_callback)
end end
function ReaderUI:switchDocument(new_file) function ReaderUI:switchDocument(new_file)
if not new_file then return end
self:handleEvent(Event:new("CloseReaderMenu")) self:handleEvent(Event:new("CloseReaderMenu"))
self:handleEvent(Event:new("CloseConfigMenu")) self:handleEvent(Event:new("CloseConfigMenu"))
self.highlight:onClose() -- close highlight dialog if any self.highlight:onClose() -- close highlight dialog if any

Loading…
Cancel
Save