Skip to content

Commit ea34c53

Browse files
committed
Merge pull request #142 from retailcoder/config
Configuration and Settings Dialog Cleanup
2 parents d978f62 + 2082f5e commit ea34c53

19 files changed

+623
-154
lines changed

RetailCoder.VBE/App.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,30 @@ public class App : IDisposable
1616
private readonly RubberduckMenu _menu;
1717
private readonly CodeInspectionsToolbar _codeInspectionsToolbar;
1818
private readonly IList<IInspection> _inspections;
19+
private readonly IConfigurationService _configService;
1920

2021
public App(VBE vbe, AddIn addIn)
2122
{
22-
var config = ConfigurationLoader.LoadConfiguration();
23+
_configService = new ConfigurationLoader();
2324

24-
var grammar = ConfigurationLoader.GetImplementedSyntax();
25+
var grammar = _configService.GetImplementedSyntax();
2526

26-
_inspections = ConfigurationLoader.GetImplementedCodeInspections();
27+
_inspections = _configService.GetImplementedCodeInspections();
2728

29+
var config = _configService.LoadConfiguration();
2830
EnableCodeInspections(config);
31+
2932
var parser = new Parser(grammar);
3033

31-
_menu = new RubberduckMenu(vbe, addIn, config, parser, _inspections);
34+
_menu = new RubberduckMenu(vbe, addIn, _configService, parser, _inspections);
3235
_codeInspectionsToolbar = new CodeInspectionsToolbar(vbe, parser, _inspections);
3336
}
3437

3538
private void EnableCodeInspections(Configuration config)
3639
{
3740
foreach (var inspection in _inspections)
3841
{
39-
foreach (var setting in config.UserSettings.CodeInspectinSettings.CodeInspections)
42+
foreach (var setting in config.UserSettings.CodeInspectionSettings.CodeInspections)
4043
{
4144
if (inspection.Name == setting.Name)
4245
{

RetailCoder.VBE/Config/ConfigurationLoader.cs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
namespace Rubberduck.Config
1313
{
1414
[ComVisible(false)]
15-
public static class ConfigurationLoader
15+
public class ConfigurationLoader : IConfigurationService
1616
{
17-
private static string configFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Rubberduck\rubberduck.config";
17+
private static string configFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Rubberduck", "rubberduck.config");
1818

1919
/// <summary> Saves a Configuration to Rubberduck.config XML file via Serialization.</summary>
20-
public static void SaveConfiguration<T>(T toSerialize)
20+
public void SaveConfiguration<T>(T toSerialize)
2121
{
2222
XmlSerializer xmlSerializer = new XmlSerializer(toSerialize.GetType());
2323
using (TextWriter textWriter = new StreamWriter(configFile))
@@ -28,14 +28,30 @@ public static void SaveConfiguration<T>(T toSerialize)
2828

2929
/// <summary> Loads the configuration from Rubberduck.config xml file. </summary>
3030
/// <remarks> If an IOException occurs returns a default configuration.</remarks>
31-
public static Configuration LoadConfiguration()
31+
public Configuration LoadConfiguration()
3232
{
3333
try
3434
{
3535
using (StreamReader reader = new StreamReader(configFile))
3636
{
3737
var deserializer = new XmlSerializer(typeof(Configuration));
38-
return (Configuration)deserializer.Deserialize(reader);
38+
var config = (Configuration)deserializer.Deserialize(reader);
39+
40+
//deserialization can silently fail for just parts of the config,
41+
// so we null check and return defaults if necessary.
42+
if (config.UserSettings.ToDoListSettings == null)
43+
{
44+
config.UserSettings.ToDoListSettings = new ToDoListSettings(GetDefaultTodoMarkers());
45+
}
46+
47+
if (config.UserSettings.CodeInspectionSettings == null)
48+
{
49+
config.UserSettings.CodeInspectionSettings = new CodeInspectionSettings(GetDefaultCodeInspections());
50+
}
51+
52+
//todo: check for implemented inspections that aren't in config file
53+
54+
return config;
3955
}
4056
}
4157
catch (IOException)
@@ -64,7 +80,7 @@ public static Configuration LoadConfiguration()
6480
}
6581
}
6682

67-
public static Configuration GetDefaultConfiguration()
83+
public Configuration GetDefaultConfiguration()
6884
{
6985
var userSettings = new UserSettings(
7086
new ToDoListSettings(GetDefaultTodoMarkers()),
@@ -74,7 +90,7 @@ public static Configuration GetDefaultConfiguration()
7490
return new Configuration(userSettings);
7591
}
7692

77-
public static ToDoMarker[] GetDefaultTodoMarkers()
93+
public ToDoMarker[] GetDefaultTodoMarkers()
7894
{
7995
var note = new ToDoMarker("NOTE:", TodoPriority.Low);
8096
var todo = new ToDoMarker("TODO:", TodoPriority.Normal);
@@ -85,7 +101,7 @@ public static ToDoMarker[] GetDefaultTodoMarkers()
85101

86102
/// <summary> Converts implemented code inspections into array of Config.CodeInspection objects. </summary>
87103
/// <returns> An array of Config.CodeInspection. </returns>
88-
public static CodeInspection[] GetDefaultCodeInspections()
104+
public CodeInspection[] GetDefaultCodeInspections()
89105
{
90106
var configInspections = new List<CodeInspection>();
91107
foreach (var inspection in GetImplementedCodeInspections())
@@ -97,7 +113,7 @@ public static CodeInspection[] GetDefaultCodeInspections()
97113
}
98114

99115
/// <summary> Gets all implemented code inspections via reflection </summary>
100-
public static IList<IInspection> GetImplementedCodeInspections()
116+
public IList<IInspection> GetImplementedCodeInspections()
101117
{
102118
var inspections = Assembly.GetExecutingAssembly()
103119
.GetTypes()
@@ -115,7 +131,7 @@ public static IList<IInspection> GetImplementedCodeInspections()
115131
}
116132

117133
/// <summary> Gets all implemented syntax via reflection. </summary>
118-
public static List<ISyntax> GetImplementedSyntax()
134+
public List<ISyntax> GetImplementedSyntax()
119135
{
120136
var grammar = Assembly.GetExecutingAssembly()
121137
.GetTypes()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace Rubberduck.Config
5+
{
6+
[ComVisible(false)]
7+
public interface IConfigurationService
8+
{
9+
CodeInspection[] GetDefaultCodeInspections();
10+
Configuration GetDefaultConfiguration();
11+
ToDoMarker[] GetDefaultTodoMarkers();
12+
System.Collections.Generic.IList<Rubberduck.Inspections.IInspection> GetImplementedCodeInspections();
13+
System.Collections.Generic.List<Rubberduck.VBA.Parser.Grammar.ISyntax> GetImplementedSyntax();
14+
Configuration LoadConfiguration();
15+
void SaveConfiguration<T>(T toSerialize);
16+
}
17+
}

RetailCoder.VBE/Config/UserSettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Rubberduck.Config
1313
public class UserSettings
1414
{
1515
public ToDoListSettings ToDoListSettings { get; set; }
16-
public CodeInspectionSettings CodeInspectinSettings { get; set; }
16+
public CodeInspectionSettings CodeInspectionSettings { get; set; }
1717

1818
public UserSettings()
1919
{
@@ -23,7 +23,7 @@ public UserSettings()
2323
public UserSettings(ToDoListSettings todoSettings, CodeInspectionSettings codeInspectionSettings)
2424
{
2525
this.ToDoListSettings = todoSettings;
26-
this.CodeInspectinSettings = codeInspectionSettings;
26+
this.CodeInspectionSettings = codeInspectionSettings;
2727
}
2828
}
2929
}

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<WarningLevel>4</WarningLevel>
2323
<RegisterForComInterop>true</RegisterForComInterop>
2424
<DocumentationFile>bin\Debug\Rubberduck.XML</DocumentationFile>
25+
<NoWarn>1591</NoWarn>
2526
</PropertyGroup>
2627
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2728
<DebugType>pdbonly</DebugType>
@@ -65,6 +66,8 @@
6566
<Reference Include="WindowsBase" />
6667
</ItemGroup>
6768
<ItemGroup>
69+
<Compile Include="Config\IConfigurationService.cs" />
70+
<Compile Include="UI\Settings\ITodoSettingsView.cs" />
6871
<Compile Include="VBEHost\AccessApp.cs" />
6972
<Compile Include="Config\ConfigurationLoader.cs" />
7073
<Compile Include="Config\UserSettings.cs" />
@@ -170,13 +173,13 @@
170173
<Compile Include="UI\Settings\SettingsDialog.Designer.cs">
171174
<DependentUpon>SettingsDialog.cs</DependentUpon>
172175
</Compile>
173-
<Compile Include="UI\Settings\TodoListSettingsControl.cs">
176+
<Compile Include="UI\Settings\TodoListSettingsUserControl.cs">
174177
<SubType>UserControl</SubType>
175178
</Compile>
176-
<Compile Include="UI\Settings\TodoListSettingsControl.Designer.cs">
177-
<DependentUpon>TodoListSettingsControl.cs</DependentUpon>
179+
<Compile Include="UI\Settings\TodoListSettingsUserControl.Designer.cs">
180+
<DependentUpon>TodoListSettingsUserControl.cs</DependentUpon>
178181
</Compile>
179-
<Compile Include="UI\Settings\TodoSettingModel.cs" />
182+
<Compile Include="UI\Settings\TodoSettingPresenter.cs" />
180183
<Compile Include="UI\ToDoItems\ToDoExplorerDockablePresenter.cs" />
181184
<Compile Include="UI\ToDoItems\ToDoItemClickEventArgs.cs" />
182185
<Compile Include="UI\WindowExtensions.cs" />
@@ -386,8 +389,8 @@
386389
<EmbeddedResource Include="UI\Settings\SettingsDialog.resx">
387390
<DependentUpon>SettingsDialog.cs</DependentUpon>
388391
</EmbeddedResource>
389-
<EmbeddedResource Include="UI\Settings\TodoListSettingsControl.resx">
390-
<DependentUpon>TodoListSettingsControl.cs</DependentUpon>
392+
<EmbeddedResource Include="UI\Settings\TodoListSettingsUserControl.resx">
393+
<DependentUpon>TodoListSettingsUserControl.cs</DependentUpon>
391394
</EmbeddedResource>
392395
<EmbeddedResource Include="VBA\Grammar\ReservedKeywords.resx">
393396
<Generator>PublicResXFileCodeGenerator</Generator>

RetailCoder.VBE/UI/RubberduckMenu.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,19 @@ public class RubberduckMenu : IDisposable
2525
private readonly CodeExplorerMenu _codeExplorerMenu;
2626
private readonly CodeInspectionsMenu _codeInspectionsMenu;
2727
//private readonly RefactorMenu _refactorMenu; // todo: implement refactoring
28+
private readonly IConfigurationService _configService;
2829

29-
public RubberduckMenu(VBE vbe, AddIn addIn, Configuration config, Parser parser, IEnumerable<IInspection> inspections)
30+
public RubberduckMenu(VBE vbe, AddIn addIn, IConfigurationService configService, Parser parser, IEnumerable<IInspection> inspections)
3031
{
3132
_vbe = vbe;
33+
_configService = configService;
34+
3235
_testMenu = new TestMenu(_vbe, addIn);
3336
_codeExplorerMenu = new CodeExplorerMenu(_vbe, addIn, parser);
34-
_todoItemsMenu = new ToDoItemsMenu(_vbe, addIn, config.UserSettings.ToDoListSettings, parser);
37+
38+
var todoSettings = configService.LoadConfiguration().UserSettings.ToDoListSettings;
39+
_todoItemsMenu = new ToDoItemsMenu(_vbe, addIn, todoSettings, parser);
40+
3541
_codeInspectionsMenu = new CodeInspectionsMenu(_vbe, addIn, parser, inspections);
3642
//_refactorMenu = new RefactorMenu(_vbe, addIn);
3743

@@ -78,7 +84,7 @@ private CommandBarButton AddButton(CommandBarPopup parentMenu, string caption, b
7884

7985
private void OnOptionsClick(CommandBarButton Ctrl, ref bool CancelDefault)
8086
{
81-
using (var window = new Settings.SettingsDialog())
87+
using (var window = new Settings.SettingsDialog(_configService))
8288
{
8389
window.ShowDialog();
8490
}

RetailCoder.VBE/UI/Settings/CodeInspectionControl.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ public CodeInspectionControl()
2424
public CodeInspectionControl(List<CodeInspection> inspections)
2525
: this()
2626
{
27-
_inspections = new BindingList<CodeInspection>(inspections);
27+
_inspections = new BindingList<CodeInspection>(inspections
28+
.OrderBy(c => c.InspectionType.ToString())
29+
.ThenBy(c => c.Name)
30+
.ToList()
31+
);
32+
2833
this.dataGridView1.AutoGenerateColumns = false;
2934
this.dataGridView1.DataSource = _inspections;
3035

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Rubberduck.Config;
7+
using System.ComponentModel;
8+
using System.Windows.Forms;
9+
10+
namespace Rubberduck.UI.Settings
11+
{
12+
public interface ITodoSettingsView
13+
{
14+
/// <summary>
15+
/// The TodoPriority level of the marker currently being edited.
16+
/// </summary>
17+
TodoPriority ActiveMarkerPriority { get; set; }
18+
19+
/// <summary>
20+
/// The Text (or Name) of the marker currently being edited.
21+
/// </summary>
22+
string ActiveMarkerText { get; set; }
23+
24+
/// <summary>
25+
/// List of all TodoMarkers to be displayed.
26+
/// </summary>
27+
BindingList<ToDoMarker> TodoMarkers { get; set; }
28+
29+
/// <summary>
30+
/// Zero based index of the currently selected TodoMarker.
31+
/// </summary>
32+
int SelectedIndex { get; set; }
33+
34+
/// <summary>
35+
/// Boolean value representing the enables/disabled state of the UI element the user needs to interact with to save the currently active marker.
36+
/// </summary>
37+
bool SaveEnabled { get; set; }
38+
39+
/// <summary>
40+
/// Request to remove the marker at the SelectedIndex.
41+
/// </summary>
42+
event EventHandler RemoveMarker;
43+
44+
/// <summary>
45+
/// Request to add the currently active marker to BindingList{TodoMarker}.
46+
/// </summary>
47+
event EventHandler AddMarker;
48+
49+
/// <summary>
50+
/// Request to save changes made to the currently active marker back to the marker at the SelectedIndex.
51+
/// </summary>
52+
event EventHandler SaveMarker;
53+
54+
/// <summary>
55+
/// Raised whenever SelectedIndex is changed.
56+
/// </summary>
57+
event EventHandler SelectionChanged;
58+
59+
/// <summary>
60+
/// Raised whenever ActiveMarkerText is changed.
61+
/// </summary>
62+
event EventHandler TextChanged;
63+
64+
/// <summary>
65+
/// Raised whenver ActiveMarkerPriority is changed.
66+
/// </summary>
67+
event EventHandler PriorityChanged;
68+
69+
}
70+
}

0 commit comments

Comments
 (0)