- Added ToggleButton as an easy switch control (i.e. for settings page)
- added control id, for easier separating of controls in one form - added automatic event selection for specific controls, to not raise an event for other controls who has invoked it - changed Action method - added example
This commit is contained in:
@@ -15,18 +15,28 @@ namespace TelegramBotBase.Base
|
||||
|
||||
public int ID { get; set; }
|
||||
|
||||
public String ControlID
|
||||
{
|
||||
get
|
||||
{
|
||||
return "#c" + this.ID.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines if the control should be rendered and invoked with actions
|
||||
/// </summary>
|
||||
public bool Enabled { get; set; } = true;
|
||||
|
||||
public virtual async Task Action(MessageResult result)
|
||||
public virtual async Task Action(MessageResult result, String value = null)
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public virtual async Task Render(MessageResult result)
|
||||
{
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace TelegramBotBase.Form
|
||||
return;
|
||||
|
||||
var handler = this.Events[__evInit].GetInvocationList().Cast<AsyncEventHandler<InitEventArgs>>();
|
||||
foreach(var h in handler)
|
||||
foreach (var h in handler)
|
||||
{
|
||||
await Async.InvokeAllAsync<InitEventArgs>(h, this, e);
|
||||
}
|
||||
@@ -169,6 +169,17 @@ namespace TelegramBotBase.Form
|
||||
/// <returns></returns>
|
||||
public async Task ActionControls(MessageResult message)
|
||||
{
|
||||
//Looking for the control by id, if not listened, raise event for all
|
||||
if (message.RawData.StartsWith("#c"))
|
||||
{
|
||||
var c = this.Controls.FirstOrDefault(a => a.ControlID == message.RawData.Split('_')[0]);
|
||||
if (c != null)
|
||||
{
|
||||
await c.Action(message, message.RawData.Split('_')[1]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var b in this.Controls)
|
||||
{
|
||||
if (!b.Enabled)
|
||||
|
||||
Reference in New Issue
Block a user