mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Open previous file in last book folder (#13424)
This commit is contained in:
@@ -1615,4 +1615,19 @@ function FileManager:onSetMixedSorting(toggle)
|
||||
return true
|
||||
end
|
||||
|
||||
function FileManager:onOpenNextOrPreviousFileInFolder(prev)
|
||||
local last_file = G_reader_settings:readSetting("lastfile")
|
||||
if not last_file then return true end
|
||||
local file = self.file_chooser:getNextOrPreviousFileInFolder(last_file, prev)
|
||||
if file then
|
||||
self:openFile(file)
|
||||
else
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = prev and _("Last book is the first file in the folder. No previous file to open.")
|
||||
or _("Last book is the last file in the folder. No next file to open."),
|
||||
})
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
return FileManager
|
||||
|
||||
@@ -171,20 +171,24 @@ function ReaderStatus:openFileBrowser()
|
||||
self.ui:showFileManager(file)
|
||||
end
|
||||
|
||||
function ReaderStatus:onOpenNextDocumentInFolder()
|
||||
function ReaderStatus:onOpenNextOrPreviousFileInFolder(prev)
|
||||
local collate = G_reader_settings:readSetting("collate")
|
||||
if collate == "access" or collate == "date" then return true end
|
||||
local FileChooser = require("ui/widget/filechooser")
|
||||
local next_file = FileChooser:getNextFile(self.document.file)
|
||||
if next_file then
|
||||
local file = FileChooser:getNextOrPreviousFileInFolder(self.document.file, prev)
|
||||
if file then
|
||||
-- Delay until the next tick, as this will destroy the Document instance,
|
||||
-- but we may not be the final Event caught by said Document...
|
||||
UIManager:nextTick(function()
|
||||
self.ui:switchDocument(next_file)
|
||||
self.ui:switchDocument(file)
|
||||
end)
|
||||
else
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = _("This is the last file in the current folder. No next file to open."),
|
||||
text = prev and _("This is the first file in the folder. No previous file to open.")
|
||||
or _("This is the last file in the folder. No next file to open."),
|
||||
})
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function ReaderStatus:deleteFile()
|
||||
|
||||
@@ -63,6 +63,8 @@ local settingsList = {
|
||||
----
|
||||
show_menu = {category="none", event="ShowMenu", title=_("Show menu"), general=true},
|
||||
menu_search = {category="none", event="MenuSearch", title=_("Menu search"), general=true},
|
||||
open_next_document_in_folder = {category="none", event="OpenNextOrPreviousFileInFolder", title=_("Open next file in last book folder"), general=true},
|
||||
open_previous_document_in_folder = {category="none", event="OpenNextOrPreviousFileInFolder", arg=true, title=_("Open previous file in last book folder"), general=true},
|
||||
notebook_file = {category="none", event="ShowNotebookFile", title=_("Notebook file"), general=true},
|
||||
screenshot = {category="none", event="Screenshot", title=_("Screenshot"), general=true, separator=true},
|
||||
----
|
||||
@@ -145,8 +147,6 @@ local settingsList = {
|
||||
----
|
||||
|
||||
-- Reader
|
||||
open_next_document_in_folder = {category="none", event="OpenNextDocumentInFolder", title=_("Open next document in folder"), reader=true, separator=true},
|
||||
----
|
||||
show_config_menu = {category="none", event="ShowConfigMenu", title=_("Show bottom menu"), reader=true},
|
||||
toggle_status_bar = {category="none", event="ToggleFooterMode", title=_("Toggle status bar"), reader=true},
|
||||
toggle_chapter_progress_bar = {category="none", event="ToggleChapterProgressBar", title=_("Toggle chapter progress bar"), reader=true, separator=true},
|
||||
@@ -298,6 +298,8 @@ local dispatcher_menu_order = {
|
||||
----
|
||||
"show_menu",
|
||||
"menu_search",
|
||||
"open_next_document_in_folder",
|
||||
"open_previous_document_in_folder",
|
||||
"notebook_file",
|
||||
"screenshot",
|
||||
----
|
||||
@@ -380,8 +382,6 @@ local dispatcher_menu_order = {
|
||||
----
|
||||
|
||||
-- Reader
|
||||
"open_next_document_in_folder",
|
||||
----
|
||||
"show_config_menu",
|
||||
"toggle_status_bar",
|
||||
"toggle_chapter_progress_bar",
|
||||
|
||||
@@ -430,23 +430,29 @@ function FileChooser:onFileHold(item)
|
||||
return true
|
||||
end
|
||||
|
||||
-- Used in ReaderStatus:onOpenNextDocumentInFolder().
|
||||
function FileChooser:getNextFile(curr_file)
|
||||
function FileChooser:getNextOrPreviousFileInFolder(curr_file, prev)
|
||||
local show_finished = FileChooser.show_finished
|
||||
FileChooser.show_finished = true
|
||||
local curr_path = curr_file:match(".*/"):gsub("/$", "")
|
||||
local item_table = self:genItemTableFromPath(curr_path)
|
||||
FileChooser.show_finished = show_finished
|
||||
local is_curr_file_found
|
||||
for i, item in ipairs(item_table) do
|
||||
if not is_curr_file_found and item.path == curr_file then
|
||||
local top_i, step, is_curr_file_found
|
||||
if prev then
|
||||
top_i = #item_table + 1
|
||||
step = -1
|
||||
else
|
||||
step = 1
|
||||
end
|
||||
for i = 1, #item_table do
|
||||
local idx = prev and top_i - i or i
|
||||
if not is_curr_file_found and item_table[idx].path == curr_file then
|
||||
is_curr_file_found = true
|
||||
end
|
||||
if is_curr_file_found then
|
||||
local next_file = item_table[i+1]
|
||||
if next_file and next_file.is_file and DocumentRegistry:hasProvider(next_file.path)
|
||||
and BookList.getBookStatus(next_file.path) ~= "complete" then
|
||||
return next_file.path
|
||||
local file = item_table[idx + step]
|
||||
if file and file.is_file and DocumentRegistry:hasProvider(file.path)
|
||||
and BookList.getBookStatus(file.path) ~= "complete" then
|
||||
return file.path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user