diff --git a/TelegramBotBase/Base/ControlBase.cs b/TelegramBotBase/Base/ControlBase.cs index fa905e0..f982591 100644 --- a/TelegramBotBase/Base/ControlBase.cs +++ b/TelegramBotBase/Base/ControlBase.cs @@ -28,6 +28,14 @@ namespace TelegramBotBase.Base /// public bool Enabled { get; set; } = true; + + public virtual async Task Load(MessageResult result) + { + + + + } + public virtual async Task Action(MessageResult result, String value = null) { diff --git a/TelegramBotBase/Base/FormBase.cs b/TelegramBotBase/Base/FormBase.cs index df7eea4..64180ea 100644 --- a/TelegramBotBase/Base/FormBase.cs +++ b/TelegramBotBase/Base/FormBase.cs @@ -152,6 +152,33 @@ namespace TelegramBotBase.Form } + /// + /// Gets invoked if a message was sent or an action triggered + /// + /// + /// + public async Task LoadControls(MessageResult message) + { + //Looking for the control by id, if not listened, raise event for all + if (message.RawData?.StartsWith("#c") ?? false) + { + var c = this.Controls.FirstOrDefault(a => a.ControlID == message.RawData.Split('_')[0]); + if (c != null) + { + await c.Load(message); + return; + } + } + + foreach (var b in this.Controls) + { + if (!b.Enabled) + continue; + + await b.Load(message); + } + } + /// /// Gets invoked if the form gets loaded and on every message belongs to this context /// @@ -162,6 +189,8 @@ namespace TelegramBotBase.Form } + + /// /// Gets invoked if the user clicked a button. /// @@ -186,6 +215,9 @@ namespace TelegramBotBase.Form continue; await b.Action(message); + + if (message.Handled) + return; } } @@ -265,6 +297,10 @@ namespace TelegramBotBase.Form await newForm.OnOpened(new EventArgs()); } + /// + /// Adds a control to the formular and sets its ID and Device. + /// + /// public void AddControl(ControlBase control) { control.ID = this.Controls.Count + 1; diff --git a/TelegramBotBase/BotBase.cs b/TelegramBotBase/BotBase.cs index 44e100b..02f5861 100644 --- a/TelegramBotBase/BotBase.cs +++ b/TelegramBotBase/BotBase.cs @@ -267,6 +267,9 @@ namespace TelegramBotBase //Pre Loading Event await activeForm.PreLoad(e); + //Send Load event to controls + await activeForm.LoadControls(e); + //Loading Event await activeForm.Load(e); @@ -279,7 +282,13 @@ namespace TelegramBotBase //Render Event if (!ds.FormSwitched) + { + + await activeForm.RenderControls(e); + await activeForm.Render(e); + } + } while (ds.FormSwitched && i < NavigationMaximum); @@ -336,6 +345,9 @@ namespace TelegramBotBase //Pre Loading Event await activeForm.PreLoad(e); + //Send Load event to controls + await activeForm.LoadControls(e); + //Loading Event await activeForm.Load(e);