Return to callback fudging, fix book info callback replacement

reviewable/pr10074/r12^2
Melik 1 year ago committed by Frans de Jonge
parent 628cacf1e6
commit 1b2adfd201

@ -343,6 +343,7 @@ function FileManager:setupLayout()
table.insert(buttons, {
{
text = _("Mark as reading"),
id = "mark_as_reading", -- used by covermenu
enabled = status ~= "reading",
callback = function()
filemanagerutil.setStatus(file, "reading")
@ -352,6 +353,7 @@ function FileManager:setupLayout()
},
{
text = _("Put on hold"),
id = "put_on_hold", -- used by covermenu
enabled = status ~= "abandoned",
callback = function()
filemanagerutil.setStatus(file, "abandoned")
@ -361,6 +363,7 @@ function FileManager:setupLayout()
},
{
text = _("Mark as read"),
id = "mark_as_read", -- used by covermenu
enabled = status ~= "complete",
callback = function()
filemanagerutil.setStatus(file, "complete")
@ -373,6 +376,7 @@ function FileManager:setupLayout()
table.insert(buttons, {
{
text = _("Reset settings"),
id = "reset_settings", -- used by covermenu
enabled = DocSettings:hasSidecarFile(BaseUtil.realpath(file)),
callback = function()
UIManager:show(ConfirmBox:new{

@ -50,6 +50,7 @@ function FileManagerCollection:onMenuHold(item)
{
{
text = _("Mark as reading"),
id = "mark_as_reading", -- used by covermenu
enabled = status ~= "reading",
callback = function()
filemanagerutil.setStatus(item.file, "reading")
@ -59,6 +60,7 @@ function FileManagerCollection:onMenuHold(item)
},
{
text = _("Put on hold"),
id = "put_on_hold", -- used by covermenu
enabled = status ~= "abandoned",
callback = function()
filemanagerutil.setStatus(item.file, "abandoned")
@ -68,6 +70,7 @@ function FileManagerCollection:onMenuHold(item)
},
{
text = _("Mark as read"),
id = "mark_as_read", -- used by covermenu
enabled = status ~= "complete",
callback = function()
filemanagerutil.setStatus(item.file, "complete")
@ -80,6 +83,7 @@ function FileManagerCollection:onMenuHold(item)
{
{
text = _("Reset settings"),
id = "reset_settings", -- used by covermenu
enabled = DocSettings:hasSidecarFile(BaseUtil.realpath(item.file)),
callback = function()
UIManager:show(ConfirmBox:new{

@ -95,6 +95,7 @@ function FileManagerHistory:onMenuHold(item)
{
{
text = _("Mark as reading"),
id = "mark_as_reading", -- used by covermenu
enabled = is_file and status ~= "reading",
callback = function()
filemanagerutil.setStatus(item.file, "reading")
@ -109,6 +110,7 @@ function FileManagerHistory:onMenuHold(item)
},
{
text = _("Put on hold"),
id = "put_on_hold", -- used by covermenu
enabled = is_file and status ~= "abandoned",
callback = function()
filemanagerutil.setStatus(item.file, "abandoned")
@ -123,6 +125,7 @@ function FileManagerHistory:onMenuHold(item)
},
{
text = _("Mark as read"),
id = "mark_as_read", -- used by covermenu
enabled = is_file and status ~= "complete",
callback = function()
filemanagerutil.setStatus(item.file, "complete")
@ -140,6 +143,7 @@ function FileManagerHistory:onMenuHold(item)
{
{
text = _("Reset settings"),
id = "reset_settings", -- used by covermenu
enabled = item.file ~= currently_opened_file and DocSettings:hasSidecarFile(FFIUtil.realpath(item.file)),
callback = function()
UIManager:show(ConfirmBox:new{

@ -320,38 +320,61 @@ function CoverMenu:updateItems(select_number)
},
})
-- 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)
-- Create the new ButtonDialogTitle, and let UIManager show it
-- (all button callback fudging must be done after this block to stick)
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
self.file_dialog = ButtonDialogTitle:new{
title = orig_title,
title_align = orig_title_align,
buttons = orig_buttons,
}
-- Fudge the "Reset settings" button callback to also trash the cover_info_cache
local button = self.file_dialog.button_table:getButtonById("reset_settings")
local orig_purge_callback = button.callback
button.callback = function()
-- Wipe the cache
if self.cover_info_cache and self.cover_info_cache[f] then
self.cover_info_cache[f] = nil
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file] = nil
end
-- And then purge the sidecar folder as expected
orig_purgeSettings(f)
orig_purge_callback()
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)
-- Fudge the status change button callbacks to also update the cover_info_cache
button = self.file_dialog.button_table:getButtonById("mark_as_reading")
local orig_mark_as_reading_callback = button.callback
button.callback = function()
-- Update the cache
if self.cover_info_cache and self.cover_info_cache[f] then
self.cover_info_cache[f][3] = status
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file][3] = "reading"
end
-- And then set the status on file as expected
orig_setStatus(f, status)
orig_mark_as_reading_callback()
end
button = self.file_dialog.button_table:getButtonById("put_on_hold")
local orig_put_on_hold_callback = button.callback
button.callback = function()
-- Update the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file][3] = "abandoned"
end
-- And then set the status on file as expected
orig_put_on_hold_callback()
end
button = self.file_dialog.button_table:getButtonById("mark_as_read")
local orig_mark_as_read_callback = button.callback
button.callback = function()
-- Update the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file][3] = "complete"
end
-- And then set the status on file as expected
orig_mark_as_read_callback()
end
-- Create the new ButtonDialogTitle, and let UIManager show it
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
self.file_dialog = ButtonDialogTitle:new{
title = orig_title,
title_align = orig_title_align,
buttons = orig_buttons,
}
-- Replace the "Book information" button callback to use directly our bookinfo
local button = self.file_dialog.button_table:getButtonById("book_information")
button = self.file_dialog.button_table:getButtonById("book_information")
button.callback = function()
FileManagerBookInfo:show(file, bookinfo)
UIManager:close(self.file_dialog)
@ -391,12 +414,6 @@ function CoverMenu:onHistoryMenuHold(item)
UIManager:close(self.histfile_dialog)
UIManager:clearRenderStack()
-- Replace Book information callback to use directly our bookinfo
self.histfile_dialog.button_table:getButtonById("book_information").callback = function()
FileManagerBookInfo:show(file, bookinfo)
UIManager:close(self.histfile_dialog)
end
-- Add some new buttons to original buttons set
table.insert(orig_buttons, {
{ -- Allow user to view real size cover in ImageViewer
@ -480,35 +497,65 @@ 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)
-- Create the new ButtonDialog, and let UIManager show it
-- (all button callback replacement must be done after this block to stick)
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
self.histfile_dialog = ButtonDialogTitle:new{
title = orig_title,
title_align = orig_title_align,
buttons = orig_buttons,
}
-- Fudge the "Reset settings" button callback to also trash the cover_info_cache
local button = self.histfile_dialog.button_table:getButtonById("reset_settings")
local orig_purge_callback = button.callback
button.callback = function()
-- Wipe the cache
if self.cover_info_cache and self.cover_info_cache[f] then
self.cover_info_cache[f] = nil
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file] = nil
end
-- And then purge the sidecar folder as expected
orig_purgeSettings(f)
orig_purge_callback()
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)
-- Fudge the status change button callbacks to also update the cover_info_cache
button = self.histfile_dialog.button_table:getButtonById("mark_as_reading")
local orig_mark_as_reading_callback = button.callback
button.callback = function()
-- Update the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file][3] = "reading"
end
-- And then set the status on file as expected
orig_mark_as_reading_callback()
end
button = self.histfile_dialog.button_table:getButtonById("put_on_hold")
local orig_put_on_hold_callback = button.callback
button.callback = function()
-- Update the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file][3] = "abandoned"
end
-- And then set the status on file as expected
orig_put_on_hold_callback()
end
button = self.histfile_dialog.button_table:getButtonById("mark_as_read")
local orig_mark_as_read_callback = button.callback
button.callback = function()
-- Update the cache
if self.cover_info_cache and self.cover_info_cache[f] then
self.cover_info_cache[f][3] = status
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file][3] = "complete"
end
-- And then set the status on file as expected
orig_setStatus(f, status)
orig_mark_as_read_callback()
end
-- Replace Book information callback to use directly our bookinfo
self.histfile_dialog.button_table:getButtonById("book_information").callback = function()
FileManagerBookInfo:show(file, bookinfo)
UIManager:close(self.histfile_dialog)
end
-- Create the new ButtonDialog, and let UIManager show it
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
self.histfile_dialog = ButtonDialogTitle:new{
title = orig_title,
title_align = orig_title_align,
buttons = orig_buttons,
}
UIManager:show(self.histfile_dialog)
return true
end
@ -536,12 +583,6 @@ function CoverMenu:onCollectionsMenuHold(item)
UIManager:close(self.collfile_dialog)
UIManager:clearRenderStack()
-- Replace Book information callback to use directly our bookinfo
self.collfile_dialog.button_table:getButtonById("book_information").callback = function()
FileManagerBookInfo:show(file, bookinfo)
UIManager:close(self.collfile_dialog)
end
-- Add some new buttons to original buttons set
table.insert(orig_buttons, {
{ -- Allow user to view real size cover in ImageViewer
@ -625,35 +666,65 @@ function CoverMenu:onCollectionsMenuHold(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)
-- Create the new ButtonDialog, and let UIManager show it
-- (all button callback replacement must be done after this block to stick)
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
self.collfile_dialog = ButtonDialogTitle:new{
title = orig_title,
title_align = orig_title_align,
buttons = orig_buttons,
}
-- Fudge the "Reset settings" button callback to also trash the cover_info_cache
local button = self.collfile_dialog.button_table:getButtonById("reset_settings")
local orig_purge_callback = button.callback
button.callback = function()
-- Wipe the cache
if self.cover_info_cache and self.cover_info_cache[f] then
self.cover_info_cache[f] = nil
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file] = nil
end
-- And then purge the sidecar folder as expected
orig_purgeSettings(f)
orig_purge_callback()
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)
-- Fudge the status change button callbacks to also update the cover_info_cache
button = self.collfile_dialog.button_table:getButtonById("mark_as_reading")
local orig_mark_as_reading_callback = button.callback
button.callback = function()
-- Update the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file][3] = "reading"
end
-- And then set the status on file as expected
orig_mark_as_reading_callback()
end
button = self.collfile_dialog.button_table:getButtonById("put_on_hold")
local orig_put_on_hold_callback = button.callback
button.callback = function()
-- Update the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file][3] = "abandoned"
end
-- And then set the status on file as expected
orig_put_on_hold_callback()
end
button = self.collfile_dialog.button_table:getButtonById("mark_as_read")
local orig_mark_as_read_callback = button.callback
button.callback = function()
-- Update the cache
if self.cover_info_cache and self.cover_info_cache[f] then
self.cover_info_cache[f][3] = status
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file][3] = "complete"
end
-- And then set the status on file as expected
orig_setStatus(f, status)
orig_mark_as_read_callback()
end
-- Replace Book information callback to use directly our bookinfo
self.collfile_dialog.button_table:getButtonById("book_information").callback = function()
FileManagerBookInfo:show(file, bookinfo)
UIManager:close(self.collfile_dialog)
end
-- Create the new ButtonDialog, and let UIManager show it
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
self.collfile_dialog = ButtonDialogTitle:new{
title = orig_title,
title_align = orig_title_align,
buttons = orig_buttons,
}
UIManager:show(self.collfile_dialog)
return true
end

Loading…
Cancel
Save