From 092649338bbb65a3ed38fedee6bca2fc47bd2b6b Mon Sep 17 00:00:00 2001 From: mbays Date: Sun, 4 Aug 2024 00:00:00 +0000 Subject: [PATCH] InputDialog: add setAllowNewline --- frontend/ui/widget/inputdialog.lua | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/frontend/ui/widget/inputdialog.lua b/frontend/ui/widget/inputdialog.lua index 82b52dcea..461e065c3 100644 --- a/frontend/ui/widget/inputdialog.lua +++ b/frontend/ui/widget/inputdialog.lua @@ -336,6 +336,16 @@ function InputDialog:init() self._top_line_num, self._charpos = top_line_num, charpos end end + self.enter_callback = self.enter_callback or function() + for _, btn_row in ipairs(self.buttons) do + for _, btn in ipairs(btn_row) do + if btn.is_enter_default then + btn.callback() + return + end + end + end + end self._input_widget = self.inputtext_class:new{ text = self.input, hint = self.input_hint, @@ -352,16 +362,7 @@ function InputDialog:init() margin = self.input_margin, input_type = self.input_type, text_type = self.text_type, - enter_callback = self.enter_callback or function() - for _,btn_row in ipairs(self.buttons) do - for _,btn in ipairs(btn_row) do - if btn.is_enter_default then - btn.callback() - return - end - end - end - end, + enter_callback = not self.allow_newline and self.enter_callback, strike_callback = self.strike_callback, edit_callback = self._buttons_edit_callback or self.edited_callback, -- self._buttons_edit_callback is nil if no Save/Close buttons scroll_callback = self._buttons_scroll_callback, -- nil if no Nav or Scroll buttons @@ -375,9 +376,6 @@ function InputDialog:init() charpos = self._charpos, } table.insert(self.layout[1], self._input_widget) - if self.allow_newline then -- remove any enter_callback - self._input_widget.enter_callback = nil - end self:mergeLayoutInVertical(self.button_table) self:refocusWidget() -- Complementary setup for some of our added buttons @@ -544,6 +542,11 @@ function InputDialog:isTextEdited() return self._input_widget:isTextEdited() end +function InputDialog:setAllowNewline(allow) + self.allow_newline = allow + self._input_widget.enter_callback = not allow and self.enter_callback +end + function InputDialog:onShow() UIManager:setDirty(self, function() return "ui", self.dialog_frame.dimen