Mercurial > repos > IBBoard.WarFoundry.GUI.WinForms
view FrmPreferences.cs @ 167:7de7890bf079
Re #88: Complete initial WinForms UI
* Update to 0.1RC1
* Rebuild About dialog to look a bit nicer
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 24 Jul 2010 11:10:07 +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); } } }