@@ -231,13 +231,14 @@ function listMode:BuildList()
231231 break
232232 end
233233 end
234- handle = NewFileSearch (main .buildPath .. self .subPath .. " *" , true )
234+ handle = NewFileSearch (main .buildPath .. self .subPath .. " *" , true )
235235 while handle do
236236 local folderName = handle :GetFileName ()
237237 t_insert (self .list , {
238238 folderName = folderName ,
239239 subPath = self .subPath ,
240240 fullFileName = main .buildPath .. self .subPath .. folderName ,
241+ modified = handle :GetFileModifiedTime ()
241242 })
242243 if not handle :NextFile () then
243244 break
@@ -249,35 +250,58 @@ end
249250function listMode :SortList ()
250251 local oldSelFileName = self .controls .buildList .selValue and self .controls .buildList .selValue .fileName
251252 table.sort (self .list , function (a , b )
252- if a . folderName and b .folderName then
253- return naturalSortCompare ( a . folderName , b .folderName )
254- elseif a . folderName and not b . folderName then
255- return true
256- elseif not a . folderName and b . folderName then
257- return false
258- end
253+ local a_is_folder = a .folderName ~= nil
254+ local b_is_folder = b .folderName ~= nil
255+
256+ if a_is_folder and not b_is_folder then return true end
257+ if not a_is_folder and b_is_folder then return false end
258+
259+
259260 if main .buildSortMode == " EDITED" then
260- return a .modified > b . modified
261- elseif main . buildSortMode == " CLASS " then
262- if a . className and not b . className then
263- return false
264- elseif not a . className and b . className then
265- return true
266- elseif a . className ~= b . className then
267- return a . className < b . className
268- elseif a . ascendClassName ~= b . ascendClassName then
269- return a . ascendClassName < b . ascendClassName
261+ local modA = a .modified or 0 -- Use 0 as fallback if modified time is nil
262+ local modB = b . modified or 0
263+ if modA ~= modB then
264+ return modA > modB -- Newest first maybe allow for inverting of order?
265+ end
266+ -- If modified times are the same or both 0 fall back to name sort
267+ if a_is_folder then
268+ return naturalSortCompare ( a . folderName , b . folderName )
269+ else
270+ return naturalSortCompare ( a . fileName , b . fileName )
270271 end
271- elseif main .buildSortMode == " LEVEL" then
272- if a .level and not b .level then
273- return false
274- elseif not a .level and b .level then
275- return true
272+ end
273+
274+ if a_is_folder then
275+ return naturalSortCompare (a .folderName , b .folderName )
276+ else
277+ if main .buildSortMode == " CLASS" then
278+ local a_has_class = a .className ~= nil
279+ local b_has_class = b .className ~= nil
280+ if not a_has_class and b_has_class then return true
281+ elseif a_has_class and not b_has_class then return false
282+ elseif a_has_class and b_has_class and a .className ~= b .className then
283+ return a .className < b .className
284+ end
285+
286+ local a_has_asc = a .ascendClassName ~= nil
287+ local b_has_asc = b .ascendClassName ~= nil
288+ if not a_has_asc and b_has_asc then return true
289+ elseif a_has_asc and not b_has_asc then return false
290+ elseif a_has_asc and b_has_asc and a .ascendClassName ~= b .ascendClassName then
291+ return a .ascendClassName < b .ascendClassName
292+ end
293+ return naturalSortCompare (a .fileName , b .fileName )
294+ elseif main .buildSortMode == " LEVEL" then
295+ if a .level and not b .level then return false
296+ elseif not a .level and b .level then return true
297+ elseif a .level and b .level then
298+ if a .level ~= b .level then return a .level < b .level end
299+ end
300+ return naturalSortCompare (a .fileName , b .fileName )
276301 else
277- return a . level < b . level
302+ return naturalSortCompare ( a . fileName , b . fileName )
278303 end
279304 end
280- return naturalSortCompare (a .fileName , b .fileName )
281305 end )
282306 if oldSelFileName then
283307 self .controls .buildList :SelByFileName (oldSelFileName )
0 commit comments