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 diff
     1.1 --- a/FrmArmyTree.cs	Wed Apr 14 19:59:35 2010 +0000
     1.2 +++ b/FrmArmyTree.cs	Sun Apr 18 14:12:09 2010 +0000
     1.3 @@ -56,10 +56,7 @@
     1.4  
     1.5  		private void TranslateForm()
     1.6  		{
     1.7 -			foreach (Control ctrl in Controls)
     1.8 -			{
     1.9 -				ControlTranslator.TranslateControl(ctrl);
    1.10 -			}
    1.11 +			ControlTranslator.TranslateControl(this);
    1.12  
    1.13  			foreach (Component comp in components.Components)
    1.14  			{
     2.1 --- a/FrmMain.cs	Wed Apr 14 19:59:35 2010 +0000
     2.2 +++ b/FrmMain.cs	Sun Apr 18 14:12:09 2010 +0000
     2.3 @@ -153,11 +153,10 @@
     2.4  			armyTree.MdiParent = this;
     2.5  			armyTree.StartPosition = FormStartPosition.Manual;
     2.6  			armyTree.Location = new Point(this.DisplayRectangle.Width - armyTree.Width - 10, 10);
     2.7 -            ControlTranslator.TranslateControl(armyTree);
     2.8  
     2.9 -            // hack to load default files
    2.10 -            WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + DefaultDataDir));
    2.11 -            WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory());
    2.12 +			// hack to load default files
    2.13 +			WarFoundryLoader.GetDefault().AddLoadDirectory(new DirectoryInfo(Constants.ExecutablePath + Constants.DirectoryString + DefaultDataDir));
    2.14 +			WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory());
    2.15  			WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished;
    2.16  			WarFoundrySaver.SetFileSaver(new WarFoundryXmlSaver());
    2.17  		}
     3.1 --- a/FrmPreferences.cs	Wed Apr 14 19:59:35 2010 +0000
     3.2 +++ b/FrmPreferences.cs	Sun Apr 18 14:12:09 2010 +0000
     3.3 @@ -15,49 +15,59 @@
     3.4  	public partial class FrmPreferences : IBBForm
     3.5  	{
     3.6  		private Preferences prefs;
     3.7 +		private string initialLang;
     3.8  
     3.9  		public FrmPreferences(Preferences preferences)
    3.10  		{
    3.11  			prefs = preferences;
    3.12  			InitializeComponent();
    3.13 +			preferenceSections.Nodes.Add("language");
    3.14  			TranslateForm();
    3.15 +			initialLang = Translation.GetTranslationLanguage();
    3.16  			SetValues();
    3.17 +			Translation.TranslationChanged += new MethodInvoker(TranslateForm); 
    3.18  		}
    3.19  
    3.20  		private void TranslateForm()
    3.21  		{
    3.22  			ControlTranslator.TranslateComponent(this);
    3.23  			languagesGroup.Text = Translation.GetTranslation("languagesGroup", "language");
    3.24 +			//HACK: This will break as soon as we get multiple sections!
    3.25 +			preferenceSections.Nodes[0].Text = Translation.GetTranslation("languagePrefSection", "language");
    3.26  		}
    3.27  
    3.28  		private void SetValues()
    3.29  		{
    3.30 -			preferenceSections.Nodes.Add(Translation.GetTranslation("languagePrefSection", "language"));
    3.31  			ICollection<TranslationLanguage> langs = Translation.GetLanguages();
    3.32  			List<TranslationLanguage> sortedLangs = new List<TranslationLanguage>(langs);
    3.33  			sortedLangs.Sort(CompareLanguages);
    3.34  			languageList.DataSource = sortedLangs;
    3.35  			languageList.DisplayMember = "Name";
    3.36 -			languageList.SelectedItem = Translation.GetTranslationSet(Translation.GetTranslationLanguage()).Language;
    3.37 +			languageList.SelectedItem = Translation.GetTranslationSet(initialLang).Language;
    3.38  			languageList.SelectedIndexChanged += new EventHandler(languageList_SelectedIndexChanged);
    3.39  		}
    3.40  
    3.41  		private void languageList_SelectedIndexChanged(object sender, EventArgs e)
    3.42  		{
    3.43 -			bttnOkay.Enabled = !(languageList.SelectedItem.Equals(Translation.GetTranslationLanguage()));
    3.44 +			TranslationLanguage lang = GetSelectedLanguage();
    3.45 +			bttnOkay.Enabled = !(lang.Equals(Translation.GetTranslationLanguage()));
    3.46 +			Translation.LoadTranslation(lang.Code);
    3.47 +		}
    3.48 +
    3.49 +		private TranslationLanguage GetSelectedLanguage()
    3.50 +		{
    3.51 +			return (TranslationLanguage)languageList.SelectedItem;
    3.52  		}
    3.53  
    3.54  		private void bttnCancel_Click(object sender, EventArgs e)
    3.55  		{
    3.56 +			Translation.LoadTranslation(initialLang);
    3.57  			Close();
    3.58  		}
    3.59  
    3.60  		private void bttnOkay_Click(object sender, EventArgs e)
    3.61  		{
    3.62 -			TranslationLanguage lang = (TranslationLanguage)languageList.SelectedItem;
    3.63 -			string langCode = lang.Code;
    3.64 -			Translation.LoadTranslation(langCode);
    3.65 -			prefs["language"] = langCode;
    3.66 +			prefs["language"] = Translation.GetTranslationLanguage();
    3.67  			prefs.Save();
    3.68  			Close();
    3.69  		}