Skip to content

Commit

Permalink
added language settings; rubberduck-vba#566, rubberduck-vba#318 - for…
Browse files Browse the repository at this point in the history
… some reason the language displayed in the dropdown always seems to be in English.
  • Loading branch information
retailcoder committed May 29, 2015
1 parent c7cd4bf commit 6f66c79
Show file tree
Hide file tree
Showing 15 changed files with 198 additions and 53 deletions.
5 changes: 2 additions & 3 deletions RetailCoder.VBE/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ public class App : IDisposable

public App(VBE vbe, AddIn addIn)
{
//note: uncomment to debug localization issues
//RubberduckUI.Culture = CultureInfo.GetCultureInfo("fr-CA");

_configService = new ConfigurationLoader();
_inspections = _configService.GetImplementedCodeInspections();

var config = _configService.LoadConfiguration();
RubberduckUI.Culture = CultureInfo.GetCultureInfo(config.UserSettings.LanguageSetting.Code);

EnableCodeInspections(config);
var parser = new RubberduckParser();
var editor = new ActiveCodePaneEditor(vbe);
Expand Down
86 changes: 46 additions & 40 deletions RetailCoder.VBE/Config/ConfigurationLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,69 +18,74 @@ public interface IGeneralConfigService : IConfigurationService<Configuration>
}

public class ConfigurationLoader : XmlConfigurationServiceBase<Configuration>, IGeneralConfigService
{

{
protected override string ConfigFile
{
get { return Path.Combine(this.rootPath, "rubberduck.config"); }
}
{
get { return Path.Combine(rootPath, "rubberduck.config"); }
}

/// <summary> Loads the configuration from Rubberduck.config xml file. </summary>
/// <remarks> If an IOException occurs, returns a default configuration.</remarks>
/// <summary>
/// Loads the configuration from Rubberduck.config xml file.
/// </summary>
/// <remarks>
/// Returns default configuration when an IOException is caught.
/// </remarks>
public override Configuration LoadConfiguration()
{
//deserialization can silently fail for just parts of the config,
// so we null check and return defaults if necessary.
//deserialization can silently fail for just parts of the config,
//so we null-check and return defaults if necessary.

var config = base.LoadConfiguration();

if (config.UserSettings.ToDoListSettings == null)
{
config.UserSettings.ToDoListSettings = new ToDoListSettings(GetDefaultTodoMarkers());
}
if (config.UserSettings.LanguageSetting == null)
{
config.UserSettings.LanguageSetting = new DisplayLanguageSetting("en-US");
}

if (config.UserSettings.CodeInspectionSettings == null)
{
config.UserSettings.CodeInspectionSettings = new CodeInspectionSettings(GetDefaultCodeInspections());
}
if (config.UserSettings.ToDoListSettings == null)
{
config.UserSettings.ToDoListSettings = new ToDoListSettings(GetDefaultTodoMarkers());
}

if (config.UserSettings.CodeInspectionSettings == null)
{
config.UserSettings.CodeInspectionSettings = new CodeInspectionSettings(GetDefaultCodeInspections());
}

var implementedInspections = GetImplementedCodeInspections();
var configInspections = config.UserSettings.CodeInspectionSettings.CodeInspections.ToList();
configInspections = MergeImplementedInspectionsNotInConfig(configInspections, implementedInspections);
config.UserSettings.CodeInspectionSettings.CodeInspections = configInspections.ToArray();
var implementedInspections = GetImplementedCodeInspections();
var configInspections = config.UserSettings.CodeInspectionSettings.CodeInspections.ToList();

configInspections = MergeImplementedInspectionsNotInConfig(configInspections, implementedInspections);
config.UserSettings.CodeInspectionSettings.CodeInspections = configInspections.ToArray();

return config;
}
return config;
}

protected override Configuration HandleIOException(IOException ex)
{
return GetDefaultConfiguration();
}
{
return GetDefaultConfiguration();
}

protected override Configuration HandleInvalidOperationException(InvalidOperationException ex)
{
var message = string.Format(RubberduckUI.PromptLoadDefaultConfig, ex.Message, ex.InnerException.Message, ConfigFile);

DialogResult result = MessageBox.Show(message, RubberduckUI.LoadConfigError, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
{
var message = string.Format(RubberduckUI.PromptLoadDefaultConfig, ex.Message, ex.InnerException.Message, ConfigFile);
var result = MessageBox.Show(message, RubberduckUI.LoadConfigError, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

if (result == DialogResult.Yes)
{
var config = GetDefaultConfiguration();
if (result == DialogResult.Yes)
{
var config = GetDefaultConfiguration();
SaveConfiguration(config);
return config;
}
return config;
}

throw ex;

}

private List<CodeInspectionSetting> MergeImplementedInspectionsNotInConfig(List<CodeInspectionSetting> configInspections, IList<IInspection> implementedInspections)
{
bool found;
foreach (var implementedInspection in implementedInspections)
{
found = false;
var found = false;
foreach (var configInspection in configInspections)
{
if (implementedInspection.Name == configInspection.Name)
Expand All @@ -101,6 +106,7 @@ private List<CodeInspectionSetting> MergeImplementedInspectionsNotInConfig(List<
public Configuration GetDefaultConfiguration()
{
var userSettings = new UserSettings(
new DisplayLanguageSetting("en-US"),
new ToDoListSettings(GetDefaultTodoMarkers()),
new CodeInspectionSettings(GetDefaultCodeInspections())
);
Expand All @@ -114,7 +120,7 @@ public ToDoMarker[] GetDefaultTodoMarkers()
var todo = new ToDoMarker(RubberduckUI.ToDoMarkerToDo, TodoPriority.Normal);
var bug = new ToDoMarker(RubberduckUI.ToDoMarkerBug, TodoPriority.High);

return new ToDoMarker[] { note, todo, bug };
return new[] { note, todo, bug };
}

/// <summary> Converts implemented code inspections into array of Config.CodeInspection objects. </summary>
Expand Down
40 changes: 40 additions & 0 deletions RetailCoder.VBE/Config/DisplayLanguageSetting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Globalization;
using System.Xml.Serialization;
using Rubberduck.UI;

namespace Rubberduck.Config
{
[XmlType(AnonymousType = true)]
public class DisplayLanguageSetting
{
[XmlAttribute]
public string Code { get; set; }

public DisplayLanguageSetting()
{
// serialization constructor
}

public DisplayLanguageSetting(string code)
{
Code = code;
_name = RubberduckUI.ResourceManager.GetString("Language_" + Code.Substring(0, 2).ToUpper());
}

private readonly string _name;

[XmlIgnore]
public string Name { get { return _name; } }

public override bool Equals(object obj)
{
var other = (DisplayLanguageSetting) obj;
return Code.Equals(other.Code);
}

public override int GetHashCode()
{
return Code.GetHashCode();
}
}
}
10 changes: 7 additions & 3 deletions RetailCoder.VBE/Config/UserSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Rubberduck.Config
[XmlType(AnonymousType = true)]
public class UserSettings
{
public DisplayLanguageSetting LanguageSetting { get; set; }
public ToDoListSettings ToDoListSettings { get; set; }
public CodeInspectionSettings CodeInspectionSettings { get; set; }

Expand All @@ -13,10 +14,13 @@ public UserSettings()
//default constructor required for serialization
}

public UserSettings(ToDoListSettings todoSettings, CodeInspectionSettings codeInspectionSettings)
public UserSettings(DisplayLanguageSetting languageSetting,
ToDoListSettings todoSettings,
CodeInspectionSettings codeInspectionSettings)
{
this.ToDoListSettings = todoSettings;
this.CodeInspectionSettings = codeInspectionSettings;
LanguageSetting = languageSetting;
ToDoListSettings = todoSettings;
CodeInspectionSettings = codeInspectionSettings;
}
}
}
11 changes: 6 additions & 5 deletions RetailCoder.VBE/Rubberduck.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@
<Reference Include="WindowsFormsIntegration" />
</ItemGroup>
<ItemGroup>
<Compile Include="Config\DisplayLanguageSetting.cs" />
<Compile Include="Config\SourceControlConfiguration.cs" />
<Compile Include="Config\XmlConfigurationServiceBase.cs" />
<Compile Include="Inspections\AssignedByValParameterInspection.cs" />
Expand Down Expand Up @@ -463,11 +464,11 @@
<Compile Include="Config\ToDoMarkers.cs" />
<Compile Include="UI\IDockableUserControl.cs" />
<Compile Include="UI\Menu.cs" />
<Compile Include="UI\Settings\CodeInspectionControl.cs">
<Compile Include="UI\Settings\CodeInspectionSettingsControl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="UI\Settings\CodeInspectionControl.Designer.cs">
<DependentUpon>CodeInspectionControl.cs</DependentUpon>
<Compile Include="UI\Settings\CodeInspectionSettingsControl.Designer.cs">
<DependentUpon>CodeInspectionSettingsControl.cs</DependentUpon>
</Compile>
<Compile Include="UI\Settings\ConfigurationTreeView.cs">
<SubType>UserControl</SubType>
Expand Down Expand Up @@ -613,8 +614,8 @@
<SubType>Designer</SubType>
<LastGenOutput>RubberduckUI.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="UI\Settings\CodeInspectionControl.resx">
<DependentUpon>CodeInspectionControl.cs</DependentUpon>
<EmbeddedResource Include="UI\Settings\CodeInspectionSettingsControl.resx">
<DependentUpon>CodeInspectionSettingsControl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\Settings\ConfigurationTreeView.resx">
<DependentUpon>ConfigurationTreeView.cs</DependentUpon>
Expand Down
27 changes: 27 additions & 0 deletions RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions RetailCoder.VBE/UI/RubberduckUI.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -646,4 +646,13 @@ Attention: les valeurs personnalisées seront perdues.</value>
<data name="_TypeNotDeclared_" xml:space="preserve">
<value>{0} '{1}' est implicitement Variant</value>
</data>
<data name="Settings_LanguageLabel" xml:space="preserve">
<value>Langue d'affichage:</value>
</data>
<data name="Language_EN" xml:space="preserve">
<value>Anglais</value>
</data>
<data name="Language_FR" xml:space="preserve">
<value>Français</value>
</data>
</root>
9 changes: 9 additions & 0 deletions RetailCoder.VBE/UI/RubberduckUI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -658,4 +658,13 @@ Warning: All customized settings will be lost.</value>
<data name="Outcome" xml:space="preserve">
<value>Outcome</value>
</data>
<data name="Settings_LanguageLabel" xml:space="preserve">
<value>Display language:</value>
</data>
<data name="Language_EN" xml:space="preserve">
<value>English</value>
</data>
<data name="Language_FR" xml:space="preserve">
<value>French</value>
</data>
</root>
24 changes: 24 additions & 0 deletions RetailCoder.VBE/UI/Settings/GeneralSettingsControl.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6f66c79

Please sign in to comment.