-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetupWindow.cs
More file actions
175 lines (149 loc) · 5.73 KB
/
SetupWindow.cs
File metadata and controls
175 lines (149 loc) · 5.73 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using vatsys;
namespace vStripsPlugin
{
public partial class SetupWindow : BaseForm
{
private bool closeDialog = false;
public SetupWindow()
{
InitializeComponent();
arrivalView.BackColor = Colours.GetColour(Colours.Identities.WindowBackground);
arrivalView.ForeColor = Colours.GetColour(Colours.Identities.InteractiveText);
departureView.BackColor = Colours.GetColour(Colours.Identities.WindowBackground);
departureView.ForeColor = Colours.GetColour(Colours.Identities.InteractiveText);
// Retrieve Properties Information
//https://www.daveoncsharp.com/2009/07/using-the-settings-file-in-csharp/
t_vStripsHostIP.Text = Properties.Settings.Default.vStripsHost;
if (vStripsConnector.Airport != null)
{
airportLabel.Enabled = true;
airportLabel.Text = vStripsConnector.Airport.ICAOName;
var rwys = Airspace2.GetRunways(vStripsConnector.Airport.ICAOName);
if(rwys != null)
{
string[] split = vStripsConnector.Runways.Split(':');
string[] arwys = split[0].Split('/');
string[] drwys = split[1].Split('/');
foreach (var rwy in rwys.Select(r => r.Name).OrderBy(n => n))
{
var anode = arrivalView.Nodes.Add(rwy);
if (arwys.Contains(rwy))
anode.Checked = true;
var dnode = departureView.Nodes.Add(rwy);
if (drwys.Contains(rwy))
dnode.Checked = true;
}
arrivalView.Enabled = true;
departureView.Enabled = true;
}
}
}
/**
* On key up, checks if Enter was pressed. If so, store and update the IP
*/
private void HostIP_onKeyup(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Convert.ToChar(Keys.Return))
{
b_restartPlugin.Focus();
updateHostIP(t_vStripsHostIP.Text);
}
}
private void storeHostIPChange(object sender, EventArgs e)
{
updateHostIP(t_vStripsHostIP.Text);
}
/**
* If the Host IP has changed, try to convert the string to an IP address
* If successful, update the Preferences and update the vStripConnector HostIP
*/
private void updateHostIP(string hostip)
{
IPAddress ip;
bool result = IPAddress.TryParse(hostip, out ip);
if (result == true)
{
Properties.Settings.Default.vStripsHost = hostip; // update settings
vStripsConnector.HostIP = ip; // update hostIP
Properties.Settings.Default.Save(); // save settings
}
else // IP invalid, restore old setting
{
// Add error notification?
t_vStripsHostIP.Text = Properties.Settings.Default.vStripsHost; // put old value back
}
}
private void storeButton_Click(object sender, EventArgs e)
{
List<string> arwys = new List<string>();
List<string> drwys = new List<string>();
foreach (TreeNode node in arrivalView.Nodes)
{
if (node.Checked)
arwys.Add(node.Text);
}
foreach (TreeNode node in departureView.Nodes)
{
if (node.Checked)
drwys.Add(node.Text);
}
vStripsConnector.Runways = string.Join(":", string.Join("/", arwys), string.Join("/", drwys));
closeDialog = true;
this.Close();
}
private void cancelButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void restartButton_Click(object sender, EventArgs e)
{
vStripsConnector.Restart();
}
private void SetupWindow_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing && !closeDialog)
vStripsConnector.Runways = vStripsConnector.Runways;//resets
this.Dispose();
}
private void View_AfterCheck(object sender, TreeViewEventArgs e)
{
bool pass = false;
foreach(TreeNode node in arrivalView.Nodes)
{
if(node.Checked)
{
pass = true;
break;
}
}
if(pass)
{
pass = false;
foreach (TreeNode node in departureView.Nodes)
{
if (node.Checked)
{
pass = true;
break;
}
}
storeButton.Enabled = pass;
return;
}
storeButton.Enabled = false;
}
private void textLabel2_Click(object sender, EventArgs e)
{
}
}
}