Winify – Diff between revs 50 and 55

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