inputdialog(feat): add is_enter_default attribute to buttons

pull/2045/head
Qingping Hou 8 years ago
parent 60587e08c6
commit 476e35708d

@ -143,11 +143,11 @@ function FileManagerMenu:setUpdateItemTable()
}, },
{ {
text = _("Save"), text = _("Save"),
is_enter_default = true,
callback = save_folder_path, callback = save_folder_path,
}, },
} }
}, },
enter_callback = save_folder_path,
} }
ss_folder_path_input:onShowKeyboard() ss_folder_path_input:onShowKeyboard()
UIManager:show(ss_folder_path_input) UIManager:show(ss_folder_path_input)

@ -163,6 +163,7 @@ function SetDefaults:init()
{ {
text = _("OK"), text = _("OK"),
enabled = true, enabled = true,
is_enter_default = true,
callback = function() callback = function()
local new_table = {} local new_table = {}
for _, field in ipairs(MultiInputDialog:getFields()) do for _, field in ipairs(MultiInputDialog:getFields()) do
@ -205,6 +206,7 @@ function SetDefaults:init()
cancel_button, cancel_button,
{ {
text = _("OK"), text = _("OK"),
is_enter_default = true,
enabled = true, enabled = true,
callback = function() callback = function()
local new_value = self.set_dialog:getInputText() local new_value = self.set_dialog:getInputText()

@ -27,6 +27,7 @@ function ReaderGoto:onShowGotoDialog()
if self.document.info.has_pages then if self.document.info.has_pages then
dialog_title = _("Go to Page") dialog_title = _("Go to Page")
goto_btn = { goto_btn = {
is_enter_default = true,
text = _("Page"), text = _("Page"),
callback = function() self:gotoPage() end, callback = function() self:gotoPage() end,
} }
@ -34,6 +35,7 @@ function ReaderGoto:onShowGotoDialog()
else else
dialog_title = _("Go to Location") dialog_title = _("Go to Location")
goto_btn = { goto_btn = {
is_enter_default = true,
text = _("Location"), text = _("Location"),
callback = function() self:gotoPage() end, callback = function() self:gotoPage() end,
} }
@ -56,7 +58,6 @@ function ReaderGoto:onShowGotoDialog()
}, },
}, },
input_type = "number", input_type = "number",
enter_callback = function() self:gotoPage() end,
} }
self.goto_dialog:onShowKeyboard() self.goto_dialog:onShowKeyboard()
UIManager:show(self.goto_dialog) UIManager:show(self.goto_dialog)

@ -534,6 +534,7 @@ function BookStatusWidget:onSwitchFocus(inputbox)
}, },
{ {
text = _("OK"), text = _("OK"),
is_enter_default = true,
callback = function() callback = function()
self.input_note:setText(self.note_dialog:getInputText()) self.input_note:setText(self.note_dialog:getInputText())
self:closeInputDialog() self:closeInputDialog()
@ -542,9 +543,6 @@ function BookStatusWidget:onSwitchFocus(inputbox)
}, },
}, },
}, },
enter_callback = function()
self:closeInputDialog()
end,
} }
self.note_dialog:onShowKeyboard() self.note_dialog:onShowKeyboard()
UIManager:show(self.note_dialog) UIManager:show(self.note_dialog)

@ -26,21 +26,26 @@ local ButtonTable = FocusManager:new{
} }
function ButtonTable:init() function ButtonTable:init()
self.buttons_layout = {}
self.container = VerticalGroup:new{ width = self.width } self.container = VerticalGroup:new{ width = self.width }
table.insert(self, self.container) table.insert(self, self.container)
if self.zero_sep then if self.zero_sep then
self:addHorizontalSep() self:addHorizontalSep()
end 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 horizontal_group = HorizontalGroup:new{}
local line = self.buttons[i] local row = self.buttons[i]
local sizer_space = self.sep_width * (#line - 1) + 2 local column_cnt = #row
for j = 1, #line do 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{ local button = Button:new{
text = line[j].text, text = btn_entry.text,
enabled = line[j].enabled, enabled = btn_entry.enabled,
callback = line[j].callback, callback = btn_entry.callback,
width = (self.width - sizer_space)/#line, width = (self.width - sizer_space)/column_cnt,
bordersize = 0, bordersize = 0,
margin = 0, margin = 0,
padding = 0, padding = 0,
@ -56,19 +61,19 @@ function ButtonTable:init()
h = button_dim.h, h = button_dim.h,
} }
} }
self.buttons[i][j] = button self.buttons_layout[i][j] = button
table.insert(horizontal_group, button) table.insert(horizontal_group, button)
if j < #line then if j < column_cnt then
table.insert(horizontal_group, vertical_sep) table.insert(horizontal_group, vertical_sep)
end end
end -- end for each button end -- end for each button
table.insert(self.container, horizontal_group) table.insert(self.container, horizontal_group)
if i < #self.buttons then if i < row_cnt then
self:addHorizontalSep() self:addHorizontalSep()
end end
end -- end for each button line end -- end for each button line
if Device:hasDPad() then if Device:hasDPad() or Device:hasKeyboard() then
self.layout = self.buttons self.layout = self.buttons_layout
self.layout[1][1]:onFocus() self.layout[1][1]:onFocus()
self.key_events.SelectByKeyPress = { {{"Press", "Enter"}} } self.key_events.SelectByKeyPress = { {{"Press", "Enter"}} }
else else

@ -116,6 +116,7 @@ function InputContainer:onInput(input)
}, },
{ {
text = _("OK"), text = _("OK"),
is_enter_default = true,
callback = function() callback = function()
input.callback(self.input_dialog:getInputText()) input.callback(self.input_dialog:getInputText())
self:closeInputDialog() 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() self.input_dialog:onShowKeyboard()
UIManager:show(self.input_dialog) UIManager:show(self.input_dialog)

@ -413,6 +413,7 @@ function DictQuickLookup:lookupInputWord(hint)
}, },
{ {
text = _("Lookup"), text = _("Lookup"),
is_enter_default = true,
callback = function() callback = function()
self:closeInputDialog() self:closeInputDialog()
self:inputLookup() self:inputLookup()
@ -420,10 +421,6 @@ function DictQuickLookup:lookupInputWord(hint)
}, },
} }
}, },
enter_callback = function()
self:closeInputDialog()
self:inputLookup()
end,
} }
self.input_dialog:onShowKeyboard() self.input_dialog:onShowKeyboard()
UIManager:show(self.input_dialog) UIManager:show(self.input_dialog)

@ -6,9 +6,6 @@ Example:
local _ = require("gettext") local _ = require("gettext")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local sample_input local sample_input
local saveHandler = function()
print('Got user input:', sample_input:getInputText())
end
sample_input = InputDialog:new{ sample_input = InputDialog:new{
title = _("Dialog title"), title = _("Dialog title"),
input = "default value", input = "default value",
@ -24,11 +21,15 @@ Example:
}, },
{ {
text = _("Save"), 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() sample_input:onShowKeyboard()
UIManager:show(sample_input) UIManager:show(sample_input)
@ -95,6 +96,7 @@ function InputDialog:init()
width = self.width, width = self.width,
} }
} }
self._input_widget = InputText:new{ self._input_widget = InputText:new{
text = self.input, text = self.input,
hint = self.input_hint, hint = self.input_hint,
@ -103,7 +105,17 @@ function InputDialog:init()
height = self.text_height or nil, height = self.text_height or nil,
input_type = self.input_type, input_type = self.input_type,
text_type = self.text_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, scroll = false,
parent = self, parent = self,
} }

Loading…
Cancel
Save