mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
inputdialog(feat): add is_enter_default attribute to buttons
This commit is contained in:
@@ -143,11 +143,11 @@ function FileManagerMenu:setUpdateItemTable()
|
||||
},
|
||||
{
|
||||
text = _("Save"),
|
||||
is_enter_default = true,
|
||||
callback = save_folder_path,
|
||||
},
|
||||
}
|
||||
},
|
||||
enter_callback = save_folder_path,
|
||||
}
|
||||
ss_folder_path_input:onShowKeyboard()
|
||||
UIManager:show(ss_folder_path_input)
|
||||
|
||||
@@ -163,6 +163,7 @@ function SetDefaults:init()
|
||||
{
|
||||
text = _("OK"),
|
||||
enabled = true,
|
||||
is_enter_default = true,
|
||||
callback = function()
|
||||
local new_table = {}
|
||||
for _, field in ipairs(MultiInputDialog:getFields()) do
|
||||
@@ -205,6 +206,7 @@ function SetDefaults:init()
|
||||
cancel_button,
|
||||
{
|
||||
text = _("OK"),
|
||||
is_enter_default = true,
|
||||
enabled = true,
|
||||
callback = function()
|
||||
local new_value = self.set_dialog:getInputText()
|
||||
|
||||
@@ -27,6 +27,7 @@ function ReaderGoto:onShowGotoDialog()
|
||||
if self.document.info.has_pages then
|
||||
dialog_title = _("Go to Page")
|
||||
goto_btn = {
|
||||
is_enter_default = true,
|
||||
text = _("Page"),
|
||||
callback = function() self:gotoPage() end,
|
||||
}
|
||||
@@ -34,6 +35,7 @@ function ReaderGoto:onShowGotoDialog()
|
||||
else
|
||||
dialog_title = _("Go to Location")
|
||||
goto_btn = {
|
||||
is_enter_default = true,
|
||||
text = _("Location"),
|
||||
callback = function() self:gotoPage() end,
|
||||
}
|
||||
@@ -56,7 +58,6 @@ function ReaderGoto:onShowGotoDialog()
|
||||
},
|
||||
},
|
||||
input_type = "number",
|
||||
enter_callback = function() self:gotoPage() end,
|
||||
}
|
||||
self.goto_dialog:onShowKeyboard()
|
||||
UIManager:show(self.goto_dialog)
|
||||
|
||||
@@ -534,6 +534,7 @@ function BookStatusWidget:onSwitchFocus(inputbox)
|
||||
},
|
||||
{
|
||||
text = _("OK"),
|
||||
is_enter_default = true,
|
||||
callback = function()
|
||||
self.input_note:setText(self.note_dialog:getInputText())
|
||||
self:closeInputDialog()
|
||||
@@ -542,9 +543,6 @@ function BookStatusWidget:onSwitchFocus(inputbox)
|
||||
},
|
||||
},
|
||||
},
|
||||
enter_callback = function()
|
||||
self:closeInputDialog()
|
||||
end,
|
||||
}
|
||||
self.note_dialog:onShowKeyboard()
|
||||
UIManager:show(self.note_dialog)
|
||||
|
||||
@@ -26,21 +26,26 @@ local ButtonTable = FocusManager:new{
|
||||
}
|
||||
|
||||
function ButtonTable:init()
|
||||
self.buttons_layout = {}
|
||||
self.container = VerticalGroup:new{ width = self.width }
|
||||
table.insert(self, self.container)
|
||||
if self.zero_sep then
|
||||
self:addHorizontalSep()
|
||||
end
|
||||
for i = 1, #self.buttons do
|
||||
local row_cnt = #self.buttons
|
||||
for i = 1, row_cnt do
|
||||
self.buttons_layout[i] = {}
|
||||
local horizontal_group = HorizontalGroup:new{}
|
||||
local line = self.buttons[i]
|
||||
local sizer_space = self.sep_width * (#line - 1) + 2
|
||||
for j = 1, #line do
|
||||
local row = self.buttons[i]
|
||||
local column_cnt = #row
|
||||
local sizer_space = self.sep_width * (column_cnt - 1) + 2
|
||||
for j = 1, column_cnt do
|
||||
local btn_entry = row[j]
|
||||
local button = Button:new{
|
||||
text = line[j].text,
|
||||
enabled = line[j].enabled,
|
||||
callback = line[j].callback,
|
||||
width = (self.width - sizer_space)/#line,
|
||||
text = btn_entry.text,
|
||||
enabled = btn_entry.enabled,
|
||||
callback = btn_entry.callback,
|
||||
width = (self.width - sizer_space)/column_cnt,
|
||||
bordersize = 0,
|
||||
margin = 0,
|
||||
padding = 0,
|
||||
@@ -56,19 +61,19 @@ function ButtonTable:init()
|
||||
h = button_dim.h,
|
||||
}
|
||||
}
|
||||
self.buttons[i][j] = button
|
||||
self.buttons_layout[i][j] = button
|
||||
table.insert(horizontal_group, button)
|
||||
if j < #line then
|
||||
if j < column_cnt then
|
||||
table.insert(horizontal_group, vertical_sep)
|
||||
end
|
||||
end -- end for each button
|
||||
table.insert(self.container, horizontal_group)
|
||||
if i < #self.buttons then
|
||||
if i < row_cnt then
|
||||
self:addHorizontalSep()
|
||||
end
|
||||
end -- end for each button line
|
||||
if Device:hasDPad() then
|
||||
self.layout = self.buttons
|
||||
if Device:hasDPad() or Device:hasKeyboard() then
|
||||
self.layout = self.buttons_layout
|
||||
self.layout[1][1]:onFocus()
|
||||
self.key_events.SelectByKeyPress = { {{"Press", "Enter"}} }
|
||||
else
|
||||
|
||||
@@ -116,6 +116,7 @@ function InputContainer:onInput(input)
|
||||
},
|
||||
{
|
||||
text = _("OK"),
|
||||
is_enter_default = true,
|
||||
callback = function()
|
||||
input.callback(self.input_dialog:getInputText())
|
||||
self:closeInputDialog()
|
||||
@@ -123,10 +124,6 @@ function InputContainer:onInput(input)
|
||||
},
|
||||
},
|
||||
},
|
||||
enter_callback = function()
|
||||
input.callback(self.input_dialog:getInputText())
|
||||
self:closeInputDialog()
|
||||
end,
|
||||
}
|
||||
self.input_dialog:onShowKeyboard()
|
||||
UIManager:show(self.input_dialog)
|
||||
|
||||
@@ -413,6 +413,7 @@ function DictQuickLookup:lookupInputWord(hint)
|
||||
},
|
||||
{
|
||||
text = _("Lookup"),
|
||||
is_enter_default = true,
|
||||
callback = function()
|
||||
self:closeInputDialog()
|
||||
self:inputLookup()
|
||||
@@ -420,10 +421,6 @@ function DictQuickLookup:lookupInputWord(hint)
|
||||
},
|
||||
}
|
||||
},
|
||||
enter_callback = function()
|
||||
self:closeInputDialog()
|
||||
self:inputLookup()
|
||||
end,
|
||||
}
|
||||
self.input_dialog:onShowKeyboard()
|
||||
UIManager:show(self.input_dialog)
|
||||
|
||||
@@ -6,9 +6,6 @@ Example:
|
||||
local _ = require("gettext")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local sample_input
|
||||
local saveHandler = function()
|
||||
print('Got user input:', sample_input:getInputText())
|
||||
end
|
||||
sample_input = InputDialog:new{
|
||||
title = _("Dialog title"),
|
||||
input = "default value",
|
||||
@@ -24,11 +21,15 @@ Example:
|
||||
},
|
||||
{
|
||||
text = _("Save"),
|
||||
callback = saveHandler,
|
||||
-- button with is_enter_default set to true will be
|
||||
-- triggered after user press the enter key from keyboard
|
||||
is_enter_default = true,
|
||||
callback = function()
|
||||
print('Got user input:', sample_input:getInputText())
|
||||
end,
|
||||
},
|
||||
}
|
||||
},
|
||||
enter_callback = saveHandler,
|
||||
}
|
||||
sample_input:onShowKeyboard()
|
||||
UIManager:show(sample_input)
|
||||
@@ -95,6 +96,7 @@ function InputDialog:init()
|
||||
width = self.width,
|
||||
}
|
||||
}
|
||||
|
||||
self._input_widget = InputText:new{
|
||||
text = self.input,
|
||||
hint = self.input_hint,
|
||||
@@ -103,7 +105,17 @@ function InputDialog:init()
|
||||
height = self.text_height or nil,
|
||||
input_type = self.input_type,
|
||||
text_type = self.text_type,
|
||||
enter_callback = self.enter_callback,
|
||||
enter_callback = self.enter_callback or function()
|
||||
for _,btn_row in ipairs(self.buttons) do
|
||||
for _,btn in ipairs(btn_row) do
|
||||
require('dbg')('looging for btn', btn)
|
||||
if btn.is_enter_default then
|
||||
btn.callback()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
scroll = false,
|
||||
parent = self,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user