Sun, 15 Jan 2017 15:08:07 +0100
fixes VS settings
81 | 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 | ||
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
37 | public void EndSubMenu() |
81 | 38 | { |
39 | current.Remove(current.Last()); | |
40 | } | |
41 | ||
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
42 | public void AddMenuItem(String label, Action<IntPtr> action) |
81 | 43 | { |
44 | if(current.Count != 0) | |
45 | { | |
46 | MenuItem item = new MenuItem(label, action); | |
47 | current.Last().Items.Add(item); | |
48 | } | |
49 | } | |
50 | ||
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
51 | public System.Windows.Controls.Menu CreateMenu(IntPtr uiobj) |
81 | 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; | |
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
58 | m.AddItems(i, uiobj); |
81 | 59 | menu.Items.Add(i); |
60 | } | |
61 | return menu; | |
62 | } | |
63 | } | |
64 | ||
65 | public interface IMenuItem | |
66 | { | |
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
67 | void AddTo(System.Windows.Controls.MenuItem menu, IntPtr uiobj); |
81 | 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 | ||
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
80 | public void AddItems(System.Windows.Controls.MenuItem i, IntPtr uiobj) |
81 | 81 | { |
82 | foreach (IMenuItem item in Items) | |
83 | { | |
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
84 | item.AddTo(i, uiobj); |
81 | 85 | } |
86 | } | |
87 | ||
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
88 | void IMenuItem.AddTo(System.Windows.Controls.MenuItem menu, IntPtr uiobj) |
81 | 89 | { |
90 | System.Windows.Controls.MenuItem i = new System.Windows.Controls.MenuItem(); | |
91 | i.Header = Label; | |
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
92 | AddItems(i, uiobj); |
81 | 93 | menu.Items.Add(i); |
94 | } | |
95 | } | |
96 | ||
97 | public class MenuItem : IMenuItem | |
98 | { | |
99 | String Label; | |
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
100 | Action<IntPtr> Action; |
81 | 101 | |
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
102 | public MenuItem(String label, Action<IntPtr> action) |
81 | 103 | { |
104 | Label = label; | |
105 | Action = action; | |
106 | } | |
107 | ||
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
108 | void IMenuItem.AddTo(System.Windows.Controls.MenuItem menu, IntPtr uiobj) |
81 | 109 | { |
110 | System.Windows.Controls.MenuItem i = new System.Windows.Controls.MenuItem(); | |
82
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
111 | EventCallback cb = new EventCallback(uiobj, Action); |
0cdb8089a29f
added event handler for menus (WPF)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
81
diff
changeset
|
112 | i.Click += cb.Callback; |
81 | 113 | i.Header = Label; |
114 | menu.Items.Add(i); | |
115 | } | |
116 | } | |
117 | } |