mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Add 'input page number' function in filemanager
by holding on the page info label at the buttom of the filemanager
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local TextWidget = require("ui/widget/textwidget")
|
||||
local ImageWidget = require("ui/widget/imagewidget")
|
||||
local Font = require("ui/font")
|
||||
local Geom = require("ui/geometry")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
local FrameContainer = require("ui/widget/container/framecontainer")
|
||||
local CenterContainer = require("ui/widget/container/centercontainer")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local FrameContainer = require("ui/widget/container/framecontainer")
|
||||
local ImageWidget = require("ui/widget/imagewidget")
|
||||
local TextWidget = require("ui/widget/textwidget")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
local Blitbuffer = require("ffi/blitbuffer")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local Geom = require("ui/geometry")
|
||||
local Device = require("device")
|
||||
local Font = require("ui/font")
|
||||
local DEBUG = require("dbg")
|
||||
local _ = require("gettext")
|
||||
local Blitbuffer = require("ffi/blitbuffer")
|
||||
|
||||
--[[
|
||||
a button widget that shows text or a icon and handles callback when tapped
|
||||
@@ -29,6 +29,7 @@ local Button = InputContainer:new{
|
||||
width = nil,
|
||||
text_font_face = "cfont",
|
||||
text_font_size = 20,
|
||||
text_font_bold = true,
|
||||
}
|
||||
|
||||
function Button:init()
|
||||
@@ -36,7 +37,7 @@ function Button:init()
|
||||
self.label_widget = TextWidget:new{
|
||||
text = self.text,
|
||||
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)
|
||||
}
|
||||
else
|
||||
@@ -91,6 +92,18 @@ function Button:init()
|
||||
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()
|
||||
self[1].color = Blitbuffer.COLOR_BLACK
|
||||
return true
|
||||
@@ -165,6 +178,8 @@ function Button:onTapSelectButton()
|
||||
return "partial", self[1].dimen
|
||||
end)
|
||||
end)
|
||||
elseif self.tap_input then
|
||||
self:onInput(self.tap_input)
|
||||
end
|
||||
return true
|
||||
end
|
||||
@@ -172,6 +187,8 @@ end
|
||||
function Button:onHoldSelectButton()
|
||||
if self.enabled and self.hold_callback then
|
||||
self.hold_callback()
|
||||
elseif self.hold_input then
|
||||
self:onInput(self.hold_input)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
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 Event = require("ui/event")
|
||||
local DEBUG = require("dbg")
|
||||
local _ = require("gettext")
|
||||
|
||||
--[[
|
||||
an InputContainer is an WidgetContainer that handles input events
|
||||
@@ -93,4 +96,43 @@ function InputContainer:onGesture(ev)
|
||||
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
|
||||
|
||||
@@ -431,9 +431,25 @@ function Menu:init()
|
||||
self.page_info_first_chev:hide()
|
||||
self.page_info_last_chev:hide()
|
||||
|
||||
self.page_info_text = TextWidget:new{
|
||||
self.page_info_text = Button:new{
|
||||
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_first_chev,
|
||||
@@ -650,7 +666,7 @@ function Menu:updateItems(select_number)
|
||||
self.item_group[select_number]:onFocus()
|
||||
end
|
||||
-- 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_right_chev:showHide(self.page_num > 1)
|
||||
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_return_arrow:enableDisable(#self.paths > 0)
|
||||
else
|
||||
self.page_info_text.text = _("no choices available")
|
||||
self.page_info_text:setText(_("no choices available"))
|
||||
end
|
||||
|
||||
UIManager:setDirty("all", function()
|
||||
@@ -813,6 +829,12 @@ function Menu:onLastPage()
|
||||
return true
|
||||
end
|
||||
|
||||
function Menu:onGotoPage(page)
|
||||
self.page = page
|
||||
self:updateItems(1)
|
||||
return true
|
||||
end
|
||||
|
||||
function Menu:onSelect()
|
||||
self:onMenuSelect(self.item_table[(self.page-1)*self.perpage+self.selected.y])
|
||||
return true
|
||||
|
||||
@@ -7,7 +7,6 @@ local HorizontalGroup = require("ui/widget/horizontalgroup")
|
||||
local VerticalGroup = require("ui/widget/verticalgroup")
|
||||
local HorizontalSpan = require("ui/widget/horizontalspan")
|
||||
local VerticalSpan = require("ui/widget/verticalspan")
|
||||
local InputDialog = require("ui/widget/inputdialog")
|
||||
local TextWidget = require("ui/widget/textwidget")
|
||||
local LineWidget = require("ui/widget/linewidget")
|
||||
local IconButton = require("ui/widget/iconbutton")
|
||||
@@ -539,7 +538,7 @@ function TouchMenu:onMenuSelect(item)
|
||||
end
|
||||
if item.tap_input then
|
||||
self:closeMenu()
|
||||
self:onMenuInput(item.tap_input)
|
||||
self:onInput(item.tap_input)
|
||||
else
|
||||
local sub_item_table = item.sub_item_table
|
||||
if item.sub_item_table_func then
|
||||
@@ -578,7 +577,7 @@ function TouchMenu:onMenuHold(item)
|
||||
end
|
||||
if item.hold_input then
|
||||
self:closeMenu()
|
||||
self:onMenuInput(item.hold_input)
|
||||
self:onInput(item.hold_input)
|
||||
else
|
||||
local callback = item.hold_callback
|
||||
if item.hold_callback_func then
|
||||
@@ -594,44 +593,6 @@ function TouchMenu:onMenuHold(item)
|
||||
return true
|
||||
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)
|
||||
if ges_ev.pos:notIntersectWith(self.dimen) then
|
||||
self:closeMenu()
|
||||
|
||||
Reference in New Issue
Block a user