view FrmPreferences.cs @ 153:fcd90498d9a2

Re #269: Handle multiple stat lines * Improve rendering of stats * Fix column widths * Set width and height based on content Also: * Make FrmUnit title contain unit type as we're using it more now Still needs more testing and fixing
author IBBoard <dev@ibboard.co.uk>
date Wed, 26 May 2010 20:05:20 +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);
		}
	}
}