/
ToolItemCollection.cs
75 lines (65 loc) · 1.48 KB
/
ToolItemCollection.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
using System.Collections.ObjectModel;
using System.Collections.Generic;
namespace Eto.Forms
{
public class ToolItemCollection : Collection<ToolItem>
{
readonly ToolBar parent;
protected internal ToolItemCollection(ToolBar parent)
{
this.parent = parent;
}
protected override void InsertItem(int index, ToolItem item)
{
base.InsertItem(index, item);
parent.Handler.AddButton(item, index);
}
protected override void RemoveItem(int index)
{
var item = this[index];
base.RemoveItem(index);
parent.Handler.RemoveButton(item);
}
protected override void ClearItems()
{
base.ClearItems();
parent.Handler.Clear();
}
public new void Add(ToolItem item)
{
int previousIndex = -1;
for (var i = 0; i < Count; ++i)
{
if (this[i].Order <= item.Order)
previousIndex = i;
else
break;
}
Insert(previousIndex + 1, item);
}
public void Add(Command command, int order = -1)
{
var item = command.CreateToolItem(parent.Generator);
item.Order = order;
Add(item);
}
public void AddSeparator(int order = -1, SeparatorToolItemType type = SeparatorToolItemType.Divider)
{
Add(new SeparatorToolItem(parent.Generator) { Order = order, Type = type });
}
public void AddRange(IEnumerable<ToolItem> items)
{
foreach (var item in items)
{
Add(item);
}
}
public void AddRange(IEnumerable<Command> commands, int order = -1)
{
foreach (var command in commands)
{
Add(command, order);
}
}
}
}