Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.WinForms
view FrmPreferences.cs @ 190:1ca23c47345a
Re #327: Point names used in the GUI
author | snowblizz |
---|---|
date | Mon, 24 Jan 2011 16:50:31 +0000 |
parents | 4023a9bdcb8b |
children |
line wrap: on
line source
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Globalization; using System.Text; using System.Windows.Forms; using IBBoard.Lang; using IBBoard.Windows.Forms; using IBBoard.Windows.Forms.I18N; namespace IBBoard.WarFoundry.GUI.WinForms { public partial class FrmPreferences : IBBForm { private Preferences prefs; private string initialLang; public FrmPreferences(Preferences preferences) { prefs = preferences; InitializeComponent(); preferenceSections.Nodes.Add("language"); TranslateForm(); initialLang = Translation.GetTranslationLanguage(); SetValues(); Translation.TranslationChanged += new MethodInvoker(TranslateForm); } private void TranslateForm() { ControlTranslator.TranslateComponent(this); languagesGroup.Text = Translation.GetTranslation("languagesGroup", "language"); //HACK: This will break as soon as we get multiple sections! preferenceSections.Nodes[0].Text = Translation.GetTranslation("languagePrefSection", "language"); } private void SetValues() { ICollection<TranslationLanguage> langs = Translation.GetLanguages(); List<TranslationLanguage> sortedLangs = new List<TranslationLanguage>(langs); sortedLangs.Sort(CompareLanguages); languageList.DataSource = sortedLangs; languageList.DisplayMember = "Name"; languageList.SelectedItem = Translation.GetTranslationSet(initialLang).Language; languageList.SelectedIndexChanged += new EventHandler(languageList_SelectedIndexChanged); } private void languageList_SelectedIndexChanged(object sender, EventArgs e) { TranslationLanguage lang = GetSelectedLanguage(); bttnOkay.Enabled = !(lang.Equals(Translation.GetTranslationLanguage())); Translation.LoadTranslation(lang.Code); } private TranslationLanguage GetSelectedLanguage() { return (TranslationLanguage)languageList.SelectedItem; } private void bttnCancel_Click(object sender, EventArgs e) { Translation.LoadTranslation(initialLang); Close(); } private void bttnOkay_Click(object sender, EventArgs e) { prefs["language"] = Translation.GetTranslationLanguage(); prefs.Save(); Close(); } private int CompareLanguages(TranslationLanguage lang1, TranslationLanguage lang2) { CompareOptions options = CompareOptions.IgnoreCase | CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth; return CultureInfo.CurrentCulture.CompareInfo.Compare(lang1.Name, lang2.Name, options); } } }