FileManager: less lfs calls when selecting files (#11476)

reviewable/pr11491/r1
hius07 2 months ago committed by GitHub
parent 5939c82bcf
commit 72a6fa1e64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,7 +1,6 @@
local BD = require("ui/bidi")
local Blitbuffer = require("ffi/blitbuffer")
local ButtonDialog = require("ui/widget/buttondialog")
local CenterContainer = require("ui/widget/container/centercontainer")
local CheckButton = require("ui/widget/checkbutton")
local ConfirmBox = require("ui/widget/confirmbox")
local Device = require("device")
@ -171,14 +170,17 @@ function FileManager:setupLayout()
return true
end
function file_chooser:onFileSelect(file) -- luacheck: ignore
function file_chooser:onFileSelect(item) -- luacheck: ignore
local file = item.path
if file_manager.select_mode then
if file_manager.selected_files[file] then
file_manager.selected_files[file] = nil
item.dim = nil
else
file_manager.selected_files[file] = true
item.dim = true
end
self:refreshPath()
self:updateItems()
else
file_manager:openFile(file)
end
@ -234,7 +236,8 @@ function FileManager:setupLayout()
file_manager:onToggleSelectMode(true) -- no full screen refresh
if is_file then
file_manager.selected_files[file] = true
self:refreshPath()
item.dim = true
self:updateItems()
end
end,
},
@ -540,8 +543,7 @@ function FileManager:tapPlus()
text = _("Select all files in folder"),
callback = function()
UIManager:close(self.file_dialog)
self.file_chooser:selectAllFilesInFolder()
self:onRefresh()
self.file_chooser:selectAllFilesInFolder(true)
end,
},
{
@ -562,7 +564,7 @@ function FileManager:tapPlus()
for file in pairs (self.selected_files) do
self.selected_files[file] = nil
end
self:onRefresh()
self.file_chooser:selectAllFilesInFolder(false) -- undim
end,
},
{
@ -1326,25 +1328,22 @@ function FileManager:showSelectedFilesList()
end
table.sort(selected_files, sorting)
local menu_container = CenterContainer:new{
dimen = Screen:getSize(),
}
local menu = Menu:new{
local menu
menu = Menu:new{
title = T(_("Selected files (%1)"), #selected_files),
item_table = selected_files,
is_borderless = true,
is_popout = false,
truncate_left = true,
show_parent = menu_container,
onMenuSelect = function(_, item)
UIManager:close(menu_container)
UIManager:close(menu)
self.file_chooser:changeToPath(util.splitFilePathName(item.filepath), item.filepath)
end,
close_callback = function()
UIManager:close(menu_container)
UIManager:close(menu)
end,
}
table.insert(menu_container, menu)
menu:switchItemTable(T(_("Selected files (%1)"), #selected_files), selected_files)
UIManager:show(menu_container)
UIManager:show(menu)
end
function FileManager:showOpenWithDialog(file)

@ -571,7 +571,7 @@ function FileChooser:onMenuSelect(item)
-- parent directory of dir without permission get nil mode
-- we need to change to parent path in this case
if item.is_file then
self:onFileSelect(item.path)
self:onFileSelect(item)
else
self:changeToPath(item.path, item.is_go_up and self.path)
end
@ -583,7 +583,7 @@ function FileChooser:onMenuHold(item)
return true
end
function FileChooser:onFileSelect(file)
function FileChooser:onFileSelect(item)
UIManager:close(self)
return true
end
@ -620,12 +620,18 @@ end
-- Used in file manager select mode to select all files in a folder,
-- that are visible in all file browser pages, without subfolders.
function FileChooser:selectAllFilesInFolder()
function FileChooser:selectAllFilesInFolder(do_select)
for _, item in ipairs(self.item_table) do
if item.is_file then
self.filemanager.selected_files[item.path] = true
if do_select then
self.filemanager.selected_files[item.path] = true
item.dim = true
else
item.dim = nil
end
end
end
self:updateItems()
end
return FileChooser

Loading…
Cancel
Save