FileManager: less lfs calls (#11452)

Use item info provided by FileChooser.
Also fix showing PathChooser with invalid path,
and fix issue when opening non-supported files.
reviewable/pr11463/r1^2
hius07 2 months ago committed by GitHub
parent 76bf85738a
commit 5d4747c593
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -185,18 +185,18 @@ function FileManager:setupLayout()
return true
end
function file_chooser:onFileHold(file)
function file_chooser:onFileHold(item)
if file_manager.select_mode then
file_manager:tapPlus()
else
self:showFileDialog(file)
self:showFileDialog(item)
end
end
function file_chooser:showFileDialog(file) -- luacheck: ignore
local is_file = isFile(file)
local is_folder = lfs.attributes(file, "mode") == "directory"
local is_not_parent_folder = BaseUtil.basename(file) ~= ".."
function file_chooser:showFileDialog(item) -- luacheck: ignore
local file = item.path
local is_file = item.is_file
local is_not_parent_folder = not item.is_go_up
local function close_dialog_callback()
UIManager:close(self.file_dialog)
@ -324,9 +324,7 @@ function FileManager:setupLayout()
},
})
end
end
if is_folder then
else -- folder
local folder = BaseUtil.realpath(file)
table.insert(buttons, {
{
@ -1495,7 +1493,7 @@ function FileManager:openFile(file, provider, doc_caller_callback, aux_caller_ca
if provider == nil then
provider = DocumentRegistry:getProvider(file, true) -- include auxiliary
end
if provider.order then -- auxiliary
if provider and provider.order then -- auxiliary
if aux_caller_callback then
aux_caller_callback()
end

@ -98,7 +98,7 @@ function DocumentRegistry:getProvider(file, include_aux)
return provider
end
-- highest weighted provider
return providers[1].provider
return providers and providers[1].provider
end
return self:getFallbackProvider()
end

@ -232,6 +232,9 @@ end
function FileChooser:init()
self.path_items = {}
if lfs.attributes(self.path, "mode") ~= "directory" then
self.path = G_reader_settings:readSetting("home_dir") or filemanagerutil.getDefaultDir()
end
self.item_table = self:genItemTableFromPath(self.path)
Menu.init(self) -- call parent's init()
end
@ -540,7 +543,7 @@ function FileChooser:onMenuSelect(item)
end
function FileChooser:onMenuHold(item)
self:onFileHold(item.path)
self:onFileHold(item)
return true
end
@ -549,7 +552,7 @@ function FileChooser:onFileSelect(file)
return true
end
function FileChooser:onFileHold(file)
function FileChooser:onFileHold(item)
return true
end

@ -242,10 +242,11 @@ function CoverMenu:updateItems(select_number)
-- Replace it with ours
-- This causes luacheck warning: "shadowing upvalue argument 'self' on line 34".
-- Ignoring it (as done in filemanager.lua for the same showFileDialog)
self.showFileDialog = function(self, file) -- luacheck: ignore
self.showFileDialog = function(self, item) -- luacheck: ignore
local file = item.path
-- Call original function: it will create a ButtonDialog
-- and store it as self.file_dialog, and UIManager:show() it.
self.showFileDialog_orig(self, file)
self.showFileDialog_orig(self, item)
local bookinfo = self.book_props -- getBookInfo(file) called by FileManager
if not bookinfo or bookinfo._is_directory then

Loading…
Cancel
Save