Update ButtonForm.cs
- adding a Duplicate function - improving Count property - adding InsertButtonRow methods - adding a dictionary property to get all buttons in a specific row
This commit is contained in:
parent
a1b3b9246b
commit
e5dc3fd2bc
@ -42,6 +42,15 @@ namespace TelegramBotBase.Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<ButtonBase> this[int row]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Buttons[row];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ButtonForm()
|
public ButtonForm()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -62,6 +71,16 @@ namespace TelegramBotBase.Form
|
|||||||
AddButtonRow(row.ToList());
|
AddButtonRow(row.ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void InsertButtonRow(int index, IEnumerable<ButtonBase> row)
|
||||||
|
{
|
||||||
|
Buttons.Insert(index, row.ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InsertButtonRow(int index, params ButtonBase[] row)
|
||||||
|
{
|
||||||
|
InsertButtonRow(index, row.ToList());
|
||||||
|
}
|
||||||
|
|
||||||
public static T[][] SplitTo<T>(IEnumerable<T> items, int itemsPerRow = 2)
|
public static T[][] SplitTo<T>(IEnumerable<T> items, int itemsPerRow = 2)
|
||||||
{
|
{
|
||||||
T[][] splitted = default(T[][]);
|
T[][] splitted = default(T[][]);
|
||||||
@ -86,7 +105,10 @@ namespace TelegramBotBase.Form
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return this.Buttons.Select(a => a.ToArray()).Aggregate((a, b) => a.Union(b).ToArray()).Length;
|
if (this.Buttons.Count == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return this.Buttons.Select(a => a.ToArray()).ToList().Aggregate((a, b) => a.Union(b).ToArray()).Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,5 +175,30 @@ namespace TelegramBotBase.Form
|
|||||||
|
|
||||||
return ikm;
|
return ikm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a copy of this form.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public ButtonForm Duplicate()
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
lst.Add(b2);
|
||||||
|
}
|
||||||
|
bf.Buttons.Add(lst);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user