Winify – Blame information for rev 71

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