view FrmPreferences.cs @ 250:3aacaa74587f

Fixes #425: FileLoadFailure when starting WarFoundry * Change commit back so we only have the logging we need - issue appeared to be with Build system, change gave it a kick
author IBBoard <dev@ibboard.co.uk>
date Sun, 26 Aug 2012 11:26:50 +0100
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);
		}
	}
}