- 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:
@@ -31,11 +31,12 @@ namespace TelegramBotBase.Form
|
||||
}
|
||||
|
||||
|
||||
public InlineKeyboardButton ToInlineButton()
|
||||
public InlineKeyboardButton ToInlineButton(ButtonForm form)
|
||||
{
|
||||
String id = (form.DependencyControl != null ? form.DependencyControl.ControlID + "_" : "");
|
||||
if (this.Url == null)
|
||||
{
|
||||
return InlineKeyboardButton.WithCallbackData(this.Text, this.Value);
|
||||
return InlineKeyboardButton.WithCallbackData(this.Text, id + this.Value);
|
||||
}
|
||||
|
||||
var ikb = new InlineKeyboardButton();
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot.Types.ReplyMarkups;
|
||||
using TelegramBotBase.Base;
|
||||
|
||||
namespace TelegramBotBase.Form
|
||||
{
|
||||
@@ -17,12 +18,18 @@ namespace TelegramBotBase.Form
|
||||
|
||||
public IReplyMarkup Markup { get; set; }
|
||||
|
||||
public ControlBase DependencyControl { get; set; }
|
||||
|
||||
public ButtonForm()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ButtonForm(ControlBase control)
|
||||
{
|
||||
this.DependencyControl = control;
|
||||
}
|
||||
|
||||
public void AddButtonRow(IEnumerable<ButtonBase> row)
|
||||
{
|
||||
Buttons.Add(row.ToList());
|
||||
@@ -62,7 +69,7 @@ namespace TelegramBotBase.Form
|
||||
{
|
||||
var sp = SplitTo<ButtonBase>(buttons, buttonsPerRow);
|
||||
|
||||
foreach(var bl in sp)
|
||||
foreach (var bl in sp)
|
||||
{
|
||||
AddButtonRow(bl);
|
||||
}
|
||||
@@ -70,7 +77,7 @@ namespace TelegramBotBase.Form
|
||||
|
||||
public InlineKeyboardButton[][] ToArray()
|
||||
{
|
||||
var ikb = this.Buttons.Select(a => a.Select(b => b.ToInlineButton()).ToArray()).ToArray();
|
||||
var ikb = this.Buttons.Select(a => a.Select(b => b.ToInlineButton(this)).ToArray()).ToArray();
|
||||
|
||||
return ikb;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user