-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeekNumberLite2ContextMenu.cs
109 lines (84 loc) · 2.58 KB
/
WeekNumberLite2ContextMenu.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#region Using statements
using WeekNumberLite2.Properties;
#endregion
namespace WeekNumberLite2
{
internal class WeekNumberLite2ContextMenu : IDisposable
{
#region Internal context menu
internal ContextMenuStrip? ContextMenu { get; private set; }
#endregion Internal context menu
#region Internal contructor
internal WeekNumberLite2ContextMenu()
{
CreateContextMenu();
}
#endregion Internal constructor
#region Private event handling
private static void ExitMenuClick(object? o, EventArgs e)
{
Application.Exit();
}
private void AboutClick(object? o, EventArgs e)
{
ToolStripMenuItem? mi = o is null ? null : (ToolStripMenuItem)o;
try
{
if (mi != null)
{
mi.Enabled = false;
}
Forms.MessageForm.LogAndDisplayLinkMessage(Resources.About, Resources.APPLICATION_URL);
}
finally
{
EnableMenuItem(mi);
}
}
#endregion Private event handling
#region Private method for context menu creation
internal void CreateContextMenu()
{
ContextMenu = new ContextMenuStrip();
ToolStripMenuItem AboutMenu = new(Resources.AboutMenu);
ToolStripMenuItem ExitMenu = new(Resources.ExitMenu);
AboutMenu.Click += AboutClick;
ExitMenu.Click += ExitMenuClick;
_ = ContextMenu.Items.Add(AboutMenu);
_ = ContextMenu.Items.Add(ExitMenu);
}
#endregion Private method for context menu creation
#region Private helper methods for menu items
private static void EnableMenuItem(ToolStripMenuItem? mi)
{
if (mi != null)
{
mi.Enabled = true;
}
}
#endregion Private helper methods for menu items
#region IDisposable methods
/// <summary>
/// Disposes the context menu
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!disposing)
{
return;
}
CleanupContextMenu();
}
private void CleanupContextMenu()
{
ContextMenu?.Dispose();
ContextMenu = null;
}
#endregion IDisposable methods
}
}