diff --git a/TelegramBotBase/Base/FormBase.cs b/TelegramBotBase/Base/FormBase.cs
index 5535164..014ab72 100644
--- a/TelegramBotBase/Base/FormBase.cs
+++ b/TelegramBotBase/Base/FormBase.cs
@@ -297,6 +297,53 @@ namespace TelegramBotBase.Form
await newForm.OnOpened(new EventArgs());
}
+ ///
+ /// Opens this form modal, but don't closes the original ones
+ ///
+ ///
+ ///
+ 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;
+ }
+
///
/// Adds a control to the formular and sets its ID and Device.
///
diff --git a/TelegramBotBase/Form/ConfirmDialog.cs b/TelegramBotBase/Form/ConfirmDialog.cs
index 9081ced..acdb25e 100644
--- a/TelegramBotBase/Form/ConfirmDialog.cs
+++ b/TelegramBotBase/Form/ConfirmDialog.cs
@@ -8,7 +8,7 @@ using TelegramBotBase.Base;
namespace TelegramBotBase.Form
{
- public class ConfirmDialog : FormBase
+ public class ConfirmDialog : ModalDialog
{
public String Message { get; set; }
diff --git a/TelegramBotBase/Form/ModalDialog.cs b/TelegramBotBase/Form/ModalDialog.cs
new file mode 100644
index 0000000..785ebd2
--- /dev/null
+++ b/TelegramBotBase/Form/ModalDialog.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TelegramBotBase.Form
+{
+ public class ModalDialog : FormBase
+ {
+
+
+ ///
+ /// This is a modal only function and does everything to close this form.
+ ///
+ public async Task CloseForm()
+ {
+
+ await this.CloseControls();
+
+ await this.OnClosed(new EventArgs());
+
+ }
+ }
+}
diff --git a/TelegramBotBase/Form/PromptDialog.cs b/TelegramBotBase/Form/PromptDialog.cs
index bb18b4c..d624dd0 100644
--- a/TelegramBotBase/Form/PromptDialog.cs
+++ b/TelegramBotBase/Form/PromptDialog.cs
@@ -8,7 +8,7 @@ using TelegramBotBase.Base;
namespace TelegramBotBase.Form
{
- public class PromptDialog : FormBase
+ public class PromptDialog : ModalDialog
{
public String Message { get; set; }
@@ -53,6 +53,8 @@ namespace TelegramBotBase.Form
OnCompleted(new EventArgs());
+
+ await this.CloseForm();
}
diff --git a/TelegramBotBaseTest/Tests/TestForm2.cs b/TelegramBotBaseTest/Tests/TestForm2.cs
index 2c07fbb..741b0c3 100644
--- a/TelegramBotBaseTest/Tests/TestForm2.cs
+++ b/TelegramBotBaseTest/Tests/TestForm2.cs
@@ -31,7 +31,7 @@ namespace TelegramBaseTest.Tests
{
await this.Device.Send("Ciao from Form 2");
}
-
+
@@ -84,12 +84,9 @@ namespace TelegramBaseTest.Tests
pd.Completed += async (s, en) =>
{
await this.Device.Send("Hello " + pd.Value);
-
- var tf = new TestForm2();
- await pd.NavigateTo(tf);
};
- await this.NavigateTo(pd);
+ await this.OpenModal(pd);
}