mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
refactoring to generic multiinputdialog
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local _ = require("gettext")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local InputDialog = require("ui/widget/inputdialog")
|
||||
local MultiInputDialog = require("ui/widget/multiinputdialog")
|
||||
@@ -10,6 +9,8 @@ local Screen = require("ui/screen")
|
||||
local Menu = require("ui/widget/menu")
|
||||
local Font = require("ui/font")
|
||||
local util = require("ffi/util")
|
||||
local DEBUG = require("dbg")
|
||||
local _ = require("gettext")
|
||||
|
||||
local SetDefaults = InputContainer:new{
|
||||
defaults_name = {},
|
||||
@@ -156,9 +157,16 @@ function SetDefaults:init()
|
||||
table.insert(self.results, {
|
||||
text = self:build_setting(i),
|
||||
callback = function()
|
||||
local fields = {}
|
||||
for m, n in util.orderedPairs(_G[self.defaults_name[i]]) do
|
||||
fields[m] = {
|
||||
text = tostring(m) .. " = " .. tostring(n),
|
||||
hint = "",
|
||||
}
|
||||
end
|
||||
self.set_dialog = MultiInputDialog:new{
|
||||
title = self.defaults_name[i] .. ":",
|
||||
field = _G[self.defaults_name[i]],
|
||||
fields = fields,
|
||||
buttons = {
|
||||
{
|
||||
{
|
||||
@@ -173,10 +181,13 @@ function SetDefaults:init()
|
||||
text = _("OK"),
|
||||
enabled = true,
|
||||
callback = function()
|
||||
|
||||
_G[self.defaults_name[i]] = MultiInputDialog:getCredential()
|
||||
|
||||
local fields = {}
|
||||
for _, field in ipairs(MultiInputDialog:getFields()) do
|
||||
fields[field:match("^[^= ]+")] = field:match("[^= ]+$")
|
||||
end
|
||||
_G[self.defaults_name[i]] = fields
|
||||
self.defaults_value[i] = "{"
|
||||
DEBUG(_G[self.defaults_name[i]])
|
||||
for k,v in util.orderedPairs(_G[self.defaults_name[i]]) do
|
||||
if tonumber(k) then
|
||||
self.defaults_value[i] = self.defaults_value[i] .. v .. ", "
|
||||
|
||||
@@ -17,12 +17,11 @@ local input_field
|
||||
local MultiInputDialog = InputDialog:extend{
|
||||
field = {},
|
||||
field_hint = {},
|
||||
fields = {},
|
||||
}
|
||||
|
||||
function MultiInputDialog:init()
|
||||
|
||||
-- init title and buttons in base class
|
||||
|
||||
InputDialog.init(self)
|
||||
local VerticalGroupData = VerticalGroup:new{
|
||||
align = "left",
|
||||
@@ -32,14 +31,14 @@ function MultiInputDialog:init()
|
||||
|
||||
input_field = {}
|
||||
local k = 0
|
||||
for i,j in util.orderedPairs(self.field) do
|
||||
for i, field in ipairs(self.fields) do
|
||||
k = k + 1
|
||||
input_field[k] = InputText:new{
|
||||
text = tostring(i) .. " = " .. tostring(j),
|
||||
hint = tostring(self.field_hint[j]) or "",
|
||||
text = field.text or "",
|
||||
hint = field.hint or "",
|
||||
face = self.input_face,
|
||||
width = self.width * 0.9,
|
||||
focused = true,
|
||||
focused = k == 1 and true or false,
|
||||
scroll = false,
|
||||
parent = self,
|
||||
}
|
||||
@@ -83,15 +82,12 @@ function MultiInputDialog:init()
|
||||
UIManager.full_refresh = true
|
||||
end
|
||||
|
||||
function MultiInputDialog:getCredential()
|
||||
local field = {}
|
||||
local dummy
|
||||
for i=1,#input_field do
|
||||
dummy = input_field[i].text
|
||||
field[dummy:match("^[^= ]+")] = dummy:match("[^= ]+$")
|
||||
function MultiInputDialog:getFields()
|
||||
local fields = {}
|
||||
for i=1, #input_field do
|
||||
table.insert(fields, input_field[i].text)
|
||||
end
|
||||
|
||||
return field
|
||||
return fields
|
||||
end
|
||||
|
||||
function MultiInputDialog:onSwitchFocus(inputbox)
|
||||
|
||||
Reference in New Issue
Block a user