diff --git a/TelegramBotBase/Base/FormBase.cs b/TelegramBotBase/Base/FormBase.cs index 747bf5d..d64b2c4 100644 --- a/TelegramBotBase/Base/FormBase.cs +++ b/TelegramBotBase/Base/FormBase.cs @@ -20,9 +20,9 @@ namespace TelegramBotBase.Form public bool CustomEventManagement { get; set; } = false; /// - /// contains if the form has been switched (navigated) + /// has this formular already been disposed ? /// - public bool FormSwitched { get; set; } = false; + public bool IsDisposed { get; set; } = false; public List Controls { get; set; } @@ -117,12 +117,14 @@ namespace TelegramBotBase.Form if (ds == null) return; - this.FormSwitched = true; + ds.FormSwitched = true; ds.ActiveForm = newForm; newForm.Client = this.Client; newForm.Device = ds; + ds.PreviousForm = this; + await newForm.Init(args); await this.Closed(); @@ -137,7 +139,7 @@ namespace TelegramBotBase.Form { this.Client = null; this.Device = null; - this.FormSwitched = false; + this.IsDisposed = true; } } } diff --git a/TelegramBotBase/BotBase.cs b/TelegramBotBase/BotBase.cs index d1a12a9..2300fe1 100644 --- a/TelegramBotBase/BotBase.cs +++ b/TelegramBotBase/BotBase.cs @@ -258,6 +258,9 @@ namespace TelegramBotBase do { i++; + + //Reset navigation + ds.FormSwitched = false; activeForm = ds.ActiveForm; @@ -279,10 +282,10 @@ namespace TelegramBotBase } //Render Event - if (!activeForm.FormSwitched) + if (!ds.FormSwitched) await activeForm.Render(e); - } while (activeForm.FormSwitched && i < NavigationMaximum); + } while (ds.FormSwitched && i < NavigationMaximum); } @@ -329,6 +332,9 @@ namespace TelegramBotBase { i++; + //Reset navigation + ds.FormSwitched = false; + activeForm = ds.ActiveForm; //If the form manages the events by itselfs, skip here @@ -342,7 +348,7 @@ namespace TelegramBotBase await activeForm.Load(e); //Action Event - if (!activeForm.FormSwitched) + if (!ds.FormSwitched) { await activeForm.Action(e); @@ -353,7 +359,7 @@ namespace TelegramBotBase if (uhc.Handled) { - if (activeForm.FormSwitched) + if (ds.FormSwitched) { continue; } @@ -367,10 +373,10 @@ namespace TelegramBotBase } //Render Event - if (!activeForm.FormSwitched) + if (!ds.FormSwitched) await activeForm.Render(e); - } while (activeForm.FormSwitched && i < NavigationMaximum); + } while (ds.FormSwitched && i < NavigationMaximum); } diff --git a/TelegramBotBase/Sessions/DeviceSession.cs b/TelegramBotBase/Sessions/DeviceSession.cs index 6453010..5e2e040 100644 --- a/TelegramBotBase/Sessions/DeviceSession.cs +++ b/TelegramBotBase/Sessions/DeviceSession.cs @@ -37,6 +37,16 @@ namespace TelegramBotBase.Sessions /// public FormBase ActiveForm { get; set; } + /// + /// Returns the previous shown form + /// + public FormBase PreviousForm { get; set; } + + /// + /// contains if the form has been switched (navigated) + /// + public bool FormSwitched { get; set; } = false; + /// /// Returns the ID of the last received message. ///