Move cache update logic into CoverMenu:updateCache

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

@ -43,6 +43,16 @@ local nb_drawings_since_last_collectgarbage = 0
-- in the real Menu class or instance
local CoverMenu = {}
function CoverMenu:updateCache(file, status)
if self.cover_info_cache and self.cover_info_cache[file] then
if status then
self.cover_info_cache[file][3] = status
else
self.cover_info_cache[file] = nil
end
end
end
function CoverMenu:updateItems(select_number)
-- As done in Menu:updateItems()
local old_dimen = self.dimen and self.dimen:copy()
@ -310,9 +320,7 @@ function CoverMenu:updateItems(select_number)
enabled = bookinfo and true or false,
callback = function()
-- Wipe the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file] = nil
end
self:updateCache(file)
BookInfoManager:deleteBookInfo(file)
UIManager:close(self.file_dialog)
self:updateItems()
@ -334,9 +342,7 @@ function CoverMenu:updateItems(select_number)
local orig_purge_callback = button.callback
button.callback = function()
-- Wipe the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file] = nil
end
self:updateCache(file)
-- And then purge the sidecar folder as expected
orig_purge_callback()
end
@ -347,9 +353,7 @@ function CoverMenu:updateItems(select_number)
local orig_status_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] = status
end
self:updateCache(file, status)
-- And then set the status on file as expected
orig_status_callback()
end
@ -469,9 +473,7 @@ function CoverMenu:onHistoryMenuHold(item)
enabled = bookinfo and true or false,
callback = function()
-- Wipe the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file] = nil
end
self:updateCache(file)
BookInfoManager:deleteBookInfo(file)
UIManager:close(self.histfile_dialog)
self:updateItems()
@ -493,9 +495,7 @@ function CoverMenu:onHistoryMenuHold(item)
local orig_purge_callback = button.callback
button.callback = function()
-- Wipe the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file] = nil
end
self:updateCache(file)
-- And then purge the sidecar folder as expected
orig_purge_callback()
end
@ -507,9 +507,7 @@ function CoverMenu:onHistoryMenuHold(item)
local orig_status_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] = status
end
self:updateCache(file, status)
-- And then set the status on file as expected
orig_status_callback()
end
@ -622,9 +620,7 @@ function CoverMenu:onCollectionsMenuHold(item)
enabled = bookinfo and true or false,
callback = function()
-- Wipe the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file] = nil
end
self:updateCache(file)
BookInfoManager:deleteBookInfo(file)
UIManager:close(self.collfile_dialog)
self:updateItems()
@ -646,9 +642,7 @@ function CoverMenu:onCollectionsMenuHold(item)
local orig_purge_callback = button.callback
button.callback = function()
-- Wipe the cache
if self.cover_info_cache and self.cover_info_cache[file] then
self.cover_info_cache[file] = nil
end
self:updateCache(file)
-- And then purge the sidecar folder as expected
orig_purge_callback()
end
@ -659,9 +653,7 @@ function CoverMenu:onCollectionsMenuHold(item)
local orig_status_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] = status
end
self:updateCache(file, status)
-- And then set the status on file as expected
orig_status_callback()
end

@ -527,6 +527,7 @@ function CoverBrowser:setupFileManagerDisplayMode(display_mode)
-- In both mosaic and list modes, replace original methods with those from
-- our generic CoverMenu
local CoverMenu = require("covermenu")
FileChooser.updateCache = CoverMenu.updateCache
FileChooser.updateItems = CoverMenu.updateItems
FileChooser.onCloseWidget = CoverMenu.onCloseWidget
@ -592,6 +593,7 @@ local function _FileManagerHistory_updateItemTable(self)
-- In both mosaic and list modes, replace original methods with those from
-- our generic CoverMenu
local CoverMenu = require("covermenu")
hist_menu.updateCache = CoverMenu.updateCache
hist_menu.updateItems = CoverMenu.updateItems
hist_menu.onCloseWidget = CoverMenu.onCloseWidget
-- Also replace original onMenuHold (it will use original method, so remember it)
@ -670,6 +672,7 @@ local function _FileManagerCollections_updateItemTable(self)
-- In both mosaic and list modes, replace original methods with those from
-- our generic CoverMenu
local CoverMenu = require("covermenu")
coll_menu.updateCache = CoverMenu.updateCache
coll_menu.updateItems = CoverMenu.updateItems
coll_menu.onCloseWidget = CoverMenu.onCloseWidget
-- Also replace original onMenuHold (it will use original method, so remember it)

Loading…
Cancel
Save