|
1 using System; |
|
2 using System.Collections.Generic; |
|
3 using System.Linq; |
|
4 using System.Text; |
|
5 using System.Threading.Tasks; |
|
6 using System.Windows; |
|
7 using System.Windows.Controls; |
|
8 |
|
9 namespace UI |
|
10 { |
|
11 public class MainToolBar |
|
12 { |
|
13 Dictionary<string, IToolItem> Items = new Dictionary<string, IToolItem>(); |
|
14 List<string> Defaults = new List<string>(); |
|
15 |
|
16 public MainToolBar() |
|
17 { |
|
18 |
|
19 } |
|
20 |
|
21 public bool HasItems() |
|
22 { |
|
23 return Defaults.Count > 0 ? true : false; |
|
24 } |
|
25 |
|
26 public void AddDefault(string itemName) |
|
27 { |
|
28 Defaults.Add(itemName); |
|
29 } |
|
30 |
|
31 public void AddToolItem(string name, string label, Action<IntPtr> action) |
|
32 { |
|
33 ToolItem item = new ToolItem(); |
|
34 item.Label = label; |
|
35 item.Action = action; |
|
36 Items.Add(name, item); |
|
37 } |
|
38 |
|
39 public ToolBarTray CreateToolBarTray(IntPtr objptr) |
|
40 { |
|
41 ToolBarTray tray = new ToolBarTray(); |
|
42 |
|
43 ToolBar toolbar = new ToolBar(); |
|
44 tray.ToolBars.Add(toolbar); |
|
45 foreach(string s in Defaults) |
|
46 { |
|
47 IToolItem item = Items[s]; |
|
48 item.AddTo(toolbar, objptr); |
|
49 } |
|
50 |
|
51 return tray; |
|
52 } |
|
53 } |
|
54 |
|
55 public interface IToolItem |
|
56 { |
|
57 void AddTo(System.Windows.Controls.ToolBar toolbar, IntPtr uiobj); |
|
58 } |
|
59 |
|
60 public class ToolItem : IToolItem |
|
61 { |
|
62 public string Label { get; set; } |
|
63 // TODO: icon |
|
64 public Action<IntPtr> Action { get; set; } |
|
65 |
|
66 public void AddTo(System.Windows.Controls.ToolBar toolbar, IntPtr uiobj) |
|
67 { |
|
68 Button button = new Button(); |
|
69 button.Content = Label; |
|
70 |
|
71 EventCallback e = new EventCallback(uiobj, Action); |
|
72 button.Click += e.Callback; |
|
73 |
|
74 toolbar.Items.Add(button); |
|
75 } |
|
76 } |
|
77 } |