Skip to content

Commit 838ee5d

Browse files
committed
WarningManager: fix reload
1 parent 6501b1c commit 838ee5d

File tree

1 file changed

+145
-142
lines changed

1 file changed

+145
-142
lines changed

Warnings/WarningControl.cs

+145-142
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,86 @@
1-
using System;
2-
using System.Windows.Forms;
3-
4-
namespace MissionPlanner.Warnings
5-
{
6-
public class WarningControl : UserControl
7-
{
8-
public event EventHandler ReloadList;
9-
10-
public WarningControl()
11-
{
12-
InitializeComponent();
13-
}
14-
15-
public WarningControl(CustomWarning item)
16-
{
17-
InitializeComponent();
18-
19-
CustomWarning.defaultsrc = MainV2.comPort.MAV.cs;
20-
item.SetField(item.Name);
21-
22-
CMB_condition.DataSource = Enum.GetNames(typeof(CustomWarning.Conditional));
23-
CMB_color.DataSource = Enum.GetNames(typeof(CustomWarning.WarningColors));
24-
25-
CMB_Source.DataSource = item.GetOptions();
26-
27-
28-
custwarning = item;
29-
30-
updateDisplay();
31-
}
32-
33-
public void updateDisplay()
1+
using System;
2+
using System.Windows.Forms;
3+
4+
namespace MissionPlanner.Warnings
5+
{
6+
public class WarningControl : UserControl
7+
{
8+
public event EventHandler ReloadList;
9+
10+
public WarningControl()
11+
{
12+
InitializeComponent();
13+
}
14+
15+
public WarningControl(CustomWarning item)
16+
{
17+
InitializeComponent();
18+
19+
CustomWarning.defaultsrc = MainV2.comPort.MAV.cs;
20+
item.SetField(item.Name);
21+
22+
CMB_condition.DataSource = Enum.GetNames(typeof(CustomWarning.Conditional));
23+
CMB_color.DataSource = Enum.GetNames(typeof(CustomWarning.WarningColors));
24+
25+
CMB_Source.DataSource = item.GetOptions();
26+
27+
28+
custwarning = item;
29+
30+
updateDisplay();
31+
}
32+
33+
public void updateDisplay()
3434
{
3535

3636
CMB_condition.Text = custwarning.ConditionType.ToString();
3737
CMB_Source.Text = custwarning.Name;
3838
NUM_warning.Value = (decimal)custwarning.Warning;
39-
39+
4040
if (custwarning.type == CustomWarning.WarningType.SpeakAndText)
4141
{
42+
//Fire the checkedchange event to enable/disable fields
43+
CB_type.Checked = false;
44+
CB_type_CheckedChanged(null, EventArgs.Empty);
45+
4246
NUM_repeattime.Value = custwarning.RepeatTime;
43-
TXT_warningtext.Text = custwarning.Text;
44-
CMB_color.Text = "NoColor";
45-
CB_type.Checked = false;
46-
//Fire the checkedchange event to enable/disable fields
47-
CB_type_CheckedChanged(null, EventArgs.Empty);
48-
}
47+
TXT_warningtext.Text = custwarning.Text;
48+
CMB_color.Text = "NoColor";
49+
50+
}
4951
else
5052
{
53+
//Fire the checkedchange event to enable/disable fields
5154
CB_type.Checked = true;
55+
CB_type_CheckedChanged(null, EventArgs.Empty);
5256
CMB_color.Text = custwarning.color;
53-
CB_type_CheckedChanged(null, EventArgs.Empty);
54-
}
55-
56-
}
57-
58-
CustomWarning _custwarn;
59-
60-
public CustomWarning custwarning
61-
{
62-
get { return _custwarn; }
63-
set { _custwarn = value; }
64-
}
65-
66-
private ComboBox CMB_condition;
67-
private NumericUpDown NUM_warning;
68-
private NumericUpDown NUM_repeattime;
69-
public TextBox TXT_warningtext;
70-
private Controls.MyButton but_addchild;
57+
}
58+
59+
}
60+
61+
CustomWarning _custwarn;
62+
63+
public CustomWarning custwarning
64+
{
65+
get { return _custwarn; }
66+
set { _custwarn = value; }
67+
}
68+
69+
private ComboBox CMB_condition;
70+
private NumericUpDown NUM_warning;
71+
private NumericUpDown NUM_repeattime;
72+
public TextBox TXT_warningtext;
73+
private Controls.MyButton but_addchild;
7174
private Controls.MyButton but_remove;
7275
private CheckBox CB_type;
7376
private ComboBox CMB_color;
74-
private ComboBox CMB_Source;
75-
// posible child
76-
//private CustomWarning item;
77-
//private CurrentState currentState;
78-
79-
private void InitializeComponent()
80-
{
77+
private ComboBox CMB_Source;
78+
// posible child
79+
//private CustomWarning item;
80+
//private CurrentState currentState;
81+
82+
private void InitializeComponent()
83+
{
8184
this.CMB_Source = new System.Windows.Forms.ComboBox();
8285
this.CMB_condition = new System.Windows.Forms.ComboBox();
8386
this.NUM_warning = new System.Windows.Forms.NumericUpDown();
@@ -211,88 +214,88 @@ private void InitializeComponent()
211214
this.ResumeLayout(false);
212215
this.PerformLayout();
213216

214-
}
215-
216-
private void CMB_Source_SelectedIndexChanged(object sender, EventArgs e)
217-
{
218-
if (custwarning != null)
219-
custwarning.SetField(CMB_Source.Text);
220-
}
221-
222-
private void CMB_condition_SelectedIndexChanged(object sender, EventArgs e)
223-
{
224-
if (custwarning != null)
225-
custwarning.ConditionType =
226-
(CustomWarning.Conditional)Enum.Parse(typeof(CustomWarning.Conditional), CMB_condition.Text);
227-
}
217+
}
218+
219+
private void CMB_Source_SelectedIndexChanged(object sender, EventArgs e)
220+
{
221+
if (custwarning != null)
222+
custwarning.SetField(CMB_Source.Text);
223+
}
224+
225+
private void CMB_condition_SelectedIndexChanged(object sender, EventArgs e)
226+
{
227+
if (custwarning != null)
228+
custwarning.ConditionType =
229+
(CustomWarning.Conditional)Enum.Parse(typeof(CustomWarning.Conditional), CMB_condition.Text);
230+
}
228231

229232
private void cmbColor_SelectedIndexChanged(object sender, EventArgs e)
230233
{
231234
if (custwarning != null)
232235
custwarning.color = CMB_color.Text;
233236

234-
}
235-
236-
private void NUM_warning_ValueChanged(object sender, EventArgs e)
237-
{
238-
if (custwarning != null)
239-
custwarning.Warning = (double)NUM_warning.Value;
240-
}
241-
242-
private void TXT_warningtext_TextChanged(object sender, EventArgs e)
243-
{
244-
if (custwarning != null)
245-
custwarning.Text = TXT_warningtext.Text;
246-
}
247-
248-
private void NUM_repeattime_ValueChanged(object sender, EventArgs e)
249-
{
250-
if (custwarning != null)
251-
custwarning.RepeatTime = (int)NUM_repeattime.Value;
252-
}
253-
254-
private void but_addchild_Click(object sender, EventArgs e)
255-
{
256-
custwarning.Child = new CustomWarning();
257-
258-
if (ReloadList != null)
259-
ReloadList(this, null);
260-
}
261-
262-
private void but_remove_Click(object sender, EventArgs e)
263-
{
264-
lock (WarningEngine.warnings)
265-
{
266-
WarningEngine.warnings.Remove(custwarning);
267-
268-
foreach (var item in WarningEngine.warnings)
269-
{
270-
removewarning(item, custwarning);
271-
}
272-
}
273-
274-
if (ReloadList != null)
275-
ReloadList(this, null);
276-
}
277-
278-
void removewarning(CustomWarning lookin, CustomWarning removeme)
279-
{
280-
// depth first check children
281-
if (lookin.Child != null)
282-
removewarning(lookin.Child, removeme);
283-
284-
if (lookin.Child == removeme)
285-
{
286-
if (lookin.Child.Child != null)
287-
{
288-
lookin.Child = lookin.Child.Child;
289-
}
290-
else
291-
{
292-
lookin.Child = null;
293-
}
294-
return;
295-
}
237+
}
238+
239+
private void NUM_warning_ValueChanged(object sender, EventArgs e)
240+
{
241+
if (custwarning != null)
242+
custwarning.Warning = (double)NUM_warning.Value;
243+
}
244+
245+
private void TXT_warningtext_TextChanged(object sender, EventArgs e)
246+
{
247+
if (custwarning != null)
248+
custwarning.Text = TXT_warningtext.Text;
249+
}
250+
251+
private void NUM_repeattime_ValueChanged(object sender, EventArgs e)
252+
{
253+
if (custwarning != null)
254+
custwarning.RepeatTime = (int)NUM_repeattime.Value;
255+
}
256+
257+
private void but_addchild_Click(object sender, EventArgs e)
258+
{
259+
custwarning.Child = new CustomWarning();
260+
261+
if (ReloadList != null)
262+
ReloadList(this, null);
263+
}
264+
265+
private void but_remove_Click(object sender, EventArgs e)
266+
{
267+
lock (WarningEngine.warnings)
268+
{
269+
WarningEngine.warnings.Remove(custwarning);
270+
271+
foreach (var item in WarningEngine.warnings)
272+
{
273+
removewarning(item, custwarning);
274+
}
275+
}
276+
277+
if (ReloadList != null)
278+
ReloadList(this, null);
279+
}
280+
281+
void removewarning(CustomWarning lookin, CustomWarning removeme)
282+
{
283+
// depth first check children
284+
if (lookin.Child != null)
285+
removewarning(lookin.Child, removeme);
286+
287+
if (lookin.Child == removeme)
288+
{
289+
if (lookin.Child.Child != null)
290+
{
291+
lookin.Child = lookin.Child.Child;
292+
}
293+
else
294+
{
295+
lookin.Child = null;
296+
}
297+
return;
298+
}
296299
}
297300

298301
private void CB_type_CheckedChanged(object sender, EventArgs e)
@@ -326,5 +329,5 @@ private void CB_type_CheckedChanged(object sender, EventArgs e)
326329

327330
}
328331
}
329-
}
332+
}
330333
}

0 commit comments

Comments
 (0)