-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathTreeViewForms.cs
98 lines (73 loc) · 2.61 KB
/
TreeViewForms.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System.Threading.Tasks;
using TelegramBotBase.Args;
using TelegramBotBase.Base;
using TelegramBotBase.Controls.Inline;
using TelegramBotBase.Enums;
using TelegramBotBase.Form;
namespace TelegramBotBase.Example.Tests.Controls;
public class TreeViewForms : AutoCleanForm
{
public TreeViewForms()
{
DeleteMode = EDeleteMode.OnLeavingForm;
Init += TreeViewForms_Init;
}
public TreeView View { get; set; }
private int? MessageId { get; set; }
private Task TreeViewForms_Init(object sender, InitEventArgs e)
{
View = new TreeView();
var tvn = new TreeViewNode("Cars", "cars");
tvn.AddNode(new TreeViewNode("Porsche", "porsche",
new TreeViewNode("Website", "web", "https://www.porsche.com/germany/"),
new TreeViewNode("911", "911"),
new TreeViewNode("918 Spyder", "918")));
tvn.AddNode(new TreeViewNode("BMW", "bmw"));
tvn.AddNode(new TreeViewNode("Audi", "audi"));
tvn.AddNode(new TreeViewNode("VW", "vw"));
tvn.AddNode(new TreeViewNode("Lamborghini", "lamborghini"));
View.Nodes.Add(tvn);
tvn = new TreeViewNode("Fruits", "fruits");
tvn.AddNode(new TreeViewNode("Apple", "apple"));
tvn.AddNode(new TreeViewNode("Orange", "orange"));
tvn.AddNode(new TreeViewNode("Lemon", "lemon"));
View.Nodes.Add(tvn);
AddControl(View);
return Task.CompletedTask;
}
public override async Task Action(MessageResult message)
{
await message.ConfirmAction();
if (message.Handled)
{
return;
}
switch (message.RawData)
{
case "back":
message.Handled = true;
var start = new Menu();
await NavigateTo(start);
break;
}
}
public override async Task Render(MessageResult message)
{
var s = "";
s += "Selected Node: " + (View.SelectedNode?.Text ?? "(null)") + "\r\n";
s += "Visible Node: " + (View.VisibleNode?.Text ?? "(top)") + "\r\n";
s += "Visible Path: " + View.GetPath() + "\r\n";
s += "Selected Path: " + (View.SelectedNode?.GetPath() ?? "(null)") + "\r\n";
var bf = new ButtonForm();
bf.AddButtonRow(new ButtonBase("Back", "back"));
if (MessageId != null)
{
await Device.Edit(MessageId.Value, s, bf);
}
else
{
var m = await Device.Send(s, bf);
MessageId = m.MessageId;
}
}
}