-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuGenerator.cs
69 lines (60 loc) · 2.03 KB
/
MenuGenerator.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
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace busylight_client
{
class MenuGenerator
{
public ContextMenuStrip Menu;
private static Settings _settings;
public MenuGenerator(Settings settings)
{
_settings = settings;
Menu = GenerateMenu();
}
private static ContextMenuStrip GenerateMenu()
{
var menu = new ContextMenuStrip();
menu.SuspendLayout();
menu.Items.AddRange(new ToolStripItem[]
{
new ToolStripMenuItem{ Text = _settings.Location, Enabled = false },
new ToolStripSeparator()
});
menu.Items.AddRange(GetColorMenu());
menu.Items.Add(new ToolStripSeparator());
menu.Items.Add("Exit", _settings.resourceSet.GetObject("Exit") as Image, (a, b) => Application.Exit());
menu.ResumeLayout(false);
return menu;
}
private static ToolStripMenuItem[] GetColorMenu()
{
var colors = new List<ToolStripMenuItem>();
foreach (DictionaryEntry entry in _settings.resourceSet)
{
var name = entry.Key.ToString();
if (name == "Exit")
continue;
if (entry.Value is Bitmap bitmap)
{
var someMenuItem = new ToolStripMenuItem
{
Name = name,
Text = name,
Image = bitmap,
Enabled = false,
Tag = "Color"
};
someMenuItem.Click += (s, e) =>
{
//connection.InvokeAsync("SendToSelf", name);
};
colors.Add(someMenuItem);
}
}
return colors.OrderBy(a => a.Text).ToArray();
}
}
}