diff 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
line wrap: on
line diff
--- 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();
 		}