add last documents menu entry

pull/2/merge
Qingping Hou 11 years ago
parent bd8e9699eb
commit f22b2301fa

@ -15,6 +15,21 @@ function DocSettings:getHistoryPath(fullpath)
return "./history/["..basename:gsub("/","#").."] "..filename..".lua"
end
function DocSettings:getPathFromHistory(hist_name)
-- 1. select everything included in brackets
local s = string.match(hist_name,"%b[]")
-- 2. crop the bracket-sign from both sides
-- 3. and finally replace decorative signs '#' to dir-char '/'
return string.gsub(string.sub(s,2,-3),"#","/")
end
function DocSettings:getNameFromHistory(hist_name)
-- at first, search for path length
local s = string.len(string.match(hist_name,"%b[]"))
-- and return the rest of string without 4 last characters (".lua")
return string.sub(hist_name, s+2, -5)
end
function DocSettings:open(docfile)
local conf_path = nil
if docfile == ".reader" then

@ -27,6 +27,32 @@ HomeMenu = InputContainer:new{
}
function HomeMenu:setUpdateItemTable()
function readHistDir(order_arg, re)
local pipe_out = io.popen("ls "..order_arg.." -1 ./history")
for f in pipe_out:lines() do
table.insert(re, {
dir = DocSettings:getPathFromHistory(f),
name = DocSettings:getNameFromHistory(f),
})
end
end
local hist_sub_item_table = {}
local last_files = {}
readHistDir("-c", last_files)
for _,v in pairs(last_files) do
table.insert(hist_sub_item_table, {
text = v.name,
callback = function()
showReader(v.dir .. "/" .. v.name)
end
})
end
table.insert(self.item_table, {
text = "Last documents",
sub_item_table = hist_sub_item_table,
})
table.insert(self.item_table, {
text = "Exit",
callback = function()
@ -36,9 +62,8 @@ function HomeMenu:setUpdateItemTable()
end
function HomeMenu:onTapShowMenu()
if #self.item_table == 0 then
self:setUpdateItemTable()
end
self.item_table = {}
self:setUpdateItemTable()
local home_menu = Menu:new{
title = "Home menu",

Loading…
Cancel
Save