Skip to content

Commit 8305394

Browse files
committed
Moved general settings to .settings file
1 parent 7bee7f9 commit 8305394

File tree

6 files changed

+58
-20
lines changed

6 files changed

+58
-20
lines changed

RetailCoder.VBE/Properties/Settings.Designer.cs

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RetailCoder.VBE/Properties/Settings.settings

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,18 @@
180180
<DefaultTestStubInNewModule>false</DefaultTestStubInNewModule>
181181
&lt;/UnitTestSettings&gt;</Value>
182182
</Setting>
183+
<Setting Name="GeneralSettings" Type="Rubberduck.Settings.GeneralSettings" Scope="Application">
184+
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
185+
&lt;GeneralSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
186+
&lt;Language Code="en-US" /&gt;
187+
&lt;CanShowSplash&gt;true&lt;/CanShowSplash&gt;
188+
&lt;CanCheckVersion&gt;true&lt;/CanCheckVersion&gt;
189+
&lt;IsSmartIndenterPrompted&gt;false&lt;/IsSmartIndenterPrompted&gt;
190+
&lt;IsAutoSaveEnabled&gt;false&lt;/IsAutoSaveEnabled&gt;
191+
&lt;AutoSavePeriod&gt;10&lt;/AutoSavePeriod&gt;
192+
&lt;MinimumLogLevel&gt;6&lt;/MinimumLogLevel&gt;
193+
&lt;EnableExperimentalFeatures /&gt;
194+
&lt;/GeneralSettings&gt;</Value>
195+
</Setting>
183196
</Settings>
184197
</SettingsFile>

RetailCoder.VBE/Settings/DisplayLanguageSetting.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ public class DisplayLanguageSetting
1010
[XmlAttribute]
1111
public string Code { get; set; }
1212

13+
/// <Summary>
14+
/// Default constructor required for XML serialization.
15+
/// </Summary>
1316
public DisplayLanguageSetting()
1417
{
15-
// serialization constructor
1618
}
1719

1820
public DisplayLanguageSetting(string code)
@@ -43,8 +45,7 @@ public DisplayLanguageSetting(string code)
4345

4446
public override bool Equals(object obj)
4547
{
46-
var other = obj as DisplayLanguageSetting;
47-
return other != null && Code.Equals(other.Code);
48+
return obj is DisplayLanguageSetting other && Code.Equals(other.Code);
4849
}
4950

5051
public override int GetHashCode()

RetailCoder.VBE/Settings/GeneralConfigProvider.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ public class GeneralConfigProvider : IConfigProvider<GeneralSettings>
77
{
88
private GeneralSettings _current;
99
private readonly IPersistanceService<GeneralSettings> _persister;
10+
private readonly GeneralSettings _defaultSettings;
1011

1112
public GeneralConfigProvider(IPersistanceService<GeneralSettings> persister)
1213
{
1314
_persister = persister;
15+
_defaultSettings = new DefaultSettings<GeneralSettings>().Default;
1416
}
1517

1618
public GeneralSettings Create()
1719
{
18-
var prototype = new GeneralSettings();
19-
var updated = _persister.Load(prototype) ?? prototype;
20+
var updated = _persister.Load(_defaultSettings) ?? _defaultSettings;
2021

2122
CheckForEventsToRaise(updated);
2223
_current = updated;
@@ -26,7 +27,7 @@ public GeneralSettings Create()
2627

2728
public GeneralSettings CreateDefaults()
2829
{
29-
return new GeneralSettings();
30+
return _defaultSettings;
3031
}
3132

3233
public void Save(GeneralSettings settings)

RetailCoder.VBE/Settings/GeneralSettings.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Configuration;
34
using System.Linq;
4-
using NLog;
55
using System.Xml.Serialization;
66
using Rubberduck.Common;
77

@@ -19,6 +19,7 @@ public interface IGeneralSettings
1919
List<ExperimentalFeatures> EnableExperimentalFeatures { get; set; }
2020
}
2121

22+
[SettingsSerializeAs(SettingsSerializeAs.Xml)]
2223
[XmlType(AnonymousType = true)]
2324
public class GeneralSettings : IGeneralSettings, IEquatable<GeneralSettings>
2425
{
@@ -50,19 +51,7 @@ public int MinimumLogLevel
5051
}
5152
}
5253

53-
public List<ExperimentalFeatures> EnableExperimentalFeatures { get; set; }
54-
55-
public GeneralSettings()
56-
{
57-
Language = new DisplayLanguageSetting("en-US");
58-
CanShowSplash = true;
59-
CanCheckVersion = true;
60-
IsSmartIndenterPrompted = false;
61-
IsAutoSaveEnabled = false;
62-
AutoSavePeriod = 10;
63-
MinimumLogLevel = LogLevel.Off.Ordinal;
64-
EnableExperimentalFeatures = new List<ExperimentalFeatures>();
65-
}
54+
public List<ExperimentalFeatures> EnableExperimentalFeatures { get; set; } = new List<ExperimentalFeatures>();
6655

6756
public bool Equals(GeneralSettings other)
6857
{

RetailCoder.VBE/app.config

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,21 @@
231231
</UnitTestSettings>
232232
</value>
233233
</setting>
234+
<setting name="GeneralSettings" serializeAs="Xml">
235+
<value>
236+
<GeneralSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
237+
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
238+
<Language Code="en-US" />
239+
<CanShowSplash>true</CanShowSplash>
240+
<CanCheckVersion>true</CanCheckVersion>
241+
<IsSmartIndenterPrompted>false</IsSmartIndenterPrompted>
242+
<IsAutoSaveEnabled>false</IsAutoSaveEnabled>
243+
<AutoSavePeriod>10</AutoSavePeriod>
244+
<MinimumLogLevel>6</MinimumLogLevel>
245+
<EnableExperimentalFeatures />
246+
</GeneralSettings>
247+
</value>
248+
</setting>
234249
</Rubberduck.Properties.Settings>
235250
</applicationSettings>
236251
</configuration>

0 commit comments

Comments
 (0)