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

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

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

Loading…
Cancel
Save