Create getStatusButtonsRow() for status buttons, hide row if history item deleted

reviewable/pr10074/r12^2
Melik 1 year ago committed by Frans de Jonge
parent 31cfffc289
commit fb7ec830c6

@ -344,11 +344,7 @@ function FileManager:setupLayout()
self:refreshPath()
UIManager:close(self.file_dialog)
end
table.insert(buttons, {
filemanagerutil.genStatusButton("reading", status ~= "reading", file, status_button_callback),
filemanagerutil.genStatusButton("abandoned", status ~= "abandoned", file, status_button_callback),
filemanagerutil.genStatusButton("complete", status ~= "complete", file, status_button_callback),
})
table.insert(buttons, filemanagerutil.getStatusButtonsRow(status, file, status_button_callback))
table.insert(buttons, {}) -- separator
table.insert(buttons, {
{

@ -51,11 +51,7 @@ function FileManagerCollection:onMenuHold(item)
UIManager:close(self.collfile_dialog)
end
local buttons = {
{
filemanagerutil.genStatusButton("reading", status ~= "reading", item.file, status_button_callback),
filemanagerutil.genStatusButton("abandoned", status ~= "abandoned", item.file, status_button_callback),
filemanagerutil.genStatusButton("complete", status ~= "complete", item.file, status_button_callback),
},
filemanagerutil.getStatusButtonsRow(status, item.file, status_button_callback),
{},
{
{

@ -100,12 +100,6 @@ function FileManagerHistory:onMenuHold(item)
UIManager:close(self.histfile_dialog)
end
local buttons = {
{
filemanagerutil.genStatusButton("reading", not item.dim and status ~= "reading", item.file, status_button_callback),
filemanagerutil.genStatusButton("abandoned", not item.dim and status ~= "abandoned", item.file, status_button_callback),
filemanagerutil.genStatusButton("complete", not item.dim and status ~= "complete", item.file, status_button_callback),
},
{},
{
{
text = _("Reset settings"),
@ -169,6 +163,10 @@ function FileManagerHistory:onMenuHold(item)
},
},
}
if not item.dim then
table.insert(buttons, 1, filemanagerutil.getStatusButtonsRow(status, item.file, status_button_callback))
table.insert(buttons, 2, {})
end
self.histfile_dialog = ButtonDialogTitle:new{
title = BD.filename(item.text:match("([^/]+)$")),
title_align = "center",

@ -109,7 +109,7 @@ function filemanagerutil.setStatus(file, status)
end
-- Generate a book status file dialog button
function filemanagerutil.genStatusButton(to_status, enabled, file, caller_callback)
function filemanagerutil.genStatusButton(to_status, current_status, file, caller_callback)
local status_text = {
reading = _("Reading"),
abandoned = _("On hold"),
@ -118,7 +118,7 @@ function filemanagerutil.genStatusButton(to_status, enabled, file, caller_callba
return {
text = status_text[to_status],
id = to_status, -- used by covermenu
enabled = enabled,
enabled = current_status ~= to_status,
callback = function()
filemanagerutil.setStatus(file, to_status)
caller_callback()
@ -126,4 +126,13 @@ function filemanagerutil.genStatusButton(to_status, enabled, file, caller_callba
}
end
-- Generate all book status file dialog buttons in a row
function filemanagerutil.getStatusButtonsRow(current_status, file, caller_callback)
return {
filemanagerutil.genStatusButton("reading", current_status, file, caller_callback),
filemanagerutil.genStatusButton("abandoned", current_status, file, caller_callback),
filemanagerutil.genStatusButton("complete", current_status, file, caller_callback),
}
end
return filemanagerutil

@ -520,34 +520,40 @@ function CoverMenu:onHistoryMenuHold(item)
-- Fudge the status change button callbacks to also update the cover_info_cache
button = self.histfile_dialog.button_table:getButtonById("reading")
local orig_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"
if button then
local orig_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_reading_callback()
end
-- And then set the status on file as expected
orig_reading_callback()
end
button = self.histfile_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"
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
-- And then set the status on file as expected
orig_abandoned_callback()
end
button = self.histfile_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"
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
-- And then set the status on file as expected
orig_complete_callback()
end
-- And then set the status on file as expected
orig_complete_callback()
end
-- Replace Book information callback to use directly our bookinfo

Loading…
Cancel
Save