- adding OpenModal/CloseModal features to leave a form open and "just" show a prompt and get back

- added new "ModalDialog" class to present modal forms
- updating examples for prompt dialog to use the modal feature
This commit is contained in:
FlorianDahn
2019-10-11 22:37:54 +02:00
parent 3bea2783b1
commit 9cbde4830e
5 changed files with 77 additions and 7 deletions
+47
View File
@@ -297,6 +297,53 @@ namespace TelegramBotBase.Form
await newForm.OnOpened(new EventArgs());
}
/// <summary>
/// Opens this form modal, but don't closes the original ones
/// </summary>
/// <param name="newForm"></param>
/// <returns></returns>
public async Task OpenModal(ModalDialog newForm, params object[] args)
{
DeviceSession ds = this.Device;
if (ds == null)
return;
var parentForm = this;
ds.FormSwitched = true;
ds.PreviousForm = ds.ActiveForm;
ds.ActiveForm = newForm;
newForm.Client = parentForm.Client;
newForm.Device = ds;
newForm.Closed += async (s, en) =>
{
await CloseModal(newForm, parentForm);
};
await newForm.OnInit(new InitEventArgs(args));
await newForm.OnOpened(new EventArgs());
}
public async Task CloseModal(ModalDialog modalForm, FormBase oldForm)
{
DeviceSession ds = this.Device;
if (ds == null)
return;
if (modalForm == null)
throw new Exception("No modal form");
ds.FormSwitched = true;
ds.PreviousForm = ds.ActiveForm;
ds.ActiveForm = oldForm;
}
/// <summary>
/// Adds a control to the formular and sets its ID and Device.
/// </summary>