diff --git a/TelegramBotBase/Form/ButtonForm.cs b/TelegramBotBase/Form/ButtonForm.cs index 8346c8c..eca6213 100644 --- a/TelegramBotBase/Form/ButtonForm.cs +++ b/TelegramBotBase/Form/ButtonForm.cs @@ -42,6 +42,15 @@ namespace TelegramBotBase.Form } } + + public List this[int row] + { + get + { + return Buttons[row]; + } + } + public ButtonForm() { @@ -62,6 +71,16 @@ namespace TelegramBotBase.Form AddButtonRow(row.ToList()); } + public void InsertButtonRow(int index, IEnumerable row) + { + Buttons.Insert(index, row.ToList()); + } + + public void InsertButtonRow(int index, params ButtonBase[] row) + { + InsertButtonRow(index, row.ToList()); + } + public static T[][] SplitTo(IEnumerable items, int itemsPerRow = 2) { T[][] splitted = default(T[][]); @@ -86,7 +105,10 @@ namespace TelegramBotBase.Form { 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; } + + /// + /// Creates a copy of this form. + /// + /// + public ButtonForm Duplicate() + { + var bf = new ButtonForm() + { + Markup = this.Markup, + DependencyControl = this.DependencyControl + }; + + foreach(var b in Buttons) + { + var lst = new List(); + foreach(var b2 in b) + { + lst.Add(b2); + } + bf.Buttons.Add(lst); + } + + return bf; + } } }