view FrmPreferences.cs @ 204:9d17b4674f6e default-army-name

Re #153: Default name for armies * Do a bit of string formatting to allow "{0} Empire Army" to become "2000pt Empire Army"
author IBBoard <dev@ibboard.co.uk>
date Wed, 08 Sep 2010 20:10:57 +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);
		}
	}
}