Sorting: adds Sort by name - mixed files and folders (#4140)

Also moves the 2 Sort by percent in a sub-menu
pull/4151/head
Robert 6 years ago committed by poire-z
parent adceda15b7
commit 7e6802737e

@ -743,6 +743,7 @@ function FileManager:getSortingMenuTable()
local fm = self
local collates = {
strcoll = {_("filename"), _("Sort by filename")},
strcoll_mixed = {_("name mixed"), _("Sort by name - mixed files and folders")},
access = {_("date read"), _("Sort by last read date")},
change = {_("date added"), _("Sort by date added")},
modification = {_("date modified"), _("Sort by date modified")},
@ -760,6 +761,14 @@ function FileManager:getSortingMenuTable()
callback = function() fm:setCollate(collate) end,
}
end
local get_collate_percent = function()
local collate_type = G_reader_settings:readSetting("collate")
if collate_type == "percent_unopened_first" or collate_type == "percent_unopened_last" then
return collates[collate_type][2]
else
return _("Sort by percent")
end
end
return {
text_func = function()
return util.template(
@ -769,13 +778,23 @@ function FileManager:getSortingMenuTable()
end,
sub_item_table = {
set_collate_table("strcoll"),
set_collate_table("strcoll_mixed"),
set_collate_table("access"),
set_collate_table("change"),
set_collate_table("modification"),
set_collate_table("size"),
set_collate_table("type"),
set_collate_table("percent_unopened_first"),
set_collate_table("percent_unopened_last"),
{
text_func = get_collate_percent,
checked_func = function()
return fm.file_chooser.collate == "percent_unopened_first"
or fm.file_chooser.collate == "percent_unopened_last"
end,
sub_item_table = {
set_collate_table("percent_unopened_first"),
set_collate_table("percent_unopened_last"),
}
},
}
}
end

@ -116,6 +116,7 @@ end
function FileChooser:genItemTableFromPath(path)
local dirs = {}
local files = {}
local up_folder_arrow = "⬆ ../"
self.list(path, dirs, files)
@ -190,10 +191,12 @@ function FileChooser:genItemTableFromPath(path)
sorting = function(a, b) return sorting_unreversed(b, a) end
end
table.sort(dirs, sorting)
if self.collate ~= "strcoll_mixed" then
table.sort(dirs, sorting)
table.sort(files, sorting)
end
if path ~= "/" then table.insert(dirs, 1, {name = ".."}) end
if self.show_current_dir_for_hold then table.insert(dirs, 1, {name = "."}) end
table.sort(files, sorting)
local item_table = {}
for i, dir in ipairs(dirs) do
@ -211,7 +214,7 @@ function FileChooser:genItemTableFromPath(path)
end
local text
if dir.name == ".." then
text = "⬆ ../"
text = up_folder_arrow
elseif dir.name == "." then -- possible with show_current_dir_for_hold
text = _("Long-press to select current directory")
else
@ -247,6 +250,18 @@ function FileChooser:genItemTableFromPath(path)
end
table.insert(item_table, file_item)
end
if self.collate == "strcoll_mixed" then
sorting = function(a, b)
if b.text == up_folder_arrow then return false end
return self.strcoll(a.text, b.text)
end
if self.reverse_collate then
local sorting_unreversed = sorting
sorting = function(a, b) return sorting_unreversed(b, a) end
end
table.sort(item_table, sorting)
end
-- lfs.dir iterated node string may be encoded with some weird codepage on
-- Windows we need to encode them to utf-8
if ffi.os == "Windows" then

Loading…
Cancel
Save