|
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 ApplicationMenu |
|
12 { |
|
13 private List<Menu> current = new List<Menu>(); |
|
14 |
|
15 public List<Menu> Menus = new List<Menu>(); |
|
16 |
|
17 public void AddMenu(String label) |
|
18 { |
|
19 current.Clear(); |
|
20 Menu menu = new Menu(label); |
|
21 current.Add(menu); |
|
22 Menus.Add(menu); |
|
23 } |
|
24 |
|
25 public Boolean IsEmpty() |
|
26 { |
|
27 return Menus.Count == 0 ? true : false; |
|
28 } |
|
29 |
|
30 public void AddSubMenu(String label) |
|
31 { |
|
32 Menu menu = new Menu(label); |
|
33 current.Last().Items.Add(menu); |
|
34 current.Add(menu); |
|
35 } |
|
36 |
|
37 public void EndMenu() |
|
38 { |
|
39 current.Remove(current.Last()); |
|
40 } |
|
41 |
|
42 public void AddMenuItem(String label, Action action) |
|
43 { |
|
44 if(current.Count != 0) |
|
45 { |
|
46 MenuItem item = new MenuItem(label, action); |
|
47 current.Last().Items.Add(item); |
|
48 } |
|
49 } |
|
50 |
|
51 public System.Windows.Controls.Menu CreateMenu() |
|
52 { |
|
53 System.Windows.Controls.Menu menu = new System.Windows.Controls.Menu(); |
|
54 foreach (Menu m in Menus) |
|
55 { |
|
56 System.Windows.Controls.MenuItem i = new System.Windows.Controls.MenuItem(); |
|
57 i.Header = m.Label; |
|
58 m.AddItems(i); |
|
59 menu.Items.Add(i); |
|
60 } |
|
61 return menu; |
|
62 } |
|
63 } |
|
64 |
|
65 public interface IMenuItem |
|
66 { |
|
67 void AddTo(System.Windows.Controls.MenuItem menu); |
|
68 } |
|
69 |
|
70 public class Menu : IMenuItem |
|
71 { |
|
72 public String Label; |
|
73 public List<IMenuItem> Items = new List<IMenuItem>(); |
|
74 |
|
75 public Menu(String label) |
|
76 { |
|
77 Label = label; |
|
78 } |
|
79 |
|
80 public void AddItems(System.Windows.Controls.MenuItem i) |
|
81 { |
|
82 foreach (IMenuItem item in Items) |
|
83 { |
|
84 item.AddTo(i); |
|
85 } |
|
86 } |
|
87 |
|
88 void IMenuItem.AddTo(System.Windows.Controls.MenuItem menu) |
|
89 { |
|
90 System.Windows.Controls.MenuItem i = new System.Windows.Controls.MenuItem(); |
|
91 i.Header = Label; |
|
92 AddItems(i); |
|
93 menu.Items.Add(i); |
|
94 } |
|
95 } |
|
96 |
|
97 public class MenuItem : IMenuItem |
|
98 { |
|
99 String Label; |
|
100 Action Action; |
|
101 |
|
102 public MenuItem(String label, Action action) |
|
103 { |
|
104 Label = label; |
|
105 Action = action; |
|
106 } |
|
107 |
|
108 void IMenuItem.AddTo(System.Windows.Controls.MenuItem menu) |
|
109 { |
|
110 System.Windows.Controls.MenuItem i = new System.Windows.Controls.MenuItem(); |
|
111 i.Header = Label; |
|
112 menu.Items.Add(i); |
|
113 } |
|
114 } |
|
115 } |