comparison FrmPreferences.cs @ 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 60c795eca8de
children
comparison
equal deleted inserted replaced
143:28105d9c2b25 144:4023a9bdcb8b
13 namespace IBBoard.WarFoundry.GUI.WinForms 13 namespace IBBoard.WarFoundry.GUI.WinForms
14 { 14 {
15 public partial class FrmPreferences : IBBForm 15 public partial class FrmPreferences : IBBForm
16 { 16 {
17 private Preferences prefs; 17 private Preferences prefs;
18 private string initialLang;
18 19
19 public FrmPreferences(Preferences preferences) 20 public FrmPreferences(Preferences preferences)
20 { 21 {
21 prefs = preferences; 22 prefs = preferences;
22 InitializeComponent(); 23 InitializeComponent();
24 preferenceSections.Nodes.Add("language");
23 TranslateForm(); 25 TranslateForm();
26 initialLang = Translation.GetTranslationLanguage();
24 SetValues(); 27 SetValues();
28 Translation.TranslationChanged += new MethodInvoker(TranslateForm);
25 } 29 }
26 30
27 private void TranslateForm() 31 private void TranslateForm()
28 { 32 {
29 ControlTranslator.TranslateComponent(this); 33 ControlTranslator.TranslateComponent(this);
30 languagesGroup.Text = Translation.GetTranslation("languagesGroup", "language"); 34 languagesGroup.Text = Translation.GetTranslation("languagesGroup", "language");
35 //HACK: This will break as soon as we get multiple sections!
36 preferenceSections.Nodes[0].Text = Translation.GetTranslation("languagePrefSection", "language");
31 } 37 }
32 38
33 private void SetValues() 39 private void SetValues()
34 { 40 {
35 preferenceSections.Nodes.Add(Translation.GetTranslation("languagePrefSection", "language"));
36 ICollection<TranslationLanguage> langs = Translation.GetLanguages(); 41 ICollection<TranslationLanguage> langs = Translation.GetLanguages();
37 List<TranslationLanguage> sortedLangs = new List<TranslationLanguage>(langs); 42 List<TranslationLanguage> sortedLangs = new List<TranslationLanguage>(langs);
38 sortedLangs.Sort(CompareLanguages); 43 sortedLangs.Sort(CompareLanguages);
39 languageList.DataSource = sortedLangs; 44 languageList.DataSource = sortedLangs;
40 languageList.DisplayMember = "Name"; 45 languageList.DisplayMember = "Name";
41 languageList.SelectedItem = Translation.GetTranslationSet(Translation.GetTranslationLanguage()).Language; 46 languageList.SelectedItem = Translation.GetTranslationSet(initialLang).Language;
42 languageList.SelectedIndexChanged += new EventHandler(languageList_SelectedIndexChanged); 47 languageList.SelectedIndexChanged += new EventHandler(languageList_SelectedIndexChanged);
43 } 48 }
44 49
45 private void languageList_SelectedIndexChanged(object sender, EventArgs e) 50 private void languageList_SelectedIndexChanged(object sender, EventArgs e)
46 { 51 {
47 bttnOkay.Enabled = !(languageList.SelectedItem.Equals(Translation.GetTranslationLanguage())); 52 TranslationLanguage lang = GetSelectedLanguage();
53 bttnOkay.Enabled = !(lang.Equals(Translation.GetTranslationLanguage()));
54 Translation.LoadTranslation(lang.Code);
55 }
56
57 private TranslationLanguage GetSelectedLanguage()
58 {
59 return (TranslationLanguage)languageList.SelectedItem;
48 } 60 }
49 61
50 private void bttnCancel_Click(object sender, EventArgs e) 62 private void bttnCancel_Click(object sender, EventArgs e)
51 { 63 {
64 Translation.LoadTranslation(initialLang);
52 Close(); 65 Close();
53 } 66 }
54 67
55 private void bttnOkay_Click(object sender, EventArgs e) 68 private void bttnOkay_Click(object sender, EventArgs e)
56 { 69 {
57 TranslationLanguage lang = (TranslationLanguage)languageList.SelectedItem; 70 prefs["language"] = Translation.GetTranslationLanguage();
58 string langCode = lang.Code;
59 Translation.LoadTranslation(langCode);
60 prefs["language"] = langCode;
61 prefs.Save(); 71 prefs.Save();
62 Close(); 72 Close();
63 } 73 }
64 74
65 private int CompareLanguages(TranslationLanguage lang1, TranslationLanguage lang2) 75 private int CompareLanguages(TranslationLanguage lang1, TranslationLanguage lang2)