From 6ad362d6987673f3e08097c864f18e54a19e9366 Mon Sep 17 00:00:00 2001 From: myk002 Date: Wed, 27 Apr 2022 11:51:46 -0700 Subject: [PATCH] return a reference to the created dialogs --- docs/changelog.txt | 1 + library/lua/gui/dialogs.lua | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 05fe533ba..9b449f4c9 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -90,6 +90,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - ``widgets.ToggleHotkeyLabel``: new ``CycleHotkeyLabel`` subclass that toggles between ``On`` and ``Off`` states - ``safe_index`` now properly handles lua sparse tables that are indexed by numbers - ``widgets``: unset values in ``frame_inset``-table default to ``0`` +- ``dialogs``: ``show*`` functions now return a reference to the created dialog # 0.47.05-r4 diff --git a/library/lua/gui/dialogs.lua b/library/lua/gui/dialogs.lua index 687c7176e..51f346bbd 100644 --- a/library/lua/gui/dialogs.lua +++ b/library/lua/gui/dialogs.lua @@ -69,22 +69,26 @@ function MessageBox:onInput(keys) end function showMessage(title, text, tcolor, on_close) - MessageBox{ + local mb = MessageBox{ frame_title = title, text = text, text_pen = tcolor, on_close = on_close - }:show() + } + mb:show() + return mb end function showYesNoPrompt(title, text, tcolor, on_accept, on_cancel) - MessageBox{ + local mb = MessageBox{ frame_title = title, text = text, text_pen = tcolor, on_accept = on_accept, on_cancel = on_cancel, - }:show() + } + mb:show() + return mb end InputBox = defclass(InputBox, MessageBox) @@ -133,7 +137,7 @@ function InputBox:onInput(keys) end function showInputPrompt(title, text, tcolor, input, on_input, on_cancel, min_width) - InputBox{ + local ib = InputBox{ frame_title = title, text = text, text_pen = tcolor, @@ -141,7 +145,9 @@ function showInputPrompt(title, text, tcolor, input, on_input, on_cancel, min_wi on_input = on_input, on_cancel = on_cancel, frame_width = min_width, - }:show() + } + ib:show() + return ib end ListBox = defclass(ListBox, MessageBox) @@ -201,7 +207,7 @@ function ListBox:init(info) on_submit2 = on_submit2, frame = { l = 0, r = 0}, frame_inset = self.list_frame_inset, - row_height = info.row_height, + row_height = self.row_height, } } end @@ -232,7 +238,7 @@ function ListBox:onInput(keys) end function showListPrompt(title, text, tcolor, choices, on_select, on_cancel, min_width, filter) - ListBox{ + local lb = ListBox{ frame_title = title, text = text, text_pen = tcolor, @@ -241,7 +247,9 @@ function showListPrompt(title, text, tcolor, choices, on_select, on_cancel, min_ on_cancel = on_cancel, frame_width = min_width, with_filter = filter, - }:show() + } + lb:show() + return lb end return _ENV