Modal and Form updates

- adding ReturnFromModal method to FormBase, will get invoked if context leaves a ModalDialog
- ModalDialog contains ParentForm for better navigation
- ModalDialog invokes ReturnFromModal on parentForm after closing
- adding ShowBackButton to PromptDialog for show a back button
This commit is contained in:
FlorianDahn
2020-04-04 19:52:15 +07:00
parent 7a3e4721bd
commit 8b9929198a
3 changed files with 38 additions and 2 deletions
+6 -2
View File
@@ -7,18 +7,22 @@ namespace TelegramBotBase.Form
{
public class ModalDialog : FormBase
{
/// <summary>
/// Contains the parent from where the modal dialog has been opened.
/// </summary>
public FormBase ParentForm { get; set; }
/// <summary>
/// This is a modal only function and does everything to close this form.
/// </summary>
public async Task CloseForm()
{
await this.CloseControls();
await this.OnClosed(new EventArgs());
this.ParentForm?.ReturnFromModal(this);
}
}
}
+19
View File
@@ -4,6 +4,7 @@ using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telegram.Bot.Types.ReplyMarkups;
using TelegramBotBase.Base;
namespace TelegramBotBase.Form
@@ -18,6 +19,9 @@ namespace TelegramBotBase.Form
private static object __evCompleted { get; } = new object();
public bool ShowBackButton { get; set; } = false;
public String BackLabel { get; set; } = "Zurück";
public PromptDialog()
{
@@ -34,6 +38,13 @@ namespace TelegramBotBase.Form
if (message.Handled)
return;
if (this.ShowBackButton && message.MessageText == BackLabel)
{
await this.CloseForm();
return;
}
if (this.Value == null)
{
this.Value = message.MessageText;
@@ -47,6 +58,14 @@ namespace TelegramBotBase.Form
if (this.Value == null)
{
if (this.ShowBackButton)
{
ButtonForm bf = new ButtonForm();
bf.AddButtonRow(new ButtonBase(BackLabel, "back"));
await this.Device.Send(this.Message, (ReplyMarkupBase)bf);
return;
}
await this.Device.Send(this.Message);
return;
}