add menu to FileManager

pull/2/merge
Qingping Hou 11 years ago
parent 22c3043959
commit 2090dabf22

@ -55,7 +55,7 @@ function ReaderMenu:setUpdateItemTable()
end
table.insert(self.item_table, {
text = "Return to file browser",
text = "Return to file manager",
callback = function()
UIManager:close(self.menu_container)
self.ui:onClose()

@ -5,8 +5,62 @@ require "ui/ui"
require "ui/readerui"
require "ui/filechooser"
require "ui/infomessage"
require "ui/button"
require "document/document"
HomeMenu = InputContainer:new{
item_table = {},
ges_events = {
TapShowMenu = {
GestureRange:new{
ges = "tap",
range = Geom:new{
x = 0, y = 0,
w = Screen:getWidth(),
h = 25,
}
}
},
},
}
function HomeMenu:setUpdateItemTable()
table.insert(self.item_table, {
text = "Exit",
callback = function()
os.exit(0)
end
})
end
function HomeMenu:onTapShowMenu()
if #self.item_table == 0 then
self:setUpdateItemTable()
end
local home_menu = Menu:new{
title = "Home menu",
item_table = self.item_table,
width = Screen:getWidth() - 100,
}
local menu_container = CenterContainer:new{
ignore = "height",
dimen = Screen:getSize(),
home_menu,
}
home_menu.close_callback = function ()
UIManager:close(menu_container)
end
UIManager:show(menu_container)
return true
end
function showReader(file, pass)
local document = DocumentRegistry:openDocument(file)
if not document then
@ -23,11 +77,14 @@ function showReader(file, pass)
UIManager:show(reader)
end
function showFileManager(path)
function showHomePage(path)
local FileManager = FileChooser:new{
title = "FileManager",
path = path,
dimen = Screen:getSize(),
width = Screen:getWidth(),
height = Screen:getHeight(),
is_borderless = true,
has_close_button = false,
filter = function(filename)
if DocumentRegistry:getProvider(filename) then
return true
@ -35,17 +92,22 @@ function showFileManager(path)
end
}
local HomePage = InputContainer:new{
FileManager,
HomeMenu,
}
function FileManager:onFileSelect(file)
showReader(file)
return true
end
function FileManager:onClose()
UIManager:quit()
--UIManager:quit()
return true
end
UIManager:show(FileManager)
UIManager:show(HomePage)
end
@ -106,7 +168,7 @@ Screen.native_rotation_mode = Screen.cur_rotation_mode
if ARGV[argidx] then
if lfs.attributes(ARGV[argidx], "mode") == "directory" then
showFileManager(ARGV[argidx])
showHomePage(ARGV[argidx])
elseif lfs.attributes(ARGV[argidx], "mode") == "file" then
showReader(ARGV[argidx])
end

Loading…
Cancel
Save