Add 'input page number' function in filemanager

by holding on the page info label at the buttom of the filemanager
pull/1484/head
chrox 9 years ago
parent ded6b89f4c
commit ebdd374c93

@ -1,16 +1,16 @@
local CenterContainer = require("ui/widget/container/centercontainer")
local InputContainer = require("ui/widget/container/inputcontainer") local InputContainer = require("ui/widget/container/inputcontainer")
local TextWidget = require("ui/widget/textwidget") local FrameContainer = require("ui/widget/container/framecontainer")
local ImageWidget = require("ui/widget/imagewidget") local ImageWidget = require("ui/widget/imagewidget")
local Font = require("ui/font") local TextWidget = require("ui/widget/textwidget")
local Geom = require("ui/geometry")
local GestureRange = require("ui/gesturerange") local GestureRange = require("ui/gesturerange")
local FrameContainer = require("ui/widget/container/framecontainer") local Blitbuffer = require("ffi/blitbuffer")
local CenterContainer = require("ui/widget/container/centercontainer")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local Geom = require("ui/geometry")
local Device = require("device") local Device = require("device")
local Font = require("ui/font")
local DEBUG = require("dbg") local DEBUG = require("dbg")
local _ = require("gettext") local _ = require("gettext")
local Blitbuffer = require("ffi/blitbuffer")
--[[ --[[
a button widget that shows text or a icon and handles callback when tapped a button widget that shows text or a icon and handles callback when tapped
@ -29,6 +29,7 @@ local Button = InputContainer:new{
width = nil, width = nil,
text_font_face = "cfont", text_font_face = "cfont",
text_font_size = 20, text_font_size = 20,
text_font_bold = true,
} }
function Button:init() function Button:init()
@ -36,7 +37,7 @@ function Button:init()
self.label_widget = TextWidget:new{ self.label_widget = TextWidget:new{
text = self.text, text = self.text,
fgcolor = Blitbuffer.gray(self.enabled and 1.0 or 0.5), fgcolor = Blitbuffer.gray(self.enabled and 1.0 or 0.5),
bold = true, bold = self.text_font_bold,
face = Font:getFace(self.text_font_face, self.text_font_size) face = Font:getFace(self.text_font_face, self.text_font_size)
} }
else else
@ -91,6 +92,18 @@ function Button:init()
end end
end end
function Button:setText(text)
self.text = text
self.width = nil
self:init()
end
function Button:setIcon(icon)
self.icon = icon
self.width = nil
self:init()
end
function Button:onFocus() function Button:onFocus()
self[1].color = Blitbuffer.COLOR_BLACK self[1].color = Blitbuffer.COLOR_BLACK
return true return true
@ -165,6 +178,8 @@ function Button:onTapSelectButton()
return "partial", self[1].dimen return "partial", self[1].dimen
end) end)
end) end)
elseif self.tap_input then
self:onInput(self.tap_input)
end end
return true return true
end end
@ -172,6 +187,8 @@ end
function Button:onHoldSelectButton() function Button:onHoldSelectButton()
if self.enabled and self.hold_callback then if self.enabled and self.hold_callback then
self.hold_callback() self.hold_callback()
elseif self.hold_input then
self:onInput(self.hold_input)
end end
return true return true
end end

@ -1,7 +1,10 @@
local WidgetContainer = require("ui/widget/container/widgetcontainer") local WidgetContainer = require("ui/widget/container/widgetcontainer")
local Event = require("ui/event") local UIManager = require("ui/uimanager")
local Screen = require("device").screen
local Geom = require("ui/geometry") local Geom = require("ui/geometry")
local Event = require("ui/event")
local DEBUG = require("dbg") local DEBUG = require("dbg")
local _ = require("gettext")
--[[ --[[
an InputContainer is an WidgetContainer that handles input events an InputContainer is an WidgetContainer that handles input events
@ -93,4 +96,43 @@ function InputContainer:onGesture(ev)
end end
end end
function InputContainer:onInput(input)
local InputDialog = require("ui/widget/inputdialog")
self.input_dialog = InputDialog:new{
title = input.title or "",
input_hint = input.hint_func and input.hint_func() or input.hint or "",
input_type = input.type or "number",
buttons = {
{
{
text = _("Cancel"),
callback = function()
self:closeInputDialog()
end,
},
{
text = _("OK"),
callback = function()
input.callback(self.input_dialog:getInputText())
self:closeInputDialog()
end,
},
},
},
enter_callback = function()
input.callback(self.input_dialog:getInputText())
self:closeInputDialog()
end,
width = Screen:getWidth() * 0.8,
height = Screen:getHeight() * 0.2,
}
self.input_dialog:onShowKeyboard()
UIManager:show(self.input_dialog)
end
function InputContainer:closeInputDialog()
self.input_dialog:onClose()
UIManager:close(self.input_dialog)
end
return InputContainer return InputContainer

@ -431,9 +431,25 @@ function Menu:init()
self.page_info_first_chev:hide() self.page_info_first_chev:hide()
self.page_info_last_chev:hide() self.page_info_last_chev:hide()
self.page_info_text = TextWidget:new{ self.page_info_text = Button:new{
text = "", text = "",
face = self.fface, hold_input = {
title = _("Input page number"),
type = "number",
hint_func = function()
return "(" .. "1 - " .. self.page_num .. ")"
end,
callback = function(input)
local page = tonumber(input)
if page >= 1 and page <= self.page_num then
self:onGotoPage(page)
end
end,
},
bordersize = 0,
text_font_face = "cfont",
text_font_size = 20,
text_font_bold = false,
} }
self.page_info = HorizontalGroup:new{ self.page_info = HorizontalGroup:new{
self.page_info_first_chev, self.page_info_first_chev,
@ -650,7 +666,7 @@ function Menu:updateItems(select_number)
self.item_group[select_number]:onFocus() self.item_group[select_number]:onFocus()
end end
-- update page information -- update page information
self.page_info_text.text = util.template(_("page %1 of %2"), self.page, self.page_num) self.page_info_text:setText(util.template(_("page %1 of %2"), self.page, self.page_num))
self.page_info_left_chev:showHide(self.page_num > 1) self.page_info_left_chev:showHide(self.page_num > 1)
self.page_info_right_chev:showHide(self.page_num > 1) self.page_info_right_chev:showHide(self.page_num > 1)
self.page_info_first_chev:showHide(self.page_num > 2) self.page_info_first_chev:showHide(self.page_num > 2)
@ -663,7 +679,7 @@ function Menu:updateItems(select_number)
self.page_info_last_chev:enableDisable(self.page < self.page_num) self.page_info_last_chev:enableDisable(self.page < self.page_num)
self.page_return_arrow:enableDisable(#self.paths > 0) self.page_return_arrow:enableDisable(#self.paths > 0)
else else
self.page_info_text.text = _("no choices available") self.page_info_text:setText(_("no choices available"))
end end
UIManager:setDirty("all", function() UIManager:setDirty("all", function()
@ -813,6 +829,12 @@ function Menu:onLastPage()
return true return true
end end
function Menu:onGotoPage(page)
self.page = page
self:updateItems(1)
return true
end
function Menu:onSelect() function Menu:onSelect()
self:onMenuSelect(self.item_table[(self.page-1)*self.perpage+self.selected.y]) self:onMenuSelect(self.item_table[(self.page-1)*self.perpage+self.selected.y])
return true return true

@ -7,7 +7,6 @@ local HorizontalGroup = require("ui/widget/horizontalgroup")
local VerticalGroup = require("ui/widget/verticalgroup") local VerticalGroup = require("ui/widget/verticalgroup")
local HorizontalSpan = require("ui/widget/horizontalspan") local HorizontalSpan = require("ui/widget/horizontalspan")
local VerticalSpan = require("ui/widget/verticalspan") local VerticalSpan = require("ui/widget/verticalspan")
local InputDialog = require("ui/widget/inputdialog")
local TextWidget = require("ui/widget/textwidget") local TextWidget = require("ui/widget/textwidget")
local LineWidget = require("ui/widget/linewidget") local LineWidget = require("ui/widget/linewidget")
local IconButton = require("ui/widget/iconbutton") local IconButton = require("ui/widget/iconbutton")
@ -539,7 +538,7 @@ function TouchMenu:onMenuSelect(item)
end end
if item.tap_input then if item.tap_input then
self:closeMenu() self:closeMenu()
self:onMenuInput(item.tap_input) self:onInput(item.tap_input)
else else
local sub_item_table = item.sub_item_table local sub_item_table = item.sub_item_table
if item.sub_item_table_func then if item.sub_item_table_func then
@ -578,7 +577,7 @@ function TouchMenu:onMenuHold(item)
end end
if item.hold_input then if item.hold_input then
self:closeMenu() self:closeMenu()
self:onMenuInput(item.hold_input) self:onInput(item.hold_input)
else else
local callback = item.hold_callback local callback = item.hold_callback
if item.hold_callback_func then if item.hold_callback_func then
@ -594,44 +593,6 @@ function TouchMenu:onMenuHold(item)
return true return true
end end
function TouchMenu:onMenuInput(input)
self.input_dialog = InputDialog:new{
title = input.title or "",
input_hint = input.hint or "",
input_type = input.type or "number",
buttons = {
{
{
text = _("Cancel"),
callback = function()
self:closeInputDialog()
end,
},
{
text = _("OK"),
callback = function()
input.callback(self.input_dialog:getInputText())
self:closeInputDialog()
end,
},
},
},
enter_callback = function()
input.callback(self.input_dialog:getInputText())
self:closeInputDialog()
end,
width = Screen:getWidth() * 0.8,
height = Screen:getHeight() * 0.2,
}
self.input_dialog:onShowKeyboard()
UIManager:show(self.input_dialog)
end
function TouchMenu:closeInputDialog()
self.input_dialog:onClose()
UIManager:close(self.input_dialog)
end
function TouchMenu:onTapCloseAllMenus(arg, ges_ev) function TouchMenu:onTapCloseAllMenus(arg, ges_ev)
if ges_ev.pos:notIntersectWith(self.dimen) then if ges_ev.pos:notIntersectWith(self.dimen) then
self:closeMenu() self:closeMenu()

Loading…
Cancel
Save