FileManager: Plus dialog button from CoverBrowser (#12857)

This commit is contained in:
hius07
2024-12-07 09:18:18 +02:00
committed by GitHub
parent a43c9ab535
commit 157c03c42d
3 changed files with 42 additions and 82 deletions

View File

@@ -1,4 +1,3 @@
local ButtonDialog = require("ui/widget/buttondialog")
local DocSettings = require("docsettings")
local InfoMessage = require("ui/widget/infomessage")
local Menu = require("ui/widget/menu")
@@ -13,7 +12,7 @@ local BookInfoManager = require("bookinfomanager")
-- work : the updating of items and the management of background jobs.
--
-- Here the common overridden methods of Menu are defined:
-- :updateItems(select_number)
-- :updateItems(select_number, no_recalculate_dimen)
-- :onCloseWidget()
--
-- MosaicMenu or ListMenu should implement specific UI methods:
@@ -24,12 +23,6 @@ local BookInfoManager = require("bookinfomanager")
-- not found item to self.items_to_update for us to update() them
-- regularly.
-- Store these as local, to be set by some object and re-used by
-- another object (as we plug the methods below to different objects,
-- we can't store them in 'self' if we want another one to use it)
local current_path = nil
local current_cover_specs = false
-- Do some collectgarbage() every few drawings
local NB_DRAWINGS_BETWEEN_COLLECTGARBAGE = 5
local nb_drawings_since_last_collectgarbage = 0
@@ -128,14 +121,6 @@ function CoverMenu:updateItems(select_number, no_recalculate_dimen)
-- Specific UI building implementation (defined in some other module)
self._has_cover_images = false
select_number = self:_updateItemsBuildUI() or select_number
-- Set the local variables with the things we know
-- These are used only by extractBooksInDirectory(), which should
-- use the cover_specs set for FileBrowser, and not those from History.
-- Hopefully, we get self.path=nil when called from History
if self.path then
current_path = self.path
current_cover_specs = self.cover_specs
end
-- As done in Menu:updateItems()
self:updatePageInfo(select_number)
@@ -261,44 +246,4 @@ function CoverMenu:onCloseWidget()
Menu.onCloseWidget(self)
end
function CoverMenu:tapPlus()
-- Call original function: it will create a ButtonDialog
-- and store it as self.file_dialog, and UIManager:show() it.
CoverMenu._FileManager_tapPlus_orig(self)
if self.file_dialog.select_mode then return end -- do not change select menu
-- Remember some of this original ButtonDialog properties
local orig_title = self.file_dialog.title
local orig_title_align = self.file_dialog.title_align
local orig_buttons = self.file_dialog.buttons
-- Close original ButtonDialog (it has not yet been painted
-- on screen, so we won't see it)
UIManager:close(self.file_dialog)
UIManager:clearRenderStack()
-- Add a new button to original buttons set
table.insert(orig_buttons, {}) -- separator
table.insert(orig_buttons, {
{
text = _("Extract and cache book information"),
callback = function()
UIManager:close(self.file_dialog)
local Trapper = require("ui/trapper")
Trapper:wrap(function()
BookInfoManager:extractBooksInDirectory(current_path, current_cover_specs)
end)
end,
},
})
-- Create the new ButtonDialog, and let UIManager show it
self.file_dialog = ButtonDialog:new{
title = orig_title,
title_align = orig_title_align,
buttons = orig_buttons,
}
UIManager:show(self.file_dialog)
return true
end
return CoverMenu

View File

@@ -27,7 +27,6 @@ local FileManagerCollection = require("apps/filemanager/filemanagercollection")
local _FileManagerCollection_updateItemTable_orig = FileManagerCollection.updateItemTable
local FileManager = require("apps/filemanager/filemanager")
local _FileManager_tapPlus_orig = FileManager.tapPlus
-- Available display modes
local DISPLAY_MODES = {
@@ -496,6 +495,22 @@ function CoverBrowser:addToMainMenu(menu_items)
})
end
function CoverBrowser:genExtractBookInfoButton(close_dialog_callback) -- for FileManager Plus dialog
return filemanager_display_mode and {
{
text = _("Extract and cache book information"),
callback = function()
close_dialog_callback()
local fc = self.ui.file_chooser
local Trapper = require("ui/trapper")
Trapper:wrap(function()
BookInfoManager:extractBooksInDirectory(fc.path, fc.cover_specs)
end)
end,
},
}
end
function CoverBrowser.initGrid(menu, display_mode)
if menu == nil then return end
if menu.nb_cols_portrait == nil then
@@ -605,7 +620,6 @@ function CoverBrowser:setupFileManagerDisplayMode(display_mode)
FileChooser.updateItems = _FileChooser_updateItems_orig
FileChooser.onCloseWidget = _FileChooser_onCloseWidget_orig
FileChooser._recalculateDimen = _FileChooser__recalculateDimen_orig
FileManager.tapPlus = _FileManager_tapPlus_orig
CoverBrowser.removeFileDialogButtons(FileManager)
-- Also clean-up what we added, even if it does not bother original code
FileChooser.updateCache = nil
@@ -646,12 +660,6 @@ function CoverBrowser:setupFileManagerDisplayMode(display_mode)
FileChooser._do_hint_opened = true -- dogear at bottom
end
-- Replace this FileManager method with the one from CoverMenu
-- (but first, make the original method saved here as local available
-- to CoverMenu)
CoverMenu._FileManager_tapPlus_orig = _FileManager_tapPlus_orig
FileManager.tapPlus = CoverMenu.tapPlus
if init_done then
self:refreshFileManagerInstance()
else