ui/wpf/UIcore/MainToolBar.cs

changeset 0
804d8803eade
equal deleted inserted replaced
-1:000000000000 0:804d8803eade
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 using System.Windows.Media;
9
10 namespace UI
11 {
12 public class MainToolBar
13 {
14 Dictionary<string, IToolItem> Items = new Dictionary<string, IToolItem>();
15 List<string> Defaults = new List<string>();
16
17 public MainToolBar()
18 {
19
20 }
21
22 public bool HasItems()
23 {
24 return Defaults.Count > 0 ? true : false;
25 }
26
27 public void AddDefault(string itemName)
28 {
29 Defaults.Add(itemName);
30 }
31
32 public void AddToolItem(string name, string label, Action<IntPtr> action)
33 {
34 ToolItem item = new ToolItem();
35 item.Label = label;
36 item.Action = action;
37 Items.Add(name, item);
38 }
39
40 public ToolBarTray CreateToolBarTray(IntPtr objptr)
41 {
42 ToolBarTray tray = new ToolBarTray();
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 }

mercurial