Review code simplify suggestion, reorder private properties

This commit is contained in:
Korney Czukowski 2017-12-19 18:15:50 +01:00
parent 40b0c94905
commit a06b1d6e27

View File

@ -14,9 +14,9 @@ namespace DS4Windows.DS4Forms
public partial class LanguagePackComboBox : UserControl public partial class LanguagePackComboBox : UserControl
{ {
private string _invariantCultureText = "No (English UI)"; private string _invariantCultureText = "No (English UI)";
private string _probingPath = "";
private string _languageAssemblyName = "DS4Windows.resources.dll"; private string _languageAssemblyName = "DS4Windows.resources.dll";
private TaskCompletionSource<bool> _languageListInitialized = new TaskCompletionSource<bool>(); private TaskCompletionSource<bool> _languageListInitialized = new TaskCompletionSource<bool>();
private string _probingPath = "";
[Category("Action")] [Category("Action")]
[Description("Fires when the combo box selected index is changed.")] [Description("Fires when the combo box selected index is changed.")]
@ -51,16 +51,16 @@ namespace DS4Windows.DS4Forms
[Description("If probing path has been changed in App.config, add the same string here.")] [Description("If probing path has been changed in App.config, add the same string here.")]
public string ProbingPath public string ProbingPath
{ {
get { return this._probingPath; } get { return _probingPath; }
set { this._probingPath = value; } set { _probingPath = value; }
} }
[Category("Data")] [Category("Data")]
[Description("Filter language assembly file names in order to ont include irrelevant assemblies to the combo box.")] [Description("Filter language assembly file names in order to ont include irrelevant assemblies to the combo box.")]
public string LanguageAssemblyName public string LanguageAssemblyName
{ {
get { return this._languageAssemblyName; } get { return _languageAssemblyName; }
set { this._languageAssemblyName = value; } set { _languageAssemblyName = value; }
} }
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
@ -91,7 +91,7 @@ namespace DS4Windows.DS4Forms
Task.Run(() => { Task.Run(() => {
// Find available language assemblies and bind the list to the combo box. // Find available language assemblies and bind the list to the combo box.
cbCulture.DataSource = this.CreateLanguageAssembliesBindingSource(); cbCulture.DataSource = CreateLanguageAssembliesBindingSource();
cbCulture.SelectedValue = Thread.CurrentThread.CurrentUICulture.Name; cbCulture.SelectedValue = Thread.CurrentThread.CurrentUICulture.Name;
// This must be set here instead of Designer or event would fire at initial selected value setting above. // This must be set here instead of Designer or event would fire at initial selected value setting above.
@ -107,7 +107,7 @@ namespace DS4Windows.DS4Forms
{ {
// Find the location where application installed. // Find the location where application installed.
string exeLocation = Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path)); string exeLocation = Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path));
List<string> lookupPaths = this.ProbingPath.Split(';') List<string> lookupPaths = ProbingPath.Split(';')
.Select(path => Path.Combine(exeLocation, path)) .Select(path => Path.Combine(exeLocation, path))
.Where(path => path != exeLocation) .Where(path => path != exeLocation)
.ToList(); .ToList();
@ -115,17 +115,17 @@ namespace DS4Windows.DS4Forms
// Get all culture for which satellite folder found with culture code, then insert invariant culture at the beginning. // Get all culture for which satellite folder found with culture code, then insert invariant culture at the beginning.
List<KeyValuePair<string, string>> cultures = CultureInfo.GetCultures(CultureTypes.AllCultures) List<KeyValuePair<string, string>> cultures = CultureInfo.GetCultures(CultureTypes.AllCultures)
.Where(c => this.IsLanguageAssemblyAvailable(lookupPaths, c)) .Where(c => IsLanguageAssemblyAvailable(lookupPaths, c))
.Select(c => new KeyValuePair<string, string>(c.Name, c.NativeName)) .Select(c => new KeyValuePair<string, string>(c.Name, c.NativeName))
.ToList(); .ToList();
cultures.Insert(0, new KeyValuePair<string, string>("", this.InvariantCultureText)); cultures.Insert(0, new KeyValuePair<string, string>("", InvariantCultureText));
return new BindingSource(cultures, null); return new BindingSource(cultures, null);
} }
private bool IsLanguageAssemblyAvailable(List<string> lookupPaths, CultureInfo culture) private bool IsLanguageAssemblyAvailable(List<string> lookupPaths, CultureInfo culture)
{ {
return lookupPaths.Select(path => Path.Combine(path, culture.Name, this.LanguageAssemblyName)) return lookupPaths.Select(path => Path.Combine(path, culture.Name, LanguageAssemblyName))
.Where(path => File.Exists(path)) .Where(path => File.Exists(path))
.Count() > 0; .Count() > 0;
} }
@ -141,17 +141,17 @@ namespace DS4Windows.DS4Forms
private void LanguagePackComboBox_SizeChanged(object sender, EventArgs e) private void LanguagePackComboBox_SizeChanged(object sender, EventArgs e)
{ {
cbCulture.Left = label1.Margin.Left + label1.Width + label1.Margin.Right; cbCulture.Left = label1.Margin.Left + label1.Width + label1.Margin.Right;
cbCulture.Width = this.Width - cbCulture.Left - cbCulture.Margin.Right - cbCulture.Margin.Left; cbCulture.Width = Width - cbCulture.Left - cbCulture.Margin.Right - cbCulture.Margin.Left;
} }
private void CbCulture_SelectedIndexChanged(object sender, EventArgs e) private void CbCulture_SelectedIndexChanged(object sender, EventArgs e)
{ {
this.SelectedIndexChanged?.Invoke(this, e); SelectedIndexChanged?.Invoke(this, e);
} }
private void CbCulture_SelectedValueChanged(object sender, EventArgs e) private void CbCulture_SelectedValueChanged(object sender, EventArgs e)
{ {
this.SelectedValueChanged?.Invoke(this, e); SelectedValueChanged?.Invoke(this, e);
} }
} }
} }