New Control: TaggedButtonGrid
- tag your list with some strings and filter it right away - adding Test to test project - adding a new localization PS: it is an improved copy of the normal ButtonGrid
This commit is contained in:
@@ -36,7 +36,7 @@ namespace TelegramBotBase.Form
|
||||
/// </summary>
|
||||
/// <param name="form"></param>
|
||||
/// <returns></returns>
|
||||
public InlineKeyboardButton ToInlineButton(ButtonForm form)
|
||||
public virtual InlineKeyboardButton ToInlineButton(ButtonForm form)
|
||||
{
|
||||
String id = (form.DependencyControl != null ? form.DependencyControl.ControlID + "_" : "");
|
||||
if (this.Url == null)
|
||||
@@ -59,7 +59,7 @@ namespace TelegramBotBase.Form
|
||||
/// </summary>
|
||||
/// <param name="form"></param>
|
||||
/// <returns></returns>
|
||||
public KeyboardButton ToKeyboardButton(ButtonForm form)
|
||||
public virtual KeyboardButton ToKeyboardButton(ButtonForm form)
|
||||
{
|
||||
return new KeyboardButton(this.Text);
|
||||
}
|
||||
|
||||
@@ -244,5 +244,47 @@ namespace TelegramBotBase.Form
|
||||
|
||||
return bf;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a copy of this form and filters by the parameter.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ButtonForm TagDuplicate(List<String> tags, bool ByRow = false)
|
||||
{
|
||||
var bf = new ButtonForm()
|
||||
{
|
||||
Markup = this.Markup,
|
||||
DependencyControl = this.DependencyControl
|
||||
};
|
||||
|
||||
foreach (var b in Buttons)
|
||||
{
|
||||
var lst = new List<ButtonBase>();
|
||||
foreach (var b2 in b)
|
||||
{
|
||||
if (!(b2 is TagButtonBase tb))
|
||||
continue;
|
||||
|
||||
if (!tags.Contains(tb.Tag))
|
||||
continue;
|
||||
|
||||
//Copy full row, when at least one match has found.
|
||||
if (ByRow)
|
||||
{
|
||||
lst.AddRange(b);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
lst.Add(b2);
|
||||
}
|
||||
}
|
||||
|
||||
if (lst.Count > 0)
|
||||
bf.Buttons.Add(lst);
|
||||
}
|
||||
|
||||
return bf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot.Types.ReplyMarkups;
|
||||
|
||||
namespace TelegramBotBase.Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for button handling
|
||||
/// </summary>
|
||||
public class TagButtonBase : ButtonBase
|
||||
{
|
||||
public String Tag { get; set; }
|
||||
|
||||
public TagButtonBase()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public TagButtonBase(String Text, String Value, String Tag)
|
||||
{
|
||||
this.Text = Text;
|
||||
this.Value = Value;
|
||||
this.Tag = Tag;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns an inline Button
|
||||
/// </summary>
|
||||
/// <param name="form"></param>
|
||||
/// <returns></returns>
|
||||
public override InlineKeyboardButton ToInlineButton(ButtonForm form)
|
||||
{
|
||||
String id = (form.DependencyControl != null ? form.DependencyControl.ControlID + "_" : "");
|
||||
|
||||
return InlineKeyboardButton.WithCallbackData(this.Text, id + this.Value);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns a KeyBoardButton
|
||||
/// </summary>
|
||||
/// <param name="form"></param>
|
||||
/// <returns></returns>
|
||||
public override KeyboardButton ToKeyboardButton(ButtonForm form)
|
||||
{
|
||||
return new KeyboardButton(this.Text);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user