1
0
Fork 0
mirror of https://github.com/ctruLua/ctruLua.git synced 2025-10-27 16:39:29 +00:00

Alphabetical sorting in openfile.lua

This commit is contained in:
Reuh 2015-12-31 15:54:10 +01:00
parent e10a101a4a
commit e7c9a60d61
2 changed files with 16 additions and 3 deletions

View file

@ -1,3 +1,15 @@
-- Sort ctr.fs.list returns (directories first and alphabetical sorting)
local function sort(files)
table.sort(files, function(i, j)
if i.isDirectory and not j.isDirectory then
return true
elseif i.isDirectory == j.isDirectory then
return string.lower(i.name) < string.lower(j.name)
end
end)
return files
end
--- Open a file explorer to select a file.
-- string title: title of the file explorer.
-- string curdir: the directory to initially open the file explorer in, or nil for the current directory.
@ -20,7 +32,8 @@ return function(title, curdir, exts, type)
-- Variables
local sel = 1
local scroll = 0
local files = ctr.fs.list(curdir)
local files = sort(ctr.fs.list(curdir))
if curdir ~= "/" then table.insert(files, 1, { name = "..", isDirectory = true }) end
local newFileName = ""
@ -59,7 +72,7 @@ return function(title, curdir, exts, type)
sel = 1
scroll = 0
files = ctr.fs.list(curdir)
files = sort(ctr.fs.list(curdir))
if curdir ~= "/" then
table.insert(files, 1, { name = "..", isDirectory = true })

View file

@ -48,7 +48,7 @@ const char* prefix_path(const char* path) {
}
/***
Lists a directory contents.
Lists a directory contents (unsorted).
@function list
@tparam string path the directory we wants to list the content
@treturn table the item list. Each item is a table like: