WingMan – Diff between revs 6 and 7

Subversion Repositories:
Rev:
Only display areas with differencesIgnore whitespace
Rev 6 Rev 7
1 using System; 1 using System;
2 using System.Collections.Generic; 2 using System.Collections.Generic;
3 using System.Drawing; 3 using System.Drawing;
4 using System.Linq; 4 using System.Linq;
5 using System.Net; 5 using System.Net;
-   6 using System.Threading;
6 using System.Threading.Tasks; 7 using System.Threading.Tasks;
7 using System.Windows.Forms; 8 using System.Windows.Forms;
8 using Gma.System.MouseKeyHook; 9 using Gma.System.MouseKeyHook;
9 using WingMan.Communication; 10 using WingMan.Communication;
-   11 using WingMan.Lobby;
10 using WingMan.MouseKey; 12 using WingMan.MouseKey;
11 using WingMan.Properties; 13 using WingMan.Properties;
12   14  
13 namespace WingMan 15 namespace WingMan
14 { 16 {
15 public partial class WingManForm : Form 17 public partial class WingManForm : Form
16 { 18 {
17 public WingManForm() 19 public WingManForm()
18 { 20 {
19 InitializeComponent(); 21 InitializeComponent();
20   22  
21 FormTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); 23 FormTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
-   24 FormCancellationTokenSource = new CancellationTokenSource();
22   25  
23 MQTTCommunication = new MQTTCommunication(FormTaskScheduler); 26 MQTTCommunication = new MQTTCommunication(FormTaskScheduler, FormCancellationTokenSource.Token);
24   27  
25 MouseKeyBindings = new MouseKeyBindings(new List<MouseKeyBinding>()); 28 MouseKeyBindings = new MouseKeyBindings(new List<MouseKeyBinding>());
26   29  
27 HelmBindingSource = new BindingSource 30 HelmListBoxBindingSource = new BindingSource
28 { 31 {
29 DataSource = MouseKeyBindings.Bindings 32 DataSource = MouseKeyBindings.Bindings
30 }; 33 };
31 HelmBindingsListBox.DisplayMember = "DisplayName"; 34 HelmBindingsListBox.DisplayMember = "DisplayName";
32 HelmBindingsListBox.ValueMember = "Keys"; 35 HelmBindingsListBox.ValueMember = "Keys";
33 HelmBindingsListBox.DataSource = HelmBindingSource; 36 HelmBindingsListBox.DataSource = HelmListBoxBindingSource;
34   37  
-   38 MouseKeyBindingsExchange = new MouseKeyBindingsExchange
-   39 {
-   40 ExchangeBindings = new List<MouseKeyBindingExchange>()
-   41 };
35 MouseKeyBindingsExchange = new MouseKeyBindingsExchange(); 42  
36 WingBindingSource = new BindingSource 43 WingBindingsComboBoxSource = new BindingSource
37 { 44 {
38 DataSource = MouseKeyBindingsExchange.ExchangeBindings 45 DataSource = MouseKeyBindingsExchange.ExchangeBindings
39 }; 46 };
40 WingBindingsComboBox.DisplayMember = "Nick"; 47 WingBindingsComboBox.DisplayMember = "Nick";
41 WingBindingsComboBox.ValueMember = "Names"; 48 WingBindingsComboBox.ValueMember = "MouseKeyBindings";
42 WingBindingsComboBox.DataSource = WingBindingSource; 49 WingBindingsComboBox.DataSource = WingBindingsComboBoxSource;
43   50  
44 // Start lobby message synchronizer. 51 // Start lobby message synchronizer.
-   52 LobbyMessageSynchronizer = new LobbyMessageSynchronizer(MQTTCommunication, FormTaskScheduler,
45 LobbyMessageSynchronizer = new LobbyMessageSynchronizer(MQTTCommunication); 53 FormCancellationTokenSource.Token);
46 LobbyMessageSynchronizer.OnLobbyMessageReceived += OnLobbyMessageReceived; 54 LobbyMessageSynchronizer.OnLobbyMessageReceived += OnLobbyMessageReceived;
47   55  
48 // Start mouse key bindings synchronizer. 56 // Start mouse key bindings synchronizer.
49 MouseKeyBindingsSynchronizer = new MouseKeyBindingsSynchronizer(MouseKeyBindings, MQTTCommunication); 57 MouseKeyBindingsSynchronizer = new MouseKeyBindingsSynchronizer(MouseKeyBindings, MQTTCommunication,
-   58 FormTaskScheduler, FormCancellationTokenSource.Token);
50 MouseKeyBindingsSynchronizer.OnMouseKeyBindingsSynchronized += OnMouseKeyBindingsSynchronized; 59 MouseKeyBindingsSynchronizer.OnMouseKeyBindingsSynchronized += OnMouseKeyBindingsSynchronized;
51 } 60 }
52   61  
53 private void OnMouseKeyBindingsSynchronized(object sender, MouseKeyBindingsSynchronizedEventArgs e) -  
54 { -  
55 foreach (var binding in e.ExchangeBindings) -  
56 { -  
57 ActivityTextBox.AppendText( -  
58 $"{Strings.Synchronized_bindings_with_client} : {binding.Nick} : {binding.Names.Count}{Environment.NewLine}"); -  
59   -  
60   -  
61 var exchangeBindings = MouseKeyBindingsExchange.ExchangeBindings.FirstOrDefault(exchangeBinding => -  
62 string.Equals(exchangeBinding.Nick, binding.Nick, StringComparison.Ordinal)); -  
63   -  
64 // If the nick has not been registered add it. -  
65 if (exchangeBindings == null) -  
66 { -  
67 MouseKeyBindingsExchange.ExchangeBindings.Add(binding); -  
68 continue; -  
69 } -  
70   -  
71 // If the nick has been added, then update the binding names. -  
72 exchangeBindings.Names = binding.Names; -  
73   -  
74 // Update wing list box. -  
75 var selectedExchangeBinding = (MouseKeyBindingExchange) WingBindingsComboBox.SelectedItem; -  
76 if (selectedExchangeBinding == null || !string.Equals(selectedExchangeBinding.Nick, binding.Nick)) -  
77 continue; -  
78   -  
79 WingBindingsListBox.Items.Clear(); -  
80 WingBindingsListBox.DisplayMember = "Name"; -  
81 WingBindingsListBox.ValueMember = "Name"; -  
82 WingBindingsListBox.Items.AddRange(exchangeBindings.Names.Select(name => (object) name).ToArray()); -  
83   -  
84 } -  
85   -  
86 WingBindingSource.ResetBindings(false); -  
87 } 62 private static CancellationTokenSource FormCancellationTokenSource { get; set; }
88   63  
89 private static TaskScheduler FormTaskScheduler { get; set; } 64 private static TaskScheduler FormTaskScheduler { get; set; }
90   65  
91 private static IKeyboardMouseEvents MouseKeyApplicationHook { get; set; } 66 private static IKeyboardMouseEvents MouseKeyApplicationHook { get; set; }
92   67  
93 private List<string> MouseKeyCombo { get; set; } 68 private List<string> MouseKeyCombo { get; set; }
94   69  
95 private MouseKeyBindings MouseKeyBindings { get; } 70 private MouseKeyBindings MouseKeyBindings { get; }
96   71  
97 private BindingSource HelmBindingSource { get; } 72 private BindingSource HelmListBoxBindingSource { get; }
98   73  
99 private BindingSource WingBindingSource { get; set; } 74 private BindingSource WingBindingsComboBoxSource { get; }
100   75  
101 private MouseKeyBindingsExchange MouseKeyBindingsExchange { get; set; } 76 private MouseKeyBindingsExchange MouseKeyBindingsExchange { get; }
102   77  
103 public MQTTCommunication MQTTCommunication { get; set; } 78 public MQTTCommunication MQTTCommunication { get; set; }
104   79  
105 public LobbyMessageSynchronizer LobbyMessageSynchronizer { get; set; } 80 public LobbyMessageSynchronizer LobbyMessageSynchronizer { get; set; }
106   81  
107 public MouseKeyBindingsSynchronizer MouseKeyBindingsSynchronizer { get; set; } 82 public MouseKeyBindingsSynchronizer MouseKeyBindingsSynchronizer { get; set; }
-   83  
-   84 /// <summary>
-   85 /// Clean up any resources being used.
-   86 /// </summary>
-   87 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
-   88 protected override void Dispose(bool disposing)
-   89 {
-   90 if (disposing && components != null)
-   91 {
-   92 FormCancellationTokenSource.Dispose();
-   93 FormCancellationTokenSource = null;
-   94  
-   95 components.Dispose();
-   96 }
-   97  
-   98 base.Dispose(disposing);
-   99 }
-   100  
-   101 private void OnMouseKeyBindingsSynchronized(object sender, MouseKeyBindingsSynchronizedEventArgs e)
-   102 {
-   103 ActivityTextBox.AppendText(
-   104 $"{Strings.Synchronized_bindings_with_client} : {e.Bindings.Nick} : {e.Bindings.MouseKeyBindings.Count}{Environment.NewLine}");
-   105  
-   106 var exchangeBindings = MouseKeyBindingsExchange.ExchangeBindings.FirstOrDefault(exchangeBinding =>
-   107 string.Equals(exchangeBinding.Nick, e.Bindings.Nick, StringComparison.Ordinal));
-   108  
-   109 // If the nick does not exist then add it.
-   110 if (exchangeBindings == null)
-   111 {
-   112 MouseKeyBindingsExchange.ExchangeBindings.Add(e.Bindings);
-   113 WingBindingsComboBoxSource.ResetBindings(false);
-   114 UpdateWingListBoxItems();
-   115 return;
-   116 }
-   117  
-   118 // If the bindings for the nick have not changed then do not update.
-   119 if (exchangeBindings.MouseKeyBindings.SequenceEqual(e.Bindings.MouseKeyBindings))
-   120 {
-   121 WingBindingsComboBoxSource.ResetBindings(false);
-   122 UpdateWingListBoxItems();
-   123 return;
-   124 }
-   125  
-   126 // Update the bindings.
-   127 exchangeBindings.MouseKeyBindings = e.Bindings.MouseKeyBindings;
-   128 WingBindingsComboBoxSource.ResetBindings(false);
-   129 UpdateWingListBoxItems();
-   130 }
-   131  
-   132 private void UpdateWingListBoxItems()
-   133 {
-   134 var exchangeBinding = (List<MouseKeyBinding>) WingBindingsComboBox.SelectedValue;
-   135 if (exchangeBinding == null)
-   136 return;
-   137  
-   138 WingBindingsListBox.Items.Clear();
-   139 WingBindingsListBox.DisplayMember = "Name";
-   140 WingBindingsListBox.ValueMember = "Name";
-   141 var i = exchangeBinding.Select(binding => (object) binding.Name).ToArray();
-   142 if (i.Length == 0)
-   143 return;
-   144  
-   145 WingBindingsListBox.Items.AddRange(i);
-   146 }
108   147  
109 private void OnLobbyMessageReceived(object sender, LobbyMessageReceivedEventArgs e) 148 private void OnLobbyMessageReceived(object sender, LobbyMessageReceivedEventArgs e)
110 { 149 {
111 LobbyTextBox.Invoke((MethodInvoker) delegate 150 LobbyTextBox.Invoke((MethodInvoker) delegate
112 { 151 {
113 LobbyTextBox.AppendText($"{e.Nick} : {e.Message}{Environment.NewLine}"); 152 LobbyTextBox.AppendText($"{e.Nick} : {e.Message}{Environment.NewLine}");
114 }); 153 });
115 } 154 }
116   155  
117 private void AddressTextBoxClick(object sender, EventArgs e) 156 private void AddressTextBoxClick(object sender, EventArgs e)
118 { 157 {
119 Address.BackColor = Color.Empty; 158 Address.BackColor = Color.Empty;
120 } 159 }
121   160  
122 private void PortTextBoxClick(object sender, EventArgs e) 161 private void PortTextBoxClick(object sender, EventArgs e)
123 { 162 {
124 Port.BackColor = Color.Empty; 163 Port.BackColor = Color.Empty;
125 } 164 }
126   165  
127 private async void HostButtonClickAsync(object sender, EventArgs e) 166 private async void HostButtonClickAsync(object sender, EventArgs e)
128 { 167 {
129 // Stop the MQTT server if it is running. 168 // Stop the MQTT server if it is running.
130 if (MQTTCommunication.Running) 169 if (MQTTCommunication.Running)
131 { 170 {
132 await MQTTCommunication.Stop().ConfigureAwait(false); 171 await MQTTCommunication.Stop().ConfigureAwait(false);
133 toolStripStatusLabel.Text = Strings.Server_stopped; 172 toolStripStatusLabel.Text = Strings.Server_stopped;
134 HostButton.BackColor = Color.Empty; 173 HostButton.BackColor = Color.Empty;
135   174  
136 // Enable controls. 175 // Enable controls.
137 ConnectButton.Enabled = true; 176 ConnectButton.Enabled = true;
138 Address.Enabled = true; 177 Address.Enabled = true;
139 Port.Enabled = true; 178 Port.Enabled = true;
140 Nick.Enabled = true; 179 Nick.Enabled = true;
141   180  
142 return; 181 return;
143 } 182 }
144   183  
145 if (!ValidateAddressPort(out var ipAddress, out var port, out var nick)) 184 if (!ValidateAddressPort(out var ipAddress, out var port, out var nick))
146 return; 185 return;
147   186  
148 // Start the MQTT server. 187 // Start the MQTT server.
149 await MQTTCommunication.Start(MQTTCommunicationType.Server, ipAddress, port, nick).ConfigureAwait(false); 188 await MQTTCommunication.Start(MQTTCommunicationType.Server, ipAddress, port, nick).ConfigureAwait(false);
150 toolStripStatusLabel.Text = Strings.Server_started; 189 toolStripStatusLabel.Text = Strings.Server_started;
151 HostButton.BackColor = Color.Aquamarine; 190 HostButton.BackColor = Color.Aquamarine;
152   191  
153 // Disable controls 192 // Disable controls
154 ConnectButton.Enabled = false; 193 ConnectButton.Enabled = false;
155 Address.Enabled = false; 194 Address.Enabled = false;
156 Port.Enabled = false; 195 Port.Enabled = false;
157 Nick.Enabled = false; 196 Nick.Enabled = false;
158 } 197 }
159   198  
160 private bool ValidateAddressPort(out IPAddress address, out int port, out string nick) 199 private bool ValidateAddressPort(out IPAddress address, out int port, out string nick)
161 { 200 {
162 address = IPAddress.Any; 201 address = IPAddress.Any;
163 port = 0; 202 port = 0;
164 nick = string.Empty; 203 nick = string.Empty;
165   204  
166 if (string.IsNullOrEmpty(Address.Text) && 205 if (string.IsNullOrEmpty(Address.Text) &&
167 string.IsNullOrEmpty(Port.Text) && 206 string.IsNullOrEmpty(Port.Text) &&
168 string.IsNullOrEmpty(Nick.Text)) 207 string.IsNullOrEmpty(Nick.Text))
169 { 208 {
170 Address.BackColor = Color.LightPink; 209 Address.BackColor = Color.LightPink;
171 Port.BackColor = Color.LightPink; 210 Port.BackColor = Color.LightPink;
172 Nick.BackColor = Color.LightPink; 211 Nick.BackColor = Color.LightPink;
173 return false; 212 return false;
174 } 213 }
175   214  
176 if (!IPAddress.TryParse(Address.Text, out address)) 215 if (!IPAddress.TryParse(Address.Text, out address))
177 { 216 {
178 Address.BackColor = Color.LightPink; 217 Address.BackColor = Color.LightPink;
179 return false; 218 return false;
180 } 219 }
181   220  
182 if (!uint.TryParse(Port.Text, out var uPort)) 221 if (!uint.TryParse(Port.Text, out var uPort))
183 { 222 {
184 Port.BackColor = Color.LightPink; 223 Port.BackColor = Color.LightPink;
185 return false; 224 return false;
186 } 225 }
187   226  
188 port = (int) uPort; 227 port = (int) uPort;
189   228  
190 if (string.IsNullOrEmpty(Nick.Text)) 229 if (string.IsNullOrEmpty(Nick.Text))
191 { 230 {
192 Nick.BackColor = Color.LightPink; 231 Nick.BackColor = Color.LightPink;
193 return false; 232 return false;
194 } 233 }
195   234  
196 nick = Nick.Text; 235 nick = Nick.Text;
197   236  
198 Address.BackColor = Color.Empty; 237 Address.BackColor = Color.Empty;
199 Port.BackColor = Color.Empty; 238 Port.BackColor = Color.Empty;
200 Nick.BackColor = Color.Empty; 239 Nick.BackColor = Color.Empty;
201   240  
202 return true; 241 return true;
203 } 242 }
204   243  
205 private async void ConnectButtonClickAsync(object sender, EventArgs e) 244 private async void ConnectButtonClickAsync(object sender, EventArgs e)
206 { 245 {
207 if (MQTTCommunication.Running) 246 if (MQTTCommunication.Running)
208 { 247 {
209 await MQTTCommunication.Stop().ConfigureAwait(false); 248 await MQTTCommunication.Stop().ConfigureAwait(false);
210 ConnectButton.Text = Strings.Connect; 249 ConnectButton.Text = Strings.Connect;
211 ConnectButton.BackColor = Color.Empty; 250 ConnectButton.BackColor = Color.Empty;
212   251  
213 Address.Enabled = true; 252 Address.Enabled = true;
214 Port.Enabled = true; 253 Port.Enabled = true;
215 Nick.Enabled = true; 254 Nick.Enabled = true;
216 HostButton.Enabled = true; 255 HostButton.Enabled = true;
217 return; 256 return;
218 } 257 }
219   258  
220 if (!ValidateAddressPort(out var ipAddress, out var port, out var nick)) 259 if (!ValidateAddressPort(out var ipAddress, out var port, out var nick))
221 return; 260 return;
222   261  
223 await MQTTCommunication.Start(MQTTCommunicationType.Client, ipAddress, port, nick).ConfigureAwait(false); 262 await MQTTCommunication.Start(MQTTCommunicationType.Client, ipAddress, port, nick).ConfigureAwait(false);
224   263  
225 toolStripStatusLabel.Text = Strings.Client_started; 264 toolStripStatusLabel.Text = Strings.Client_started;
226 ConnectButton.Text = Strings.Disconnect; 265 ConnectButton.Text = Strings.Disconnect;
227 ConnectButton.BackColor = Color.Aquamarine; 266 ConnectButton.BackColor = Color.Aquamarine;
228   267  
229 HostButton.Enabled = false; 268 HostButton.Enabled = false;
230 Address.Enabled = false; 269 Address.Enabled = false;
231 Port.Enabled = false; 270 Port.Enabled = false;
232 Nick.Enabled = false; 271 Nick.Enabled = false;
233 } 272 }
234   273  
235 private async void LobbySayTextBoxKeyDown(object sender, KeyEventArgs e) 274 private async void LobbySayTextBoxKeyDown(object sender, KeyEventArgs e)
236 { 275 {
237 if (e.KeyCode != Keys.Enter) 276 if (e.KeyCode != Keys.Enter)
238 return; 277 return;
239   278  
240 await LobbyMessageSynchronizer.Broadcast(LobbySayTextBox.Text).ConfigureAwait(false); 279 await LobbyMessageSynchronizer.Broadcast(LobbySayTextBox.Text).ConfigureAwait(false);
241   280  
242 LobbySayTextBox.Text = string.Empty; 281 LobbySayTextBox.Text = string.Empty;
243 } 282 }
244   283  
245 private void HelmAddButtonClick(object sender, EventArgs e) 284 private void HelmAddButtonClick(object sender, EventArgs e)
246 { 285 {
247 if (string.IsNullOrEmpty(HelmNameTextBox.Text)) 286 if (string.IsNullOrEmpty(HelmNameTextBox.Text))
248 { 287 {
249 HelmNameTextBox.BackColor = Color.LightPink; 288 HelmNameTextBox.BackColor = Color.LightPink;
250 return; 289 return;
251 } 290 }
252   291  
253 HelmAddButton.Enabled = false; 292 HelmAddButton.Enabled = false;
254   293  
255 MouseKeyCombo = new List<string>(); 294 MouseKeyCombo = new List<string>();
256   295  
257 MouseKeyApplicationHook = Hook.AppEvents(); 296 MouseKeyApplicationHook = Hook.AppEvents();
258 MouseKeyApplicationHook.MouseDown += MouseKeyHookOnMouseDown; 297 MouseKeyApplicationHook.MouseDown += MouseKeyHookOnMouseDown;
259 MouseKeyApplicationHook.KeyUp += MouseKeyHookOnKeyUp; 298 MouseKeyApplicationHook.KeyUp += MouseKeyHookOnKeyUp;
260 MouseKeyApplicationHook.KeyDown += MouseKeyHookOnKeyDown; 299 MouseKeyApplicationHook.KeyDown += MouseKeyHookOnKeyDown;
261 MouseKeyApplicationHook.MouseUp += MouseKeyHookOnMouseUp; 300 MouseKeyApplicationHook.MouseUp += MouseKeyHookOnMouseUp;
262 } 301 }
263   302  
264 private void MouseKeyHookOnKeyUp(object sender, KeyEventArgs e) 303 private void MouseKeyHookOnKeyUp(object sender, KeyEventArgs e)
265 { 304 {
266 MouseKeyBindings.Bindings.Add(new MouseKeyBinding(HelmNameTextBox.Text, MouseKeyCombo)); 305 MouseKeyBindings.Bindings.Add(new MouseKeyBinding(HelmNameTextBox.Text, MouseKeyCombo));
267   306  
268 HelmBindingSource.ResetBindings(false); 307 HelmListBoxBindingSource.ResetBindings(false);
269   308  
270 MouseKeyApplicationHook.KeyDown -= MouseKeyHookOnKeyDown; 309 MouseKeyApplicationHook.KeyDown -= MouseKeyHookOnKeyDown;
271 MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp; 310 MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp;
272 MouseKeyApplicationHook.KeyDown -= MouseKeyHookOnKeyDown; 311 MouseKeyApplicationHook.KeyDown -= MouseKeyHookOnKeyDown;
273 MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp; 312 MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp;
274   313  
275 MouseKeyApplicationHook.Dispose(); 314 MouseKeyApplicationHook.Dispose();
276   315  
277 HelmNameTextBox.Text = string.Empty; 316 HelmNameTextBox.Text = string.Empty;
278 HelmAddButton.Enabled = true; 317 HelmAddButton.Enabled = true;
279 } 318 }
280   319  
281 private void MouseKeyHookOnMouseUp(object sender, MouseEventArgs e) 320 private void MouseKeyHookOnMouseUp(object sender, MouseEventArgs e)
282 { 321 {
283 MouseKeyBindings.Bindings.Add(new MouseKeyBinding(HelmNameTextBox.Text, MouseKeyCombo)); 322 MouseKeyBindings.Bindings.Add(new MouseKeyBinding(HelmNameTextBox.Text, MouseKeyCombo));
284   323  
285 HelmBindingSource.ResetBindings(false); 324 HelmListBoxBindingSource.ResetBindings(false);
286   325  
287 MouseKeyApplicationHook.KeyDown -= MouseKeyHookOnKeyDown; 326 MouseKeyApplicationHook.KeyDown -= MouseKeyHookOnKeyDown;
288 MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp; 327 MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp;
289 MouseKeyApplicationHook.KeyDown -= MouseKeyHookOnKeyDown; 328 MouseKeyApplicationHook.KeyDown -= MouseKeyHookOnKeyDown;
290 MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp; 329 MouseKeyApplicationHook.KeyUp -= MouseKeyHookOnKeyUp;
291   330  
292 MouseKeyApplicationHook.Dispose(); 331 MouseKeyApplicationHook.Dispose();
293   332  
294 HelmNameTextBox.Text = string.Empty; 333 HelmNameTextBox.Text = string.Empty;
295 HelmAddButton.Enabled = true; 334 HelmAddButton.Enabled = true;
296 } 335 }
297   336  
298   337  
299 private void MouseKeyHookOnMouseDown(object sender, MouseEventArgs e) 338 private void MouseKeyHookOnMouseDown(object sender, MouseEventArgs e)
300 { 339 {
301 MouseKeyCombo.Add(e.Button.ToDisplayName()); 340 MouseKeyCombo.Add(e.Button.ToDisplayName());
302 } 341 }
303   342  
304 private void MouseKeyHookOnKeyDown(object sender, KeyEventArgs e) 343 private void MouseKeyHookOnKeyDown(object sender, KeyEventArgs e)
305 { 344 {
306 e.SuppressKeyPress = true; 345 e.SuppressKeyPress = true;
307   346  
308 MouseKeyCombo.Add(e.KeyCode.ToDisplayName()); 347 MouseKeyCombo.Add(e.KeyCode.ToDisplayName());
309 } 348 }
310   349  
311 private void HelmNameTextBoxClick(object sender, EventArgs e) 350 private void HelmNameTextBoxClick(object sender, EventArgs e)
312 { 351 {
313 HelmNameTextBox.BackColor = Color.Empty; 352 HelmNameTextBox.BackColor = Color.Empty;
314 } 353 }
315   354  
316 private void HelmRemoveButtonClick(object sender, EventArgs e) 355 private void HelmRemoveButtonClick(object sender, EventArgs e)
317 { 356 {
318 var helmBinding = (MouseKeyBinding) HelmBindingsListBox.SelectedItem; 357 var helmBinding = (MouseKeyBinding) HelmBindingsListBox.SelectedItem;
319 if (helmBinding == null) 358 if (helmBinding == null)
320 return; 359 return;
321   360  
322 MouseKeyBindings.Bindings.Remove(helmBinding); 361 MouseKeyBindings.Bindings.Remove(helmBinding);
323 HelmBindingSource.ResetBindings(false); 362 HelmListBoxBindingSource.ResetBindings(false);
324 } 363 }
325   364  
326 private async void LobbySayButtonClick(object sender, EventArgs e) 365 private async void LobbySayButtonClick(object sender, EventArgs e)
327 { 366 {
328 await LobbyMessageSynchronizer.Broadcast(LobbySayTextBox.Text).ConfigureAwait(false); 367 await LobbyMessageSynchronizer.Broadcast(LobbySayTextBox.Text).ConfigureAwait(false);
329   368  
330 LobbySayTextBox.Text = string.Empty; 369 LobbySayTextBox.Text = string.Empty;
331 } 370 }
332   371  
333 private void WingBindingsComboBoxSelectionChangeCompleted(object sender, EventArgs e) 372 private void WingBindingsComboBoxSelectionChangeCompleted(object sender, EventArgs e)
334 { 373 {
335 var exchangeBinding = (MouseKeyBindingExchange)WingBindingsComboBox.SelectedItem; -  
336 if (exchangeBinding == null) -  
337 return; -  
338   -  
339 WingBindingsListBox.Items.Clear(); 374 UpdateWingListBoxItems();
340 WingBindingsListBox.DisplayMember = "Name"; -  
341 WingBindingsListBox.ValueMember = "Name"; -  
342 WingBindingsListBox.Items.AddRange(exchangeBinding.Names.Select(name => (object)name).ToArray()); -  
343 } 375 }
344 } 376 }
345 } 377 }
346   378