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:
parent
e10a101a4a
commit
e7c9a60d61
2 changed files with 16 additions and 3 deletions
|
|
@ -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.
|
--- Open a file explorer to select a file.
|
||||||
-- string title: title of the file explorer.
|
-- string title: title of the file explorer.
|
||||||
-- string curdir: the directory to initially open the file explorer in, or nil for the current directory.
|
-- 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
|
-- Variables
|
||||||
local sel = 1
|
local sel = 1
|
||||||
local scroll = 0
|
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
|
if curdir ~= "/" then table.insert(files, 1, { name = "..", isDirectory = true }) end
|
||||||
local newFileName = ""
|
local newFileName = ""
|
||||||
|
|
||||||
|
|
@ -59,7 +72,7 @@ return function(title, curdir, exts, type)
|
||||||
|
|
||||||
sel = 1
|
sel = 1
|
||||||
scroll = 0
|
scroll = 0
|
||||||
files = ctr.fs.list(curdir)
|
files = sort(ctr.fs.list(curdir))
|
||||||
|
|
||||||
if curdir ~= "/" then
|
if curdir ~= "/" then
|
||||||
table.insert(files, 1, { name = "..", isDirectory = true })
|
table.insert(files, 1, { name = "..", isDirectory = true })
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ const char* prefix_path(const char* path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
Lists a directory contents.
|
Lists a directory contents (unsorted).
|
||||||
@function list
|
@function list
|
||||||
@tparam string path the directory we wants to list the content
|
@tparam string path the directory we wants to list the content
|
||||||
@treturn table the item list. Each item is a table like:
|
@treturn table the item list. Each item is a table like:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue