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