2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2013-10-22 15:11:31 +00:00
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
|
|
|
local Menu = require("ui/widget/menu")
|
2014-01-22 18:03:44 +00:00
|
|
|
local ButtonDialog = require("ui/widget/buttondialog")
|
2013-10-18 20:38:07 +00:00
|
|
|
local Screen = require("ui/screen")
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local DocSettings = require("docsettings")
|
2013-12-01 12:41:52 +00:00
|
|
|
local DEBUG = require("dbg")
|
2013-10-18 20:38:07 +00:00
|
|
|
local _ = require("gettext")
|
|
|
|
|
2014-01-22 18:03:44 +00:00
|
|
|
local history_dir = "./history/"
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local FileManagerHistory = InputContainer:extend{
|
2013-08-14 09:29:05 +00:00
|
|
|
hist_menu_title = _("History"),
|
|
|
|
}
|
|
|
|
|
|
|
|
function FileManagerHistory:init()
|
|
|
|
self.ui.menu:registerToMainMenu(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileManagerHistory:onSetDimensions(dimen)
|
|
|
|
self.dimen = dimen
|
|
|
|
end
|
|
|
|
|
2014-01-22 18:03:44 +00:00
|
|
|
function FileManagerHistory:onMenuHold(item)
|
|
|
|
self.histfile_dialog = ButtonDialog:new{
|
|
|
|
buttons = {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
text = _("Delete"),
|
|
|
|
callback = function()
|
|
|
|
os.remove(history_dir..item.histfile)
|
|
|
|
self._manager:updateItemTable()
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
UIManager:show(self.histfile_dialog)
|
|
|
|
return true
|
|
|
|
end
|
2013-08-14 09:29:05 +00:00
|
|
|
|
2014-01-22 18:03:44 +00:00
|
|
|
function FileManagerHistory:onShowHist()
|
2013-08-14 09:29:05 +00:00
|
|
|
local menu_container = CenterContainer:new{
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
}
|
|
|
|
|
2014-01-22 18:03:44 +00:00
|
|
|
self.hist_menu = Menu:new{
|
2013-08-14 09:29:05 +00:00
|
|
|
ui = self.ui,
|
|
|
|
width = Screen:getWidth()-50,
|
|
|
|
height = Screen:getHeight()-50,
|
|
|
|
show_parent = menu_container,
|
2014-01-22 18:03:44 +00:00
|
|
|
onMenuHold = self.onMenuHold,
|
|
|
|
_manager = self,
|
2013-08-14 09:29:05 +00:00
|
|
|
}
|
2014-01-22 18:03:44 +00:00
|
|
|
self:updateItemTable()
|
2013-08-14 09:29:05 +00:00
|
|
|
|
2014-01-22 18:03:44 +00:00
|
|
|
table.insert(menu_container, self.hist_menu)
|
2013-08-14 09:29:05 +00:00
|
|
|
|
2014-01-22 18:03:44 +00:00
|
|
|
self.hist_menu.close_callback = function()
|
2013-08-14 09:29:05 +00:00
|
|
|
UIManager:close(menu_container)
|
|
|
|
end
|
|
|
|
|
|
|
|
UIManager:show(menu_container)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileManagerHistory:addToMainMenu(tab_item_table)
|
|
|
|
-- insert table to main reader menu
|
|
|
|
table.insert(tab_item_table.main, {
|
|
|
|
text = self.hist_menu_title,
|
|
|
|
callback = function()
|
|
|
|
self:onShowHist()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileManagerHistory:updateItemTable()
|
2013-12-01 12:41:52 +00:00
|
|
|
function readHistDir(re)
|
|
|
|
local sorted_files = {}
|
|
|
|
for f in lfs.dir(history_dir) do
|
|
|
|
local path = history_dir..f
|
|
|
|
if lfs.attributes(path, "mode") == "file" then
|
|
|
|
table.insert(sorted_files, {file = f, date = lfs.attributes(path, "modification")})
|
|
|
|
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),
|
2014-01-22 18:03:44 +00:00
|
|
|
histfile = v.file,
|
2013-12-01 12:41:52 +00:00
|
|
|
})
|
2013-08-14 09:29:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
self.hist = {}
|
|
|
|
local last_files = {}
|
2013-12-01 12:41:52 +00:00
|
|
|
readHistDir(last_files)
|
2013-08-14 09:29:05 +00:00
|
|
|
for _,v in pairs(last_files) do
|
|
|
|
table.insert(self.hist, {
|
|
|
|
text = v.name,
|
2014-01-22 18:03:44 +00:00
|
|
|
histfile = v.histfile,
|
2013-08-14 09:29:05 +00:00
|
|
|
callback = function()
|
|
|
|
showReaderUI(v.dir .. "/" .. v.name)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
2014-01-22 18:03:44 +00:00
|
|
|
self.hist_menu:swithItemTable(self.hist_menu_title, self.hist)
|
2013-08-14 09:29:05 +00:00
|
|
|
end
|
|
|
|
|
2014-01-22 18:03:44 +00:00
|
|
|
return FileManagerHistory
|