sort history file with modification time

pull/381/head
chrox 11 years ago
parent 84ad0f2307
commit e4c77c272a

@ -4,6 +4,7 @@ local Menu = require("ui/widget/menu")
local Screen = require("ui/screen") local Screen = require("ui/screen")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local DocSettings = require("docsettings") local DocSettings = require("docsettings")
local DEBUG = require("dbg")
local _ = require("gettext") local _ = require("gettext")
local FileManagerHistory = InputContainer:extend{ local FileManagerHistory = InputContainer:extend{
@ -55,22 +56,27 @@ function FileManagerHistory:addToMainMenu(tab_item_table)
end end
function FileManagerHistory:updateItemTable() function FileManagerHistory:updateItemTable()
function readHistDir(order_arg, re) function readHistDir(re)
for f in lfs.dir("./history") do local sorted_files = {}
local filemode = lfs.attributes(f, "mode") local history_dir = "./history/"
for f in lfs.dir(history_dir) do
if filemode ~= "directory" then -- we can't use filemode == "file" here, when it should be "file" it is actually nil, weird local path = history_dir..f
table.insert(re, { if lfs.attributes(path, "mode") == "file" then
dir = DocSettings:getPathFromHistory(f), table.insert(sorted_files, {file = f, date = lfs.attributes(path, "modification")})
name = DocSettings:getNameFromHistory(f), end
}) end
end table.sort(sorted_files, function(v1,v2) return v1.date > v2.date end)
for _, v in pairs(sorted_files) do
table.insert(re, {
dir = DocSettings:getPathFromHistory(v.file),
name = DocSettings:getNameFromHistory(v.file),
})
end end
end end
self.hist = {} self.hist = {}
local last_files = {} local last_files = {}
readHistDir("-c", last_files) readHistDir(last_files)
for _,v in pairs(last_files) do for _,v in pairs(last_files) do
table.insert(self.hist, { table.insert(self.hist, {
text = v.name, text = v.name,
@ -81,4 +87,4 @@ function FileManagerHistory:updateItemTable()
end end
end end
return FileManagerHistory return FileManagerHistory
Loading…
Cancel
Save