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

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

@ -232,6 +232,9 @@ end
function FileChooser:init() function FileChooser:init()
self.path_items = {} 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) self.item_table = self:genItemTableFromPath(self.path)
Menu.init(self) -- call parent's init() Menu.init(self) -- call parent's init()
end end
@ -540,7 +543,7 @@ function FileChooser:onMenuSelect(item)
end end
function FileChooser:onMenuHold(item) function FileChooser:onMenuHold(item)
self:onFileHold(item.path) self:onFileHold(item)
return true return true
end end
@ -549,7 +552,7 @@ function FileChooser:onFileSelect(file)
return true return true
end end
function FileChooser:onFileHold(file) function FileChooser:onFileHold(item)
return true return true
end end

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

Loading…
Cancel
Save