diff FrmPreferences.cs @ 140:60c795eca8de WarFoundry_v0.1beta8_Winforms

Re #265: Add language preference UI * Add initial preferences dialog with translation options * Re-translate main form when language changes * Save translation for later use Only known bug on initial quick implementation is that open unit dialogs become named "{0}" (which should be replaced by unit name), but this should be quite a simple fix
author IBBoard <dev@ibboard.co.uk>
date Sun, 11 Apr 2010 19:55:03 +0000
parents
children 4023a9bdcb8b
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FrmPreferences.cs	Sun Apr 11 19:55:03 2010 +0000
@@ -0,0 +1,71 @@
+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;
+
+		public FrmPreferences(Preferences preferences)
+		{
+			prefs = preferences;
+			InitializeComponent();
+			TranslateForm();
+			SetValues();
+		}
+
+		private void TranslateForm()
+		{
+			ControlTranslator.TranslateComponent(this);
+			languagesGroup.Text = Translation.GetTranslation("languagesGroup", "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.SelectedIndexChanged += new EventHandler(languageList_SelectedIndexChanged);
+		}
+
+		private void languageList_SelectedIndexChanged(object sender, EventArgs e)
+		{
+			bttnOkay.Enabled = !(languageList.SelectedItem.Equals(Translation.GetTranslationLanguage()));
+		}
+
+		private void bttnCancel_Click(object sender, EventArgs e)
+		{
+			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.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);
+		}
+	}
+}
\ No newline at end of file