tbf/TestBenchFramework/PreferencesDlg.cs

125 lines
3.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

///
/// Copyright (c) 2013-2015 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using TBF.Resources;
namespace TBF
{
/// <summary>
/// Dialog to edit local settings that specify UI preferences, language, etc. (S1.1)
/// </summary>
public partial class PreferencesDlg : Form
{
string[] LanguageName = new string[]
{
"English",
"中国 (Chinese simplified)",
"Česky Czech)",
"Deutch (German)",
"Español (Spanish)",
"Français (French)",
"Italiano (Italian)",
"Polski (Polish)",
"Русский (Russion)",
};
/// <summary>
/// Available languages.
/// Method ToString should give a supported culture info string:
/// ("en","de","fr","es","it","cn", etc.).
/// </summary>
string[] LanguageCode = new string[]
{
"en",
"zh-CN",
"cs",
"de",
"es",
"fr",
"it",
"pl",
"ru",
};
// Local copy of 'local settings' initialized to Program.localSettings.
// Dialog modifies this copy and updates Program.localSettings just
// when 'OK' is pressed.
LocalSettings localSettings;
public PreferencesDlg()
{
Program.LocalSettings.Save();
localSettings = LocalSettings.Load(Program.LocalSettingsFileName);
if (localSettings == null) throw new Exception("Cannot load local settings");
InitializeComponent();
// Initialize the list box with langauges
for (int i = 0; i < LanguageName.Length; i++)
{
languageListBox.Items.Add(LanguageName[i]);
if (localSettings.Language == LanguageCode[i])
{
languageListBox.Text = LanguageName[i];
}
}
}
private void languageListBox_SelectedIndexChanged(object sender, EventArgs e)
{
localSettings.Language = LanguageCode[languageListBox.SelectedIndex];
}
/// <summary>
/// Update setting, return DialogResult.OK
/// </summary>
/// <param name="sender">Not used</param>
/// <param name="e">Not used</param>
private void okButton_Click(object sender, EventArgs e)
{
try
{
string culture = localSettings.Language.Replace('_', '-');
CultureInfo ci = new CultureInfo(culture);
System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
localSettings.Save();
Program.LocalSettings = LocalSettings.Load(Program.LocalSettingsFileName);
DialogResult response = MessageBox.Show(Strings.Restart_To_Apply_Changes);
DialogResult = DialogResult.OK;
Close();
}
catch
{
MessageBox.Show("Selected language not supported.\nUsing English.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
localSettings.Language = "en";
System.Threading.Thread.CurrentThread.CurrentUICulture =
new System.Globalization.CultureInfo(localSettings.Language);
}
return;
}
/// <summary>
/// Throw away changes, return DialogResult.Cancel
/// </summary>
/// <param name="sender">Not used</param>
/// <param name="e">Not used</param>
private void cancelButton_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
return;
}
}
}