mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
FileManager: Plus dialog button from CoverBrowser (#12857)
This commit is contained in:
@@ -531,8 +531,9 @@ function FileManager:onToggleSelectMode(do_refresh)
|
||||
end
|
||||
|
||||
function FileManager:tapPlus()
|
||||
local plus_dialog
|
||||
local function close_dialog_callback()
|
||||
UIManager:close(self.file_dialog)
|
||||
UIManager:close(plus_dialog)
|
||||
end
|
||||
local function refresh_titlebar_callback()
|
||||
self:updateTitleBarPath()
|
||||
@@ -556,7 +557,7 @@ function FileManager:tapPlus()
|
||||
text = _("Show selected files list"),
|
||||
enabled = actions_enabled,
|
||||
callback = function()
|
||||
UIManager:close(self.file_dialog)
|
||||
UIManager:close(plus_dialog)
|
||||
self:showSelectedFilesList()
|
||||
end,
|
||||
},
|
||||
@@ -573,7 +574,7 @@ function FileManager:tapPlus()
|
||||
{
|
||||
text = _("Select all files in folder"),
|
||||
callback = function()
|
||||
UIManager:close(self.file_dialog)
|
||||
UIManager:close(plus_dialog)
|
||||
self.file_chooser:selectAllFilesInFolder(true)
|
||||
end,
|
||||
},
|
||||
@@ -591,7 +592,7 @@ function FileManager:tapPlus()
|
||||
text = _("Deselect all"),
|
||||
enabled = actions_enabled,
|
||||
callback = function()
|
||||
UIManager:close(self.file_dialog)
|
||||
UIManager:close(plus_dialog)
|
||||
for file in pairs (self.selected_files) do
|
||||
self.selected_files[file] = nil
|
||||
end
|
||||
@@ -606,7 +607,7 @@ function FileManager:tapPlus()
|
||||
text = _("Delete selected files?\nIf you delete a file, it is permanently lost."),
|
||||
ok_text = _("Delete"),
|
||||
ok_callback = function()
|
||||
UIManager:close(self.file_dialog)
|
||||
UIManager:close(plus_dialog)
|
||||
self:deleteSelectedFiles()
|
||||
end,
|
||||
})
|
||||
@@ -617,7 +618,7 @@ function FileManager:tapPlus()
|
||||
{
|
||||
text = _("Exit select mode"),
|
||||
callback = function()
|
||||
UIManager:close(self.file_dialog)
|
||||
UIManager:close(plus_dialog)
|
||||
self:onToggleSelectMode()
|
||||
end,
|
||||
},
|
||||
@@ -634,7 +635,7 @@ function FileManager:tapPlus()
|
||||
{
|
||||
text = _("New folder"),
|
||||
callback = function()
|
||||
UIManager:close(self.file_dialog)
|
||||
UIManager:close(plus_dialog)
|
||||
self:createFolder()
|
||||
end,
|
||||
},
|
||||
@@ -648,7 +649,7 @@ function FileManager:tapPlus()
|
||||
{
|
||||
text = _("Select files"),
|
||||
callback = function()
|
||||
UIManager:close(self.file_dialog)
|
||||
UIManager:close(plus_dialog)
|
||||
self:onToggleSelectMode()
|
||||
end,
|
||||
},
|
||||
@@ -657,7 +658,7 @@ function FileManager:tapPlus()
|
||||
{
|
||||
text = _("New folder"),
|
||||
callback = function()
|
||||
UIManager:close(self.file_dialog)
|
||||
UIManager:close(plus_dialog)
|
||||
self:createFolder()
|
||||
end,
|
||||
},
|
||||
@@ -667,7 +668,7 @@ function FileManager:tapPlus()
|
||||
text = _("Paste"),
|
||||
enabled = self.clipboard and true or false,
|
||||
callback = function()
|
||||
UIManager:close(self.file_dialog)
|
||||
UIManager:close(plus_dialog)
|
||||
self:pasteFileFromClipboard()
|
||||
end,
|
||||
},
|
||||
@@ -676,7 +677,7 @@ function FileManager:tapPlus()
|
||||
{
|
||||
text = _("Set as HOME folder"),
|
||||
callback = function()
|
||||
UIManager:close(self.file_dialog)
|
||||
UIManager:close(plus_dialog)
|
||||
self:setHome()
|
||||
end
|
||||
},
|
||||
@@ -685,7 +686,7 @@ function FileManager:tapPlus()
|
||||
{
|
||||
text = _("Go to HOME folder"),
|
||||
callback = function()
|
||||
UIManager:close(self.file_dialog)
|
||||
UIManager:close(plus_dialog)
|
||||
self:goHome()
|
||||
end
|
||||
},
|
||||
@@ -694,7 +695,7 @@ function FileManager:tapPlus()
|
||||
{
|
||||
text = _("Open random document"),
|
||||
callback = function()
|
||||
UIManager:close(self.file_dialog)
|
||||
UIManager:close(plus_dialog)
|
||||
self:openRandomFile(self.file_chooser.path)
|
||||
end
|
||||
},
|
||||
@@ -715,7 +716,7 @@ function FileManager:tapPlus()
|
||||
and _("Switch to SDCard") or _("Switch to internal storage")
|
||||
end,
|
||||
callback = function()
|
||||
UIManager:close(self.file_dialog)
|
||||
UIManager:close(plus_dialog)
|
||||
if Device:isValidPath(self.file_chooser.path) then
|
||||
local ok, sd_path = Device:hasExternalSD()
|
||||
if ok then
|
||||
@@ -735,21 +736,27 @@ function FileManager:tapPlus()
|
||||
text = _("Import files here"),
|
||||
enabled = Device:isValidPath(self.file_chooser.path),
|
||||
callback = function()
|
||||
UIManager:close(self.file_dialog)
|
||||
UIManager:close(plus_dialog)
|
||||
Device.importFile(self.file_chooser.path)
|
||||
end,
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
local extract_button = self.coverbrowser and self.coverbrowser:genExtractBookInfoButton(close_dialog_callback)
|
||||
if extract_button ~= nil then
|
||||
table.insert(buttons, {}) -- separator
|
||||
table.insert(buttons, extract_button)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
self.file_dialog = ButtonDialog:new{
|
||||
plus_dialog = ButtonDialog:new{
|
||||
title = title,
|
||||
title_align = "center",
|
||||
buttons = buttons,
|
||||
select_mode = self.selected_files and true or nil, -- for coverbrowser
|
||||
}
|
||||
UIManager:show(self.file_dialog)
|
||||
UIManager:show(plus_dialog)
|
||||
end
|
||||
|
||||
function FileManager:reinit(path, focused_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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user