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() self:refreshPath()
UIManager:close(self.file_dialog) UIManager:close(self.file_dialog)
end end
table.insert(buttons, { table.insert(buttons, filemanagerutil.getStatusButtonsRow(status, file, status_button_callback))
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, {}) -- separator table.insert(buttons, {}) -- separator
table.insert(buttons, { table.insert(buttons, {
{ {

@ -51,11 +51,7 @@ function FileManagerCollection:onMenuHold(item)
UIManager:close(self.collfile_dialog) UIManager:close(self.collfile_dialog)
end end
local buttons = { local buttons = {
{ filemanagerutil.getStatusButtonsRow(status, item.file, status_button_callback),
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),
},
{}, {},
{ {
{ {

@ -100,12 +100,6 @@ function FileManagerHistory:onMenuHold(item)
UIManager:close(self.histfile_dialog) UIManager:close(self.histfile_dialog)
end end
local buttons = { 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"), 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{ self.histfile_dialog = ButtonDialogTitle:new{
title = BD.filename(item.text:match("([^/]+)$")), title = BD.filename(item.text:match("([^/]+)$")),
title_align = "center", title_align = "center",

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

@ -520,34 +520,40 @@ function CoverMenu:onHistoryMenuHold(item)
-- 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") button = self.histfile_dialog.button_table:getButtonById("reading")
local orig_reading_callback = button.callback if button then
button.callback = function() local orig_reading_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
self.cover_info_cache[file][3] = "reading"
end
-- And then set the status on file as expected
orig_reading_callback()
end end
-- And then set the status on file as expected
orig_reading_callback()
end end
button = self.histfile_dialog.button_table:getButtonById("abandoned") button = self.histfile_dialog.button_table:getButtonById("abandoned")
local orig_abandoned_callback = button.callback if button then
button.callback = function() local orig_abandoned_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] = "abandoned" 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
-- And then set the status on file as expected
orig_abandoned_callback()
end end
button = self.histfile_dialog.button_table:getButtonById("complete") button = self.histfile_dialog.button_table:getButtonById("complete")
local orig_complete_callback = button.callback if button then
button.callback = function() local orig_complete_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] = "complete" 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 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