add exit tip for mconfdialog

This commit is contained in:
ruki
2022-09-09 00:42:50 +08:00
parent 501e695576
commit ca0db88e3f

View File

@@ -53,7 +53,10 @@ Pressing <Y> includes, <N> excludes. Enter <Esc> or <Back> to go back, <?> for H
self:menuconf():on_event(event.command {"cm_back"}) self:menuconf():on_event(event.command {"cm_back"})
self:buttons():select(self:button("select")) self:buttons():select(self:button("select"))
end) end)
self:button_add("exit", "< Exit >", function (v, e) self:quit() end) self:button_add("exit", "< Exit >", function (v, e)
self:show_exit([[Did you wish to save your new configuration?
Pressing <Esc> to continue your configuration.]])
end)
self:button_add("help", "< Help >", function (v, e) self:show_help() end) self:button_add("help", "< Help >", function (v, e) self:show_help() end)
self:button_add("save", "< Save >", function (v, e) self:action_on(action.ac_on_save) end) self:button_add("save", "< Save >", function (v, e) self:action_on(action.ac_on_save) end)
self:buttons():select(self:button("select")) self:buttons():select(self:button("select"))
@@ -262,6 +265,24 @@ function mconfdialog:searchdialog()
return self._SEARCHDIALOG return self._SEARCHDIALOG
end end
-- get exit dialog
function mconfdialog:exitdialog()
if not self._EXITDIALOG then
local exitdialog = textdialog:new("mconfdialog.exit", rect{0, 0, math.min(80, self:width() - 8), math.min(8, self:height())}, "")
exitdialog:background_set(self:frame():background())
exitdialog:frame():background_set("cyan")
exitdialog:button_add("Yes", "< Yes >", function (v)
self:action_on(action.ac_on_save)
self:quit()
end)
exitdialog:button_add("No", "< No >", function (v) self:quit() end)
exitdialog:option_set("scrollable", false)
exitdialog:button_select("Yes")
self._EXITDIALOG = exitdialog
end
return self._EXITDIALOG
end
-- search configs via the given text -- search configs via the given text
function mconfdialog:search(configs, text) function mconfdialog:search(configs, text)
local results = {} local results = {}
@@ -340,6 +361,17 @@ function mconfdialog:show_result(text)
end end
end end
-- show exit dialog
function mconfdialog:show_exit(text)
local dialog_exit = self:exitdialog()
dialog_exit:text():text_set(text)
if not self:view("mconfdialog.exit") then
self:insert(dialog_exit, {centerx = true, centery = true})
else
self:select(dialog_exit)
end
end
-- on event -- on event
function mconfdialog:on_event(e) function mconfdialog:on_event(e)