Compact covermenu addn. to for loop, fix collections bug, further gimp genStatusButton to use upvalues

reviewable/pr10074/r12^2
Melik 1 year ago committed by Frans de Jonge
parent 0e470aaed9
commit 7d6da81233

@ -50,10 +50,10 @@ function FileManagerCollection:onMenuHold(item)
UIManager:close(self.collfile_dialog) UIManager:close(self.collfile_dialog)
end end
local buttons = { local buttons = {
filemanagerutil.getStatusButtonsRow(item.file, currently_opened_file, status_button_callback), filemanagerutil.getStatusButtonsRow(item.file, status_button_callback),
{}, {},
{ {
filemanagerutil.genResetSettingsButton(item.file, nil, status_button_callback), filemanagerutil.genResetSettingsButton(item.file, currently_opened_file, status_button_callback),
{ {
text = _("Remove from collection"), text = _("Remove from collection"),
callback = function() callback = function()

@ -132,9 +132,9 @@ function filemanagerutil.getStatusButtonsRow(file, caller_callback)
} }
end end
return { return {
genStatusButton("reading", status, file, caller_callback), genStatusButton("reading"),
genStatusButton("abandoned", status, file, caller_callback), genStatusButton("abandoned"),
genStatusButton("complete", status, file, caller_callback), genStatusButton("complete"),
} }
end end

@ -342,35 +342,17 @@ function CoverMenu:updateItems(select_number)
end end
-- Fudge the status change button callbacks to also update the cover_info_cache -- Fudge the status change button callbacks to also update the cover_info_cache
button = self.file_dialog.button_table:getButtonById("reading") for _, status in ipairs({"reading", "abandoned", "complete"}) do
local orig_reading_callback = button.callback button = self.file_dialog.button_table:getButtonById(status)
button.callback = function() local orig_status_callback = button.callback
-- Update the cache button.callback = function()
if self.cover_info_cache and self.cover_info_cache[file] then -- Update the cache
self.cover_info_cache[file][3] = "reading" if self.cover_info_cache and self.cover_info_cache[file] then
end self.cover_info_cache[file][3] = status
-- And then set the status on file as expected end
orig_reading_callback() -- And then set the status on file as expected
end orig_status_callback()
button = self.file_dialog.button_table:getButtonById("abandoned")
local orig_abandoned_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_abandoned_callback()
end
button = self.file_dialog.button_table:getButtonById("complete")
local orig_complete_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 end
-- And then set the status on file as expected
orig_complete_callback()
end end
-- Replace the "Book information" button callback to use directly our bookinfo -- Replace the "Book information" button callback to use directly our bookinfo
@ -519,40 +501,18 @@ function CoverMenu:onHistoryMenuHold(item)
end end
-- Fudge the status change button callbacks to also update the cover_info_cache -- Fudge the status change button callbacks to also update the cover_info_cache
button = self.histfile_dialog.button_table:getButtonById("reading") for _, status in ipairs({"reading", "abandoned", "complete"}) do
if button then button = self.histfile_dialog.button_table:getButtonById(status)
local orig_reading_callback = button.callback if button then
button.callback = function() local orig_status_callback = button.callback
-- Update the cache button.callback = function()
if self.cover_info_cache and self.cover_info_cache[file] then -- Update the cache
self.cover_info_cache[file][3] = "reading" if self.cover_info_cache and self.cover_info_cache[file] then
end self.cover_info_cache[file][3] = status
-- And then set the status on file as expected end
orig_reading_callback() -- And then set the status on file as expected
end orig_status_callback()
end
button = self.histfile_dialog.button_table:getButtonById("abandoned")
if button then
local orig_abandoned_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_abandoned_callback()
end
end
button = self.histfile_dialog.button_table:getButtonById("complete")
if button then
local orig_complete_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 end
-- And then set the status on file as expected
orig_complete_callback()
end end
end end
@ -694,35 +654,17 @@ function CoverMenu:onCollectionsMenuHold(item)
end end
-- Fudge the status change button callbacks to also update the cover_info_cache -- Fudge the status change button callbacks to also update the cover_info_cache
button = self.collfile_dialog.button_table:getButtonById("reading") for _, status in ipairs({"reading", "abandoned", "complete"}) do
local orig_reading_callback = button.callback button = self.collfile_dialog.button_table:getButtonById(status)
button.callback = function() local orig_status_callback = button.callback
-- Update the cache button.callback = function()
if self.cover_info_cache and self.cover_info_cache[file] then -- Update the cache
self.cover_info_cache[file][3] = "reading" if self.cover_info_cache and self.cover_info_cache[file] then
end self.cover_info_cache[file][3] = status
-- And then set the status on file as expected end
orig_reading_callback() -- And then set the status on file as expected
end orig_status_callback()
button = self.collfile_dialog.button_table:getButtonById("abandoned")
local orig_abandoned_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_abandoned_callback()
end
button = self.collfile_dialog.button_table:getButtonById("complete")
local orig_complete_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 end
-- And then set the status on file as expected
orig_complete_callback()
end end
-- Replace Book information callback to use directly our bookinfo -- Replace Book information callback to use directly our bookinfo

Loading…
Cancel
Save