Skip to content

Commit a1a7483

Browse files
committed
Moved window settings to .settings file
1 parent 303b589 commit a1a7483

File tree

6 files changed

+74
-29
lines changed

6 files changed

+74
-29
lines changed

RetailCoder.VBE/Properties/Settings.Designer.cs

Lines changed: 21 additions & 2 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: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,18 @@
157157
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
158158
&lt;ToDoMarker xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Text="BUG" /&gt;</Value>
159159
</Setting>
160+
<Setting Name="WindowSettings" Type="Rubberduck.Settings.WindowSettings" Scope="Application">
161+
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
162+
&lt;WindowSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
163+
&lt;CodeExplorerVisibleOnStartup&gt;false&lt;/CodeExplorerVisibleOnStartup&gt;
164+
&lt;CodeInspectionsVisibleOnStartup&gt;false&lt;/CodeInspectionsVisibleOnStartup&gt;
165+
&lt;SourceControlVisibleOnStartup&gt;false&lt;/SourceControlVisibleOnStartup&gt;
166+
&lt;TestExplorerVisibleOnStartup&gt;false&lt;/TestExplorerVisibleOnStartup&gt;
167+
&lt;TodoExplorerVisibleOnStartup&gt;false&lt;/TodoExplorerVisibleOnStartup&gt;
168+
&lt;CodeExplorer_SortByName&gt;true&lt;/CodeExplorer_SortByName&gt;
169+
&lt;CodeExplorer_SortByCodeOrder&gt;false&lt;/CodeExplorer_SortByCodeOrder&gt;
170+
&lt;CodeExplorer_GroupByType&gt;false&lt;/CodeExplorer_GroupByType&gt;
171+
&lt;/WindowSettings&gt;</Value>
172+
</Setting>
160173
</Settings>
161-
</SettingsFile>
174+
</SettingsFile>

RetailCoder.VBE/Settings/DefaultSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace Rubberduck.Settings
66
public class DefaultSettings<T>
77
{
88
public IEnumerable<T> Defaults { get; }
9+
public T Default => Defaults.First();
910

1011
public DefaultSettings()
1112
{

RetailCoder.VBE/Settings/WindowConfigProvider.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,22 @@ namespace Rubberduck.Settings
55
public class WindowConfigProvider : IConfigProvider<WindowSettings>
66
{
77
private readonly IPersistanceService<WindowSettings> _persister;
8+
private readonly WindowSettings _defaultSettings;
89

910
public WindowConfigProvider(IPersistanceService<WindowSettings> persister)
1011
{
1112
_persister = persister;
13+
_defaultSettings = new DefaultSettings<WindowSettings>().Default;
1214
}
1315

1416
public WindowSettings Create()
1517
{
16-
var prototype = new WindowSettings();
17-
return _persister.Load(prototype) ?? prototype;
18+
return _persister.Load(_defaultSettings) ?? _defaultSettings;
1819
}
1920

2021
public WindowSettings CreateDefaults()
2122
{
22-
return new WindowSettings();
23+
return _defaultSettings;
2324
}
2425

2526
public void Save(WindowSettings settings)

RetailCoder.VBE/Settings/WindowSettings.cs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Configuration;
23
using System.Xml.Serialization;
34
using Rubberduck.UI;
45
using Rubberduck.UI.CodeExplorer;
@@ -24,14 +25,15 @@ public interface IWindowSettings
2425
bool IsWindowVisible(DockableToolwindowPresenter candidate);
2526
}
2627

28+
[SettingsSerializeAs(SettingsSerializeAs.Xml)]
2729
[XmlType(AnonymousType = true)]
2830
public class WindowSettings : IWindowSettings, IEquatable<WindowSettings>
2931
{
32+
/// <Summary>
33+
/// Default constructor required for XML serialization. Initializes all settings to false.
34+
/// </Summary>
3035
public WindowSettings()
31-
: this(false, false, false, false, false, true, false, false)
32-
// SortByName and SortByLocation are opposites; SortByName should start as True.
3336
{
34-
//empty constructor needed for serialization
3537
}
3638

3739
public WindowSettings(bool codeExplorerVisibleOnStartup, bool codeInspectionsVisibleOnStartup,
@@ -63,28 +65,22 @@ public bool IsWindowVisible(DockableToolwindowPresenter candidate)
6365
{
6466
//I'm sure there's a better way to do this, because this is a lazy-ass way to do it.
6567
//We're injecting into the base class, so check the derived class:
66-
if (candidate is CodeExplorerDockablePresenter)
68+
switch (candidate)
6769
{
68-
return CodeExplorerVisibleOnStartup;
70+
case CodeExplorerDockablePresenter _:
71+
return CodeExplorerVisibleOnStartup;
72+
case InspectionResultsDockablePresenter _:
73+
return CodeInspectionsVisibleOnStartup;
74+
case SourceControlDockablePresenter _:
75+
return SourceControlVisibleOnStartup;
76+
case TestExplorerDockablePresenter _:
77+
return TestExplorerVisibleOnStartup;
78+
case ToDoExplorerDockablePresenter _:
79+
return TodoExplorerVisibleOnStartup;
80+
default:
81+
//Oh. Hello. I have no clue who you are...
82+
return false;
6983
}
70-
if (candidate is InspectionResultsDockablePresenter)
71-
{
72-
return CodeInspectionsVisibleOnStartup;
73-
}
74-
if (candidate is SourceControlDockablePresenter)
75-
{
76-
return SourceControlVisibleOnStartup;
77-
}
78-
if (candidate is TestExplorerDockablePresenter)
79-
{
80-
return TestExplorerVisibleOnStartup;
81-
}
82-
if (candidate is ToDoExplorerDockablePresenter)
83-
{
84-
return TodoExplorerVisibleOnStartup;
85-
}
86-
//Oh. Hello. I have no clue who you are...
87-
return false;
8884
}
8985

9086
public bool Equals(WindowSettings other)

RetailCoder.VBE/app.config

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,21 @@
204204
xmlns:xsd="http://www.w3.org/2001/XMLSchema" Text="BUG" />
205205
</value>
206206
</setting>
207+
<setting name="WindowSettings" serializeAs="Xml">
208+
<value>
209+
<WindowSettings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
210+
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
211+
<CodeExplorerVisibleOnStartup>false</CodeExplorerVisibleOnStartup>
212+
<CodeInspectionsVisibleOnStartup>false</CodeInspectionsVisibleOnStartup>
213+
<SourceControlVisibleOnStartup>false</SourceControlVisibleOnStartup>
214+
<TestExplorerVisibleOnStartup>false</TestExplorerVisibleOnStartup>
215+
<TodoExplorerVisibleOnStartup>false</TodoExplorerVisibleOnStartup>
216+
<CodeExplorer_SortByName>true</CodeExplorer_SortByName>
217+
<CodeExplorer_SortByCodeOrder>false</CodeExplorer_SortByCodeOrder>
218+
<CodeExplorer_GroupByType>false</CodeExplorer_GroupByType>
219+
</WindowSettings>
220+
</value>
221+
</setting>
207222
</Rubberduck.Properties.Settings>
208223
</applicationSettings>
209224
</configuration>

0 commit comments

Comments
 (0)