2
0
mirror of https://github.com/koreader/koreader synced 2024-11-10 01:10:34 +00:00

Add buttons to history, use id for button-getting

This commit is contained in:
Melik 2022-12-24 02:28:02 -06:00 committed by Frans de Jonge
parent 086d4622e6
commit 57849b3f7c
5 changed files with 88 additions and 22 deletions

View File

@ -339,15 +339,7 @@ function FileManager:setupLayout()
end end
if is_file then if is_file then
local status = nil local status = filemanagerutil.getStatus(file)
if DocSettings:hasSidecarFile(file) then
local docinfo = DocSettings:open(file) -- no io handles created, do not close
if docinfo.data.summary and docinfo.data.summary.status and docinfo.data.summary.status ~= "" then
status = docinfo.data.summary.status
else
status = "reading"
end
end
table.insert(buttons, { table.insert(buttons, {
{ {
text = _("Mark as reading"), text = _("Mark as reading"),

View File

@ -85,6 +85,7 @@ function FileManagerCollection:onMenuHold(item)
{ {
{ {
text = _("Book information"), text = _("Book information"),
id = "book_information", -- used by covermenu
enabled = FileManagerBookInfo:isSupported(item.file), enabled = FileManagerBookInfo:isSupported(item.file),
callback = function() callback = function()
FileManagerBookInfo:show(item.file) FileManagerBookInfo:show(item.file)

View File

@ -47,17 +47,7 @@ function FileManagerHistory:fetchStatuses(count)
if v.dim then if v.dim then
status = "deleted" status = "deleted"
else else
if DocSettings:hasSidecarFile(v.file) then status = filemanagerutil.getStatus(v.file)
local docinfo = DocSettings:open(v.file) -- no io handles created, do not close
if docinfo.data.summary and docinfo.data.summary.status
and docinfo.data.summary.status ~= "" then
status = docinfo.data.summary.status
else
status = "reading"
end
else
status = "new"
end
end end
v.status = status v.status = status
if count then if count then
@ -99,7 +89,53 @@ function FileManagerHistory:onMenuHold(item)
local readerui_instance = require("apps/reader/readerui"):_getRunningInstance() local readerui_instance = require("apps/reader/readerui"):_getRunningInstance()
local currently_opened_file = readerui_instance and readerui_instance.document and readerui_instance.document.file local currently_opened_file = readerui_instance and readerui_instance.document and readerui_instance.document.file
self.histfile_dialog = nil self.histfile_dialog = nil
local status = filemanagerutil.getStatus(item.file)
local buttons = { local buttons = {
{
{
text = _("Mark as reading"),
enabled = status ~= "reading",
callback = function()
filemanagerutil.setStatus(item.file, "reading")
if self._manager.filter ~= "all" then
self._manager:fetchStatuses(false)
else
self._manager.statuses_fetched = false
end
self._manager:updateItemTable()
UIManager:close(self.histfile_dialog)
end,
},
{
text = _("Mark as read"),
enabled = status ~= "complete",
callback = function()
filemanagerutil.setStatus(item.file, "complete")
if self._manager.filter ~= "all" then
self._manager:fetchStatuses(false)
else
self._manager.statuses_fetched = false
end
self._manager:updateItemTable()
UIManager:close(self.histfile_dialog)
end,
},
{
text = _("Put on hold"),
enabled = status ~= "abandoned",
callback = function()
filemanagerutil.setStatus(item.file, "abandoned")
if self._manager.filter ~= "all" then
self._manager:fetchStatuses(false)
else
self._manager.statuses_fetched = false
end
self._manager:updateItemTable()
UIManager:close(self.histfile_dialog)
end,
},
},
{},
{ {
{ {
text = _("Reset settings"), text = _("Reset settings"),
@ -153,6 +189,7 @@ function FileManagerHistory:onMenuHold(item)
}, },
{ {
text = _("Book information"), text = _("Book information"),
id = "book_information", -- used by covermenu
enabled = FileManagerBookInfo:isSupported(item.file), enabled = FileManagerBookInfo:isSupported(item.file),
callback = function() callback = function()
FileManagerBookInfo:show(item.file) FileManagerBookInfo:show(item.file)

View File

@ -63,6 +63,20 @@ function filemanagerutil.resetDocumentSettings(file)
end end
end end
-- Get a document's status ("new", "reading", "complete", or "abandoned")
function filemanagerutil.getStatus(file)
local status = "new"
if DocSettings:hasSidecarFile(file) then
local docinfo = DocSettings:open(file) -- no io handles created, do not close
if docinfo.data.summary and docinfo.data.summary.status and docinfo.data.summary.status ~= "" then
status = docinfo.data.summary.status
else
status = "reading"
end
end
return status
end
-- Set a document's status -- Set a document's status
function filemanagerutil.setStatus(file, status) function filemanagerutil.setStatus(file, status)
-- In case the book doesn't have a sidecar file, this'll create it -- In case the book doesn't have a sidecar file, this'll create it

View File

@ -392,7 +392,7 @@ function CoverMenu:onHistoryMenuHold(item)
UIManager:clearRenderStack() UIManager:clearRenderStack()
-- Replace Book information callback to use directly our bookinfo -- Replace Book information callback to use directly our bookinfo
orig_buttons[2][2].callback = function() self.histfile_dialog.button_table:getButtonById("book_information").callback = function()
FileManagerBookInfo:show(file, bookinfo) FileManagerBookInfo:show(file, bookinfo)
UIManager:close(self.histfile_dialog) UIManager:close(self.histfile_dialog)
end end
@ -480,6 +480,28 @@ function CoverMenu:onHistoryMenuHold(item)
}, },
}) })
-- Fudge the setting resets (e.g. "Reset settings" button) to also trash the cover_info_cache
local orig_purgeSettings = filemanagerutil.purgeSettings
filemanagerutil.purgeSettings = function(f)
-- Wipe the cache
if self.cover_info_cache and self.cover_info_cache[f] then
self.cover_info_cache[f] = nil
end
-- And then purge the sidecar folder as expected
orig_purgeSettings(f)
end
-- Fudge status changes (e.g. "Mark as read" button) to also update the cover_info_cache
local orig_setStatus = filemanagerutil.setStatus
filemanagerutil.setStatus = function(f, status)
-- Update the cache
if self.cover_info_cache and self.cover_info_cache[f] then
self.cover_info_cache[f][3] = status
end
-- And then set the status on file as expected
orig_setStatus(f, status)
end
-- Create the new ButtonDialog, and let UIManager show it -- Create the new ButtonDialog, and let UIManager show it
local ButtonDialogTitle = require("ui/widget/buttondialogtitle") local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
self.histfile_dialog = ButtonDialogTitle:new{ self.histfile_dialog = ButtonDialogTitle:new{
@ -515,7 +537,7 @@ function CoverMenu:onCollectionsMenuHold(item)
UIManager:clearRenderStack() UIManager:clearRenderStack()
-- Replace Book information callback to use directly our bookinfo -- Replace Book information callback to use directly our bookinfo
orig_buttons[2][1].callback = function() self.collfile_dialog.button_table:getButtonById("book_information").callback = function()
FileManagerBookInfo:show(file, bookinfo) FileManagerBookInfo:show(file, bookinfo)
UIManager:close(self.collfile_dialog) UIManager:close(self.collfile_dialog)
end end