Winify – Blame information for rev 49
?pathlinks?
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 | |
21 | office | 24 | private readonly Announcements.Announcements _announcements; |
25 | |||
26 | private readonly BindingSource _serverBindingSource; |
||
27 | |||
30 | office | 28 | private readonly 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; |
21 | office | 36 | |
4 | office | 37 | #endregion |
38 | |||
1 | office | 39 | #region Constructors, Destructors and Finalizers |
40 | |||
30 | office | 41 | public SettingsForm() |
1 | office | 42 | { |
43 | InitializeComponent(); |
||
44 | office | 44 | Utilities.WindowState.FormTracker.Track(this); |
1 | office | 45 | } |
46 | |||
30 | office | 47 | public SettingsForm(MainForm mainForm) : this() |
4 | office | 48 | { |
30 | office | 49 | _mainForm = mainForm; |
50 | } |
||
51 | |||
52 | public SettingsForm(MainForm mainForm, Servers.Servers servers, Announcements.Announcements announcements, |
||
53 | CancellationToken cancellationToken) : this(mainForm) |
||
54 | { |
||
4 | office | 55 | _servers = servers; |
21 | office | 56 | _server = _servers.Server.FirstOrDefault() ?? new Server(); |
30 | office | 57 | _cancellationToken = cancellationToken; |
7 | office | 58 | |
21 | office | 59 | _serverBindingSource = new BindingSource(); |
60 | _serverBindingSource.DataSource = _server; |
||
44 | office | 61 | _configurationBindingSource = new BindingSource(); |
62 | _configurationBindingSource.DataSource = _mainForm.Configuration; |
||
21 | office | 63 | |
44 | office | 64 | checkBox1.DataBindings.Add(new Binding("Checked", _configurationBindingSource, |
65 | nameof(_mainForm.Configuration.LaunchOnBoot), true, DataSourceUpdateMode.OnPropertyChanged)); |
||
66 | |||
67 | checkBox2.DataBindings.Add(new Binding("Checked", _configurationBindingSource, |
||
68 | nameof(_mainForm.Configuration.IgnoreSelfSignedCertificates), true, DataSourceUpdateMode.OnPropertyChanged)); |
||
69 | |||
21 | office | 70 | serverNameTextBox.DataBindings.Add(new Binding("Text", _serverBindingSource, nameof(_server.Name), true, |
71 | DataSourceUpdateMode.OnPropertyChanged)); |
||
72 | serverUrlTextBox.DataBindings.Add(new Binding("Text", _serverBindingSource, nameof(_server.Url), true, |
||
73 | DataSourceUpdateMode.OnPropertyChanged)); |
||
74 | serverUsernameTextBox.DataBindings.Add(new Binding("Text", _serverBindingSource, nameof(_server.Username), |
||
75 | true, |
||
76 | DataSourceUpdateMode.OnPropertyChanged)); |
||
77 | serverPasswordTextBox.DataBindings.Add(new Binding("Text", _serverBindingSource, nameof(_server.Password), |
||
78 | true, |
||
79 | DataSourceUpdateMode.OnPropertyChanged)); |
||
80 | |||
7 | office | 81 | listBox1.DataSource = _servers.Server; |
82 | listBox1.DisplayMember = "Name"; |
||
83 | listBox1.DataBindings.Add(new Binding("Text", _servers.Server, "Name", true, |
||
84 | DataSourceUpdateMode.OnPropertyChanged)); |
||
15 | office | 85 | |
21 | office | 86 | _announcements = announcements; |
87 | _announcement = _announcements.Announcement.FirstOrDefault() ?? new Announcement(); |
||
88 | |||
89 | _announcementBindingSource = new BindingSource(); |
||
90 | _announcementBindingSource.DataSource = _announcement; |
||
91 | |||
92 | appIdTextBox.DataBindings.Add(new Binding("Text", _announcementBindingSource, nameof(_announcement.AppId), |
||
93 | true, |
||
94 | DataSourceUpdateMode.OnPropertyChanged)); |
||
95 | lingerTimeTextBox.DataBindings.Add(new Binding("Text", _announcementBindingSource, |
||
96 | nameof(_announcement.LingerTime), true, |
||
97 | DataSourceUpdateMode.OnPropertyChanged)); |
||
98 | |||
99 | listBox2.DataSource = _announcements.Announcement; |
||
15 | office | 100 | listBox2.DisplayMember = "Id"; |
21 | office | 101 | listBox2.DataBindings.Add(new Binding("Text", _announcements.Announcement, "Id", true, |
15 | office | 102 | DataSourceUpdateMode.OnPropertyChanged)); |
4 | office | 103 | } |
104 | |||
1 | office | 105 | #endregion |
106 | |||
107 | #region Event Handlers |
||
108 | |||
109 | private void CheckBox1_CheckedChanged(object sender, EventArgs e) |
||
110 | { |
||
30 | office | 111 | _mainForm.Configuration.LaunchOnBoot = ((CheckBox)sender).Checked; |
1 | office | 112 | |
30 | office | 113 | _mainForm.ChangedConfigurationContinuation.Schedule(TimeSpan.FromSeconds(1), |
114 | async () => { await _mainForm.SaveConfiguration(); }, _cancellationToken); |
||
115 | |||
116 | Miscellaneous.LaunchOnBootSet(_mainForm.Configuration.LaunchOnBoot); |
||
1 | office | 117 | } |
118 | |||
4 | office | 119 | private void Button1_Click(object sender, EventArgs e) |
120 | { |
||
21 | office | 121 | var server = new Server(); |
48 | office | 122 | server.Name = "New Server"; |
4 | office | 123 | |
21 | office | 124 | _servers.Server.Add(server); |
48 | office | 125 | _serverBindingSource.DataSource = server; |
25 | office | 126 | |
43 | office | 127 | Save?.Invoke(this, new SettingsSavedEventArgs(_servers, _announcements)); |
128 | |||
25 | office | 129 | listBox1.SelectedItem = server; |
4 | office | 130 | } |
131 | |||
132 | private void Button2_Click(object sender, EventArgs e) |
||
133 | { |
||
48 | office | 134 | var index = -1; |
135 | |||
136 | if (listBox1.SelectedItem is Server server) |
||
137 | { |
||
138 | index = listBox1.Items.IndexOf(server); |
||
139 | _servers.Server.Remove(server); |
||
140 | } |
||
141 | |||
142 | if (index >= listBox1.Items.Count) |
||
143 | { |
||
144 | --index; |
||
145 | } |
||
146 | |||
147 | listBox1.SelectedIndex = index; |
||
4 | office | 148 | } |
149 | |||
150 | private void ListBox1_SelectedIndexChanged(object sender, EventArgs e) |
||
151 | { |
||
48 | office | 152 | |
28 | office | 153 | var listBox = (ListBox)sender; |
48 | office | 154 | if (listBox.SelectedIndex == -1) |
155 | { |
||
156 | _serverBindingSource.DataSource = new |
||
157 | { Name = string.Empty, Url = string.Empty, Username = string.Empty, Password = string.Empty }; |
||
158 | return; |
||
159 | } |
||
4 | office | 160 | |
21 | office | 161 | if (listBox.SelectedItem is Server server) |
4 | office | 162 | { |
21 | office | 163 | _server = server; |
4 | office | 164 | |
21 | office | 165 | _serverBindingSource.DataSource = _server; |
4 | office | 166 | } |
167 | } |
||
168 | |||
15 | office | 169 | private void Button3_Click(object sender, EventArgs e) |
170 | { |
||
44 | office | 171 | if (listBox2.SelectedItem is Announcement announcement) _announcements.Announcement.Remove(announcement); |
15 | office | 172 | } |
173 | |||
174 | private void Button4_Click(object sender, EventArgs e) |
||
175 | { |
||
21 | office | 176 | var announcement = new Announcement(); |
44 | office | 177 | if (int.TryParse(appIdTextBox.Text, out var appId)) announcement.AppId = appId; |
15 | office | 178 | |
44 | office | 179 | if (int.TryParse(lingerTimeTextBox.Text, out var lingerTime)) announcement.LingerTime = lingerTime; |
43 | office | 180 | |
21 | office | 181 | _announcements.Announcement.Add(announcement); |
25 | office | 182 | |
43 | office | 183 | Save?.Invoke(this, new SettingsSavedEventArgs(_servers, _announcements)); |
184 | |||
25 | office | 185 | listBox2.SelectedItem = announcement; |
15 | office | 186 | } |
187 | |||
188 | private void ListBox2_SelectedIndexChanged(object sender, EventArgs e) |
||
189 | { |
||
28 | office | 190 | var listBox = (ListBox)sender; |
15 | office | 191 | |
21 | office | 192 | if (listBox.SelectedItem is Announcement announcement) |
15 | office | 193 | { |
21 | office | 194 | _announcement = announcement; |
15 | office | 195 | |
21 | office | 196 | _announcementBindingSource.DataSource = _announcement; |
15 | office | 197 | } |
198 | } |
||
199 | |||
25 | office | 200 | private void Button6_Click(object sender, EventArgs e) |
201 | { |
||
202 | Close(); |
||
203 | } |
||
204 | |||
205 | private void Button5_Click(object sender, EventArgs e) |
||
206 | { |
||
207 | Save?.Invoke(this, new SettingsSavedEventArgs(_servers, _announcements)); |
||
30 | office | 208 | |
25 | office | 209 | Close(); |
210 | } |
||
211 | |||
30 | office | 212 | private void SettingsForm_Load(object sender, EventArgs e) |
213 | { |
||
214 | checkBox1.Checked = _mainForm.Configuration.LaunchOnBoot; |
||
215 | } |
||
216 | |||
1 | office | 217 | #endregion |
44 | office | 218 | |
219 | private void CheckBox2_CheckedChanged(object sender, EventArgs e) |
||
220 | { |
||
221 | _mainForm.Configuration.IgnoreSelfSignedCertificates = ((CheckBox)sender).Checked; |
||
222 | |||
223 | _mainForm.ChangedConfigurationContinuation.Schedule(TimeSpan.FromSeconds(1), |
||
224 | async () => { await _mainForm.SaveConfiguration(); }, _cancellationToken); |
||
225 | } |
||
1 | office | 226 | } |
227 | } |