|
20 | 20 | using System.Diagnostics; |
21 | 21 | using System.Drawing; |
22 | 22 | using System.Linq; |
| 23 | +using System.Reflection; |
23 | 24 | using System.Text.RegularExpressions; |
24 | 25 | using System.Windows.Forms; |
25 | 26 | using GNU.Gettext; |
@@ -193,6 +194,110 @@ void InitializeForm() |
193 | 194 | float[] dashPattern = { 4, 2 }; |
194 | 195 | ZoomTargetPen.DashPattern = dashPattern; |
195 | 196 | pathPen.DashPattern = dashPattern; |
| 197 | + |
| 198 | + setDefaults(this); |
| 199 | + } |
| 200 | + |
| 201 | + // |
| 202 | + // set the defaults for all the map controls which have a property in UserSettings.c |
| 203 | + // properties are stored in the registry or in a .ini file |
| 204 | + // |
| 205 | + private void setDefaults(System.Windows.Forms.Control controlToSet) |
| 206 | + { |
| 207 | + foreach (System.Windows.Forms.Control control in controlToSet.Controls) |
| 208 | + { |
| 209 | + // recursive call to find deeper controls |
| 210 | + setDefaults(control); |
| 211 | + } |
| 212 | + |
| 213 | + string name = "Map_" + controlToSet.Name; |
| 214 | + PropertyInfo property = Viewer.Settings.GetProperty(name); |
| 215 | + if (property != null) |
| 216 | + { |
| 217 | + if (controlToSet is CheckBox checkBox) |
| 218 | + { |
| 219 | + checkBox.Checked = (bool)property.GetValue(Viewer.Settings); |
| 220 | + checkBox.CheckedChanged += c_ControlChanged; |
| 221 | + } |
| 222 | + if (controlToSet is NumericUpDown numericUpDown) |
| 223 | + { |
| 224 | + numericUpDown.Value = (int)property.GetValue(Viewer.Settings, null); |
| 225 | + numericUpDown.ValueChanged += c_ControlChanged; |
| 226 | + } |
| 227 | + if (controlToSet is Button button) |
| 228 | + { |
| 229 | + if (name.Equals("Map_rotateThemesButton")) |
| 230 | + { |
| 231 | + ThemeName = (string)property.GetValue(Viewer.Settings, null); |
| 232 | + Theme = MapThemeProvider.GetTheme(ThemeName); |
| 233 | + |
| 234 | + ApplyThemeRecursively(this); |
| 235 | + MapCanvasColor = Theme.MapCanvasColor; |
| 236 | + TrackPen.Color = Theme.TrackColor; |
| 237 | + } |
| 238 | + button.Click += c_ControlChanged; |
| 239 | + } |
| 240 | + if (controlToSet is RadioButton radioButton) |
| 241 | + { |
| 242 | + radioButton.Checked = (bool)property.GetValue(Viewer.Settings); |
| 243 | + radioButton.CheckedChanged += c_ControlChanged; |
| 244 | + } |
| 245 | + if (controlToSet is MapViewer mapViewer) |
| 246 | + { |
| 247 | + Size size = new Size( |
| 248 | + ((int[])property.GetValue(Viewer.Settings, null))[2], |
| 249 | + ((int[])property.GetValue(Viewer.Settings, null))[3]); |
| 250 | + Size = size; |
| 251 | + |
| 252 | + StartPosition = FormStartPosition.Manual; |
| 253 | + this.Location = new System.Drawing.Point( |
| 254 | + ((int[])property.GetValue(Viewer.Settings, null))[0], |
| 255 | + ((int[])property.GetValue(Viewer.Settings, null))[1]); |
| 256 | + |
| 257 | + mapViewer.Resize += c_ControlChanged; |
| 258 | + mapViewer.Move += c_ControlChanged; |
| 259 | + } |
| 260 | + } |
| 261 | + } |
| 262 | + |
| 263 | + // |
| 264 | + // save the setting of a map control |
| 265 | + // |
| 266 | + void c_ControlChanged(object sender, EventArgs e) |
| 267 | + { |
| 268 | + if (sender is CheckBox checkBox) |
| 269 | + { |
| 270 | + string name = "Map_" + checkBox.Name; |
| 271 | + Viewer.Settings.GetProperty(name).SetValue(Viewer.Settings, checkBox.CheckState == CheckState.Checked, null); |
| 272 | + Viewer.Settings.Save(name); |
| 273 | + } |
| 274 | + if (sender is NumericUpDown numericUpDown) |
| 275 | + { |
| 276 | + string name = "Map_" + numericUpDown.Name; |
| 277 | + Viewer.Settings.GetProperty(name).SetValue(Viewer.Settings, (int)numericUpDown.Value, null); |
| 278 | + Viewer.Settings.Save(name); |
| 279 | + } |
| 280 | + if (sender is Button button) |
| 281 | + { |
| 282 | + string name = "Map_" + button.Name; |
| 283 | + Viewer.Settings.GetProperty(name).SetValue(Viewer.Settings, ThemeName, null); |
| 284 | + Viewer.Settings.Save(name); |
| 285 | + } |
| 286 | + if (sender is RadioButton radioButton) |
| 287 | + { |
| 288 | + string name = "Map_" + radioButton.Name; |
| 289 | + Viewer.Settings.GetProperty(name).SetValue(Viewer.Settings, radioButton.Checked, null); |
| 290 | + Viewer.Settings.Save(name); |
| 291 | + } |
| 292 | + if (sender is MapViewer mapViewer) |
| 293 | + { |
| 294 | + string name = "Map_" + mapViewer.Name; |
| 295 | + |
| 296 | + int X = this.Bounds.X; |
| 297 | + int Y = this.Bounds.Y; |
| 298 | + Viewer.Settings.GetProperty(name).SetValue(Viewer.Settings, new int[] { X, Y, Size.Width, Size.Height }, null); |
| 299 | + Viewer.Settings.Save(name); |
| 300 | + } |
196 | 301 | } |
197 | 302 |
|
198 | 303 | #region initData |
|
0 commit comments