Flat file list (no subfolders) (#15425)
This commit is contained in:
1 parent
1bad43518a
commit
5e9f418559
4 files changed
+63
-12
No files matched your search
@@ -1361,6 +1361,7 @@ function FileManager:onShowFolderMenu()
|
||||
}}
|
||||
end
|
||||
|
||||
local curr_path = self.file_chooser.path
|
||||
local home_dir = filemanagerutil.getHomeFolder()
|
||||
local home_dir_shortened = G_reader_settings:nilOrTrue("shorten_home_dir")
|
||||
local home_dir_not_locked = G_reader_settings:nilOrFalse("lock_home_folder")
|
||||
@@ -1379,9 +1380,9 @@ function FileManager:onShowFolderMenu()
|
||||
table.insert(buttons, genButton(text, path))
|
||||
end
|
||||
-- other folders
|
||||
local indent = ""
|
||||
for part in self.file_chooser.path:gmatch("([^/]+)") do
|
||||
text = (#buttons == 0 and path or indent .. "└ ") .. part
|
||||
local indent = 0
|
||||
for part in curr_path:gmatch("([^/]+)") do
|
||||
text = (#buttons == 0 and path or (" "):rep(indent) .. "└ ") .. part
|
||||
path = path .. part .. "/"
|
||||
is_home = path == home_dir or path == home_dir .. "/"
|
||||
if not home_found and is_home then
|
||||
@@ -1392,7 +1393,33 @@ function FileManager:onShowFolderMenu()
|
||||
text = text .. home_dir_suffix
|
||||
end
|
||||
table.insert(buttons, genButton(text, path))
|
||||
indent = indent .. " "
|
||||
indent = indent + 1
|
||||
end
|
||||
end
|
||||
-- subfolders
|
||||
if FileChooser.show_flat_view then
|
||||
local subfolders = {}
|
||||
local ok, iter, dir_obj = pcall(lfs.dir, curr_path)
|
||||
if ok then
|
||||
for f in iter, dir_obj do
|
||||
if FileChooser.show_hidden or not util.stringStartsWith(f, ".") then
|
||||
local attributes = lfs.attributes(curr_path .. "/" .. f)
|
||||
if attributes and attributes.mode == "directory" and f ~= "." and f ~= ".."
|
||||
and self.file_chooser:show_dir(f) then
|
||||
table.insert(subfolders, f)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if #subfolders > 0 then
|
||||
if #subfolders > 1 then
|
||||
table.sort(subfolders, function(a, b) return ffiUtil.strcoll(a, b) end)
|
||||
end
|
||||
table.insert(buttons, {}) -- separator
|
||||
local prefix = (" "):rep(indent + 1) .. "└ "
|
||||
for _, f in ipairs(subfolders) do
|
||||
table.insert(buttons, genButton(prefix .. f, curr_path .. "/" .. f))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1669,6 +1696,13 @@ function FileManager:onSetMixedSorting(toggle)
|
||||
return true
|
||||
end
|
||||
|
||||
function FileManager:onSetFlatView(toggle)
|
||||
FileChooser.show_flat_view = toggle
|
||||
G_reader_settings:saveSetting("show_flat_view", toggle)
|
||||
self.file_chooser:refreshPath()
|
||||
return true
|
||||
end
|
||||
|
||||
function FileManager:onOpenNextOrPreviousFileInFolder(prev)
|
||||
local last_file = G_reader_settings:readSetting("lastfile")
|
||||
if not last_file then return true end
|
||||
|
||||
@@ -154,6 +154,11 @@ function FileManagerMenu:setUpdateItemTable()
|
||||
self.menu_items.filebrowser_settings = {
|
||||
text = _("Settings"),
|
||||
sub_item_table = {
|
||||
{
|
||||
text = _("Show all files from subfolders"),
|
||||
checked_func = function() return FileChooser.show_flat_view end,
|
||||
callback = function() FileChooser:toggleShowFilesMode("show_flat_view") end,
|
||||
},
|
||||
{
|
||||
text = _("Show hidden files"),
|
||||
checked_func = function() return FileChooser.show_hidden end,
|
||||
|
||||
@@ -144,15 +144,16 @@ local settingsList = {
|
||||
set_display_mode = {category="string", event="SetDisplayMode", title=_("Set display mode"), args_func=FileManager.getDisplayModeActions, filemanager=true},
|
||||
set_sort_by = {category="string", event="SetSortBy", title=_("Sort by"), args_func=FileManager.getSortByActions, filemanager=true},
|
||||
set_reverse_sorting = {category="string", event="SetReverseSorting", title=_("Reverse sorting"), args={true, false}, toggle={_("on"), _("off")}, filemanager=true},
|
||||
set_mixed_sorting = {category="string", event="SetMixedSorting", title=_("Folders and files mixed"), args={true, false}, toggle={_("on"), _("off")}, filemanager=true, separator=true},
|
||||
set_mixed_sorting = {category="string", event="SetMixedSorting", title=_("Folders and files mixed"), args={true, false}, toggle={_("on"), _("off")}, filemanager=true},
|
||||
set_flat_view = {category="string", event="SetFlatView", title=_("Show all files from subfolders"), args={true, false}, toggle={_("on"), _("off")}, filemanager=true, separator=true},
|
||||
----
|
||||
show_plus_menu = {category="none", event="ShowPlusMenu", title=_("Show plus menu"), filemanager=true},
|
||||
toggle_select_mode = {category="none", event="ToggleSelectMode", title=_("Toggle select mode"), filemanager=true},
|
||||
refresh_content = {category="none", event="RefreshContent", title=_("Refresh content"), filemanager=true},
|
||||
folder_shortcuts = {category="none", event="ShowFolderShortcutsDialog", title=_("Folder shortcuts"), filemanager=true},
|
||||
file_search = {category="none", event="ShowFileSearch", title=_("File search"), filemanager=true},
|
||||
file_search_results = {category="none", event="ShowSearchResults", title=_("Last file search results"), filemanager=true},
|
||||
----
|
||||
folder_shortcuts = {category="none", event="ShowFolderShortcutsDialog", title=_("Folder shortcuts"), filemanager=true},
|
||||
folder_up = {category="none", event="FolderUp", title=_("Folder up"), filemanager=true},
|
||||
fm_go_to = {category="none", event="ShowGotoDialog", title=_("Go to page"), filemanager=true},
|
||||
fm_back = {category="none", event="Back", title=_("Back"), filemanager=true, separator=true},
|
||||
@@ -404,14 +405,15 @@ local dispatcher_menu_order = {
|
||||
"set_sort_by",
|
||||
"set_reverse_sorting",
|
||||
"set_mixed_sorting",
|
||||
"set_flat_view",
|
||||
----
|
||||
"show_plus_menu",
|
||||
"toggle_select_mode",
|
||||
"refresh_content",
|
||||
"folder_shortcuts",
|
||||
"file_search",
|
||||
"file_search_results",
|
||||
----
|
||||
"folder_shortcuts",
|
||||
"folder_up",
|
||||
"fm_go_to",
|
||||
"fm_back",
|
||||
|
||||
@@ -20,6 +20,7 @@ local FileChooser = BookList:extend{
|
||||
show_path = true,
|
||||
parent = nil,
|
||||
show_filter = G_reader_settings:readSetting("show_filter", {}),
|
||||
show_flat_view = G_reader_settings:readSetting("show_flat_view", false), -- show all files from subfolders
|
||||
show_hidden = G_reader_settings:readSetting("show_hidden", false), -- folders/files starting with "."
|
||||
show_unsupported = G_reader_settings:readSetting("show_unsupported", false), -- set to true to ignore file_filter
|
||||
file_filter = nil, -- function defined in the caller, returns true for files to be shown
|
||||
@@ -105,6 +106,11 @@ end
|
||||
|
||||
function FileChooser:getList(path, collate)
|
||||
local dirs, files = {}, {}
|
||||
self:getPathList(path, collate, dirs, files)
|
||||
return dirs, files
|
||||
end
|
||||
|
||||
function FileChooser:getPathList(path, collate, dirs, files)
|
||||
-- lfs.dir directory without permission will give error
|
||||
local ok, iter, dir_obj = pcall(lfs.dir, path)
|
||||
if ok then
|
||||
@@ -116,10 +122,14 @@ function FileChooser:getList(path, collate)
|
||||
local item = true
|
||||
if attributes.mode == "directory" and f ~= "." and f ~= ".."
|
||||
and self:show_dir(f) then
|
||||
if collate then -- when collate == nil count only to display in folder mandatory
|
||||
item = self:getListItem(path, f, fullpath, attributes, collate)
|
||||
if FileChooser.show_flat_view then
|
||||
self:getPathList(fullpath, collate, dirs, files)
|
||||
else
|
||||
if collate then -- when collate == nil count only to display in folder mandatory
|
||||
item = self:getListItem(path, f, fullpath, attributes, collate)
|
||||
end
|
||||
table.insert(dirs, item)
|
||||
end
|
||||
table.insert(dirs, item)
|
||||
-- Always ignore macOS resource forks.
|
||||
elseif attributes.mode == "file" and not util.stringStartsWith(f, "._")
|
||||
and self:show_file(f, fullpath) then
|
||||
@@ -131,6 +141,7 @@ function FileChooser:getList(path, collate)
|
||||
end
|
||||
end
|
||||
else -- error, probably "permission denied"
|
||||
if FileChooser.show_flat_view then return end
|
||||
if unreadable_dir_content[path] then
|
||||
-- Add this dummy item that will be replaced with a message by genItemTable()
|
||||
table.insert(dirs, self:getListItem(path, "./.", path, {}))
|
||||
@@ -145,7 +156,6 @@ function FileChooser:getList(path, collate)
|
||||
end
|
||||
end
|
||||
end
|
||||
return dirs, files
|
||||
end
|
||||
|
||||
function FileChooser:getListItem(dirpath, f, fullpath, attributes, collate)
|
||||
@@ -381,7 +391,7 @@ function FileChooser:onFolderUp()
|
||||
end
|
||||
|
||||
function FileChooser:toggleShowFilesMode(mode)
|
||||
-- modes: "show_hidden", "show_unsupported"
|
||||
-- modes: "show_flat_view", "show_hidden", "show_unsupported"
|
||||
FileChooser[mode] = not FileChooser[mode]
|
||||
G_reader_settings:saveSetting(mode, FileChooser[mode])
|
||||
self:refreshPath()
|
||||
|
||||
Reference in new issue
Block a user