add menu to FileManager

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

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

@ -5,8 +5,62 @@ require "ui/ui"
require "ui/readerui" require "ui/readerui"
require "ui/filechooser" require "ui/filechooser"
require "ui/infomessage" require "ui/infomessage"
require "ui/button"
require "document/document" 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) function showReader(file, pass)
local document = DocumentRegistry:openDocument(file) local document = DocumentRegistry:openDocument(file)
if not document then if not document then
@ -23,11 +77,14 @@ function showReader(file, pass)
UIManager:show(reader) UIManager:show(reader)
end end
function showFileManager(path) function showHomePage(path)
local FileManager = FileChooser:new{ local FileManager = FileChooser:new{
title = "FileManager",
path = path, path = path,
dimen = Screen:getSize(), width = Screen:getWidth(),
height = Screen:getHeight(),
is_borderless = true, is_borderless = true,
has_close_button = false,
filter = function(filename) filter = function(filename)
if DocumentRegistry:getProvider(filename) then if DocumentRegistry:getProvider(filename) then
return true return true
@ -35,17 +92,22 @@ function showFileManager(path)
end end
} }
local HomePage = InputContainer:new{
FileManager,
HomeMenu,
}
function FileManager:onFileSelect(file) function FileManager:onFileSelect(file)
showReader(file) showReader(file)
return true return true
end end
function FileManager:onClose() function FileManager:onClose()
UIManager:quit() --UIManager:quit()
return true return true
end end
UIManager:show(FileManager) UIManager:show(HomePage)
end end
@ -106,7 +168,7 @@ Screen.native_rotation_mode = Screen.cur_rotation_mode
if ARGV[argidx] then if ARGV[argidx] then
if lfs.attributes(ARGV[argidx], "mode") == "directory" then if lfs.attributes(ARGV[argidx], "mode") == "directory" then
showFileManager(ARGV[argidx]) showHomePage(ARGV[argidx])
elseif lfs.attributes(ARGV[argidx], "mode") == "file" then elseif lfs.attributes(ARGV[argidx], "mode") == "file" then
showReader(ARGV[argidx]) showReader(ARGV[argidx])
end end

Loading…
Cancel
Save