Winify – Blame information for rev 55

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 using System;
4 office 2 using System.Linq;
30 office 3 using System.Threading;
1 office 4 using System.Windows.Forms;
15 office 5 using Announcements;
6 office 6 using Servers;
1 office 7 using Winify.Utilities;
48 office 8 using static System.Windows.Forms.VisualStyles.VisualStyleElement;
1 office 9  
25 office 10 namespace Winify.Settings
1 office 11 {
12 public partial class SettingsForm : Form
13 {
25 office 14 #region Public Events & Delegates
15  
16 public event EventHandler<SettingsSavedEventArgs> Save;
17  
18 #endregion
19  
4 office 20 #region Private Delegates, Events, Enums, Properties, Indexers and Fields
21  
21 office 22 private readonly BindingSource _announcementBindingSource;
15 office 23  
55 office 24 private Announcements.Announcements _announcements;
21 office 25  
26 private readonly BindingSource _serverBindingSource;
27  
55 office 28 private Servers.Servers _servers;
4 office 29  
21 office 30 private Announcement _announcement;
31  
32 private Server _server;
30 office 33 private readonly MainForm _mainForm;
34 private readonly CancellationToken _cancellationToken;
44 office 35 private readonly BindingSource _configurationBindingSource;
50 office 36 private readonly BindingSource _configurationProxyBindingSource;
21 office 37  
4 office 38 #endregion
39  
1 office 40 #region Constructors, Destructors and Finalizers
41  
30 office 42 public SettingsForm()
1 office 43 {
44 InitializeComponent();
55 office 45  
44 office 46 Utilities.WindowState.FormTracker.Track(this);
1 office 47 }
48  
55 office 49 public SettingsForm(MainForm mainForm, Servers.Servers servers, Announcements.Announcements announcements,
50 CancellationToken cancellationToken) : this()
4 office 51 {
30 office 52 _mainForm = mainForm;
4 office 53 _servers = servers;
55 office 54 _announcements = announcements;
30 office 55 _cancellationToken = cancellationToken;
7 office 56  
44 office 57 _configurationBindingSource = new BindingSource();
58 _configurationBindingSource.DataSource = _mainForm.Configuration;
55 office 59  
50 office 60 _configurationProxyBindingSource = new BindingSource();
61 _configurationProxyBindingSource.DataSource = _mainForm.Configuration.Proxy;
21 office 62  
55 office 63 _serverBindingSource = new BindingSource();
64 _serverBindingSource.DataSource = _server;
50 office 65  
21 office 66 _announcementBindingSource = new BindingSource();
67 _announcementBindingSource.DataSource = _announcement;
4 office 68 }
69  
1 office 70 #endregion
71  
72 #region Event Handlers
73  
74 private void CheckBox1_CheckedChanged(object sender, EventArgs e)
75 {
55 office 76  
1 office 77 }
78  
4 office 79 private void Button1_Click(object sender, EventArgs e)
80 {
21 office 81 var server = new Server();
48 office 82 server.Name = "New Server";
4 office 83  
21 office 84 _servers.Server.Add(server);
48 office 85 _serverBindingSource.DataSource = server;
25 office 86  
43 office 87 Save?.Invoke(this, new SettingsSavedEventArgs(_servers, _announcements));
88  
25 office 89 listBox1.SelectedItem = server;
4 office 90 }
91  
92 private void Button2_Click(object sender, EventArgs e)
93 {
48 office 94 var index = -1;
95  
96 if (listBox1.SelectedItem is Server server)
97 {
98 index = listBox1.Items.IndexOf(server);
99 _servers.Server.Remove(server);
100 }
101  
102 if (index >= listBox1.Items.Count)
103 {
104 --index;
105 }
106  
107 listBox1.SelectedIndex = index;
4 office 108 }
109  
110 private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
111 {
48 office 112  
28 office 113 var listBox = (ListBox)sender;
48 office 114 if (listBox.SelectedIndex == -1)
115 {
116 _serverBindingSource.DataSource = new
117 { Name = string.Empty, Url = string.Empty, Username = string.Empty, Password = string.Empty };
118 return;
119 }
4 office 120  
21 office 121 if (listBox.SelectedItem is Server server)
4 office 122 {
21 office 123 _server = server;
4 office 124  
21 office 125 _serverBindingSource.DataSource = _server;
4 office 126 }
127 }
128  
15 office 129 private void Button3_Click(object sender, EventArgs e)
130 {
44 office 131 if (listBox2.SelectedItem is Announcement announcement) _announcements.Announcement.Remove(announcement);
15 office 132 }
133  
134 private void Button4_Click(object sender, EventArgs e)
135 {
21 office 136 var announcement = new Announcement();
44 office 137 if (int.TryParse(appIdTextBox.Text, out var appId)) announcement.AppId = appId;
15 office 138  
44 office 139 if (int.TryParse(lingerTimeTextBox.Text, out var lingerTime)) announcement.LingerTime = lingerTime;
43 office 140  
21 office 141 _announcements.Announcement.Add(announcement);
25 office 142  
43 office 143 Save?.Invoke(this, new SettingsSavedEventArgs(_servers, _announcements));
144  
25 office 145 listBox2.SelectedItem = announcement;
15 office 146 }
147  
148 private void ListBox2_SelectedIndexChanged(object sender, EventArgs e)
149 {
28 office 150 var listBox = (ListBox)sender;
15 office 151  
21 office 152 if (listBox.SelectedItem is Announcement announcement)
15 office 153 {
21 office 154 _announcement = announcement;
15 office 155  
21 office 156 _announcementBindingSource.DataSource = _announcement;
15 office 157 }
158 }
159  
25 office 160 private void Button6_Click(object sender, EventArgs e)
161 {
162 Close();
163 }
164  
165 private void Button5_Click(object sender, EventArgs e)
166 {
167 Save?.Invoke(this, new SettingsSavedEventArgs(_servers, _announcements));
30 office 168  
25 office 169 Close();
170 }
171  
55 office 172 #endregion
173  
174 private void checkBox4_CheckedStateChanged(object sender, EventArgs e)
30 office 175 {
55 office 176 var checkBox = (CheckBox)sender;
177 var state = checkBox.Checked;
178 if (state)
179 {
180 ToggleTableRow(tableLayoutPanel13, 0, false);
181  
182 return;
183 }
184  
185 ToggleTableRow(tableLayoutPanel13, 0, true);
30 office 186 }
187  
55 office 188 private static void ToggleTableRow(TableLayoutPanel tableLayoutPanel, int row, bool enable)
189 {
190 var count = tableLayoutPanel.RowCount;
191 foreach (var i in Enumerable.Range(0, count))
192 {
193 var control = tableLayoutPanel.GetControlFromPosition(i, row);
194 control.Enabled = enable;
195 }
196 }
44 office 197  
55 office 198 private void SettingsForm_Load(object sender, EventArgs e)
44 office 199 {
55 office 200 // Databindings.
201 numericUpDown1.DataBindings.Add(new Binding("Value", _configurationBindingSource,
202 nameof(_mainForm.Configuration.ToastDuration), true,
203 DataSourceUpdateMode.OnPropertyChanged));
44 office 204  
55 office 205 checkBox4.DataBindings.Add(
206 new Binding("Checked", _configurationBindingSource, nameof(_mainForm.Configuration.InfiniteToastDuration), true,
207 DataSourceUpdateMode.OnPropertyChanged));
208  
209 checkBox1.DataBindings.Add(new Binding("Checked", _configurationBindingSource,
210 nameof(_mainForm.Configuration.LaunchOnBoot), true, DataSourceUpdateMode.OnPropertyChanged));
211  
212 checkBox2.DataBindings.Add(new Binding("Checked", _configurationBindingSource,
213 nameof(_mainForm.Configuration.IgnoreSelfSignedCertificates), true,
214 DataSourceUpdateMode.OnPropertyChanged));
215  
216 checkBox3.DataBindings.Add(
217 new Binding("Checked", _configurationProxyBindingSource, nameof(_mainForm.Configuration.Proxy.Enable), true,
218 DataSourceUpdateMode.OnPropertyChanged));
219 textBox1.DataBindings.Add(
220 new Binding("Text", _configurationProxyBindingSource, nameof(_mainForm.Configuration.Proxy.Url), true,
221 DataSourceUpdateMode.OnPropertyChanged));
222 textBox2.DataBindings.Add(
223 new Binding("Text", _configurationProxyBindingSource, nameof(_mainForm.Configuration.Proxy.Username), true,
224 DataSourceUpdateMode.OnPropertyChanged));
225 textBox3.DataBindings.Add(
226 new Binding("Text", _configurationProxyBindingSource, nameof(_mainForm.Configuration.Proxy.Password), true,
227 DataSourceUpdateMode.OnPropertyChanged));
228  
229 switch (_servers?.Server == null)
230 {
231 case true:
232 _servers = new Servers.Servers();
233 _server = new Server();
234 _servers.Server.Add(_server);
235 break;
236 default:
237 _server = _servers.Server.FirstOrDefault();
238 break;
239 }
240  
241 serverNameTextBox.DataBindings.Add(new Binding("Text", _serverBindingSource, nameof(_server.Name), true,
242 DataSourceUpdateMode.OnPropertyChanged));
243 serverUrlTextBox.DataBindings.Add(new Binding("Text", _serverBindingSource, nameof(_server.Url), true,
244 DataSourceUpdateMode.OnPropertyChanged));
245 serverUsernameTextBox.DataBindings.Add(new Binding("Text", _serverBindingSource, nameof(_server.Username),
246 true,
247 DataSourceUpdateMode.OnPropertyChanged));
248 serverPasswordTextBox.DataBindings.Add(new Binding("Text", _serverBindingSource, nameof(_server.Password),
249 true,
250 DataSourceUpdateMode.OnPropertyChanged));
251  
252 listBox1.DataSource = _servers.Server;
253 listBox1.DisplayMember = "Name";
254 listBox1.DataBindings.Add(new Binding("Text", _servers.Server, "Name", true,
255 DataSourceUpdateMode.OnPropertyChanged));
256  
257 switch (_announcements?.Announcement == null)
258 {
259 case true:
260 _announcements = new Announcements.Announcements();
261 _announcement = new Announcement();
262 _announcements.Announcement.Add(_announcement);
263 break;
264 default:
265 _announcement = _announcements.Announcement.FirstOrDefault();
266 break;
267 }
268  
269 appIdTextBox.DataBindings.Add(new Binding("Text", _announcementBindingSource, nameof(_announcement.AppId),
270 true,
271 DataSourceUpdateMode.OnPropertyChanged));
272 lingerTimeTextBox.DataBindings.Add(new Binding("Text", _announcementBindingSource,
273 nameof(_announcement.LingerTime), true,
274 DataSourceUpdateMode.OnPropertyChanged));
275  
276 listBox2.DataSource = _announcements.Announcement;
277 listBox2.DisplayMember = "Id";
278 listBox2.DataBindings.Add(new Binding("Text", _announcements.Announcement, "Id", true,
279 DataSourceUpdateMode.OnPropertyChanged));
280  
281 // Miscellaneous.
282 ToggleTableRow(tableLayoutPanel13, 0, !_mainForm.Configuration.InfiniteToastDuration);
44 office 283 }
1 office 284 }
285 }