comparison 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
comparison
equal deleted inserted replaced
139:b3eec7735006 140:60c795eca8de
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Globalization;
7 using System.Text;
8 using System.Windows.Forms;
9 using IBBoard.Lang;
10 using IBBoard.Windows.Forms;
11 using IBBoard.Windows.Forms.I18N;
12
13 namespace IBBoard.WarFoundry.GUI.WinForms
14 {
15 public partial class FrmPreferences : IBBForm
16 {
17 private Preferences prefs;
18
19 public FrmPreferences(Preferences preferences)
20 {
21 prefs = preferences;
22 InitializeComponent();
23 TranslateForm();
24 SetValues();
25 }
26
27 private void TranslateForm()
28 {
29 ControlTranslator.TranslateComponent(this);
30 languagesGroup.Text = Translation.GetTranslation("languagesGroup", "language");
31 }
32
33 private void SetValues()
34 {
35 preferenceSections.Nodes.Add(Translation.GetTranslation("languagePrefSection", "language"));
36 ICollection<TranslationLanguage> langs = Translation.GetLanguages();
37 List<TranslationLanguage> sortedLangs = new List<TranslationLanguage>(langs);
38 sortedLangs.Sort(CompareLanguages);
39 languageList.DataSource = sortedLangs;
40 languageList.DisplayMember = "Name";
41 languageList.SelectedItem = Translation.GetTranslationSet(Translation.GetTranslationLanguage()).Language;
42 languageList.SelectedIndexChanged += new EventHandler(languageList_SelectedIndexChanged);
43 }
44
45 private void languageList_SelectedIndexChanged(object sender, EventArgs e)
46 {
47 bttnOkay.Enabled = !(languageList.SelectedItem.Equals(Translation.GetTranslationLanguage()));
48 }
49
50 private void bttnCancel_Click(object sender, EventArgs e)
51 {
52 Close();
53 }
54
55 private void bttnOkay_Click(object sender, EventArgs e)
56 {
57 TranslationLanguage lang = (TranslationLanguage)languageList.SelectedItem;
58 string langCode = lang.Code;
59 Translation.LoadTranslation(langCode);
60 prefs["language"] = langCode;
61 prefs.Save();
62 Close();
63 }
64
65 private int CompareLanguages(TranslationLanguage lang1, TranslationLanguage lang2)
66 {
67 CompareOptions options = CompareOptions.IgnoreCase | CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth;
68 return CultureInfo.CurrentCulture.CompareInfo.Compare(lang1.Name, lang2.Name, options);
69 }
70 }
71 }