Mercurial > repos > IBBoard.WarFoundry.GUI.WinForms
changeset 144:4023a9bdcb8b
Re #265: Add language preference UI
* Fix army tree translating
* Make translations change on list change, not just on "okay"
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 18 Apr 2010 14:12:09 +0000 |
parents | 28105d9c2b25 |
children | 51463bc1fb21 |
files | FrmArmyTree.cs FrmMain.cs FrmPreferences.cs |
diffstat | 3 files changed, 21 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/FrmArmyTree.cs Wed Apr 14 19:59:35 2010 +0000 +++ b/FrmArmyTree.cs Sun Apr 18 14:12:09 2010 +0000 @@ -56,10 +56,7 @@ private void TranslateForm() { - foreach (Control ctrl in Controls) - { - ControlTranslator.TranslateControl(ctrl); - } + ControlTranslator.TranslateControl(this); foreach (Component comp in components.Components) {
--- a/FrmMain.cs Wed Apr 14 19:59:35 2010 +0000 +++ b/FrmMain.cs Sun Apr 18 14:12:09 2010 +0000 @@ -153,11 +153,10 @@ armyTree.MdiParent = this; armyTree.StartPosition = FormStartPosition.Manual; armyTree.Location = new Point(this.DisplayRectangle.Width - armyTree.Width - 10, 10); - ControlTranslator.TranslateControl(armyTree); - // hack to load default files - WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + DefaultDataDir)); - WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory()); + // hack to load default files + WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + DefaultDataDir)); + WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory()); WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished; WarFoundrySaver.SetFileSaver(new WarFoundryXmlSaver()); }
--- a/FrmPreferences.cs Wed Apr 14 19:59:35 2010 +0000 +++ b/FrmPreferences.cs Sun Apr 18 14:12:09 2010 +0000 @@ -15,49 +15,59 @@ 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() { - preferenceSections.Nodes.Add(Translation.GetTranslation("languagePrefSection", "language")); 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(Translation.GetTranslationLanguage()).Language; + languageList.SelectedItem = Translation.GetTranslationSet(initialLang).Language; languageList.SelectedIndexChanged += new EventHandler(languageList_SelectedIndexChanged); } private void languageList_SelectedIndexChanged(object sender, EventArgs e) { - bttnOkay.Enabled = !(languageList.SelectedItem.Equals(Translation.GetTranslationLanguage())); + 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) { - TranslationLanguage lang = (TranslationLanguage)languageList.SelectedItem; - string langCode = lang.Code; - Translation.LoadTranslation(langCode); - prefs["language"] = langCode; + prefs["language"] = Translation.GetTranslationLanguage(); prefs.Save(); Close(); }