Merge pull request #733 from houqp/new_ui_code

add menu to filemanager
This commit is contained in:
Huang Xin
2013-02-03 03:38:03 -08:00
4 changed files with 82 additions and 22 deletions

View File

@@ -226,6 +226,8 @@ Menu = FocusManager:new{
-- set this to true to not paint as popup menu
is_borderless = false,
-- set this to true to add close button
has_close_button = true,
-- close_callback is a function, which is executed when menu is closed
-- it is usually set by the widget which creates the menu
close_callback = nil
@@ -307,10 +309,12 @@ function Menu:init()
-- start to set up input event callback --
------------------------------------------
if Device:isTouchDevice() then
table.insert(self.title_bar,
MenuCloseButton:new{
menu = self,
})
if self.has_close_button then
table.insert(self.title_bar,
MenuCloseButton:new{
menu = self,
})
end
self.ges_events.TapCloseAllMenus = {
GestureRange:new{
ges = "tap",
@@ -476,9 +480,13 @@ function Menu:onMenuSelect(item)
end
--[[
override this function to handle the choice
]]--
default to call item callback
override this function to handle the choice
--]]
function Menu:onMenuChoice(item)
if item.callback then
item.callback()
end
return true
end

View File

@@ -99,11 +99,6 @@ function ReaderFont:onShowFontMenu()
item_table = self.face_table,
width = Screen:getWidth() - 100,
}
function main_menu:onMenuChoice(item)
if item.callback then
item.callback()
end
end
-- build container
local menu_container = CenterContainer:new{
main_menu,

View File

@@ -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()
@@ -73,11 +73,6 @@ function ReaderMenu:onShowMenu()
item_table = self.item_table,
width = Screen:getWidth() - 100,
}
function main_menu:onMenuChoice(item)
if item.callback then
item.callback()
end
end
local menu_container = CenterContainer:new{
ignore = "height",

View File

@@ -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