annotate FrmPreferences.cs @ 253:7243e6646926 default tip

Re #427: Resizable equipment dialog * Make equipment dialog resizable
author IBBoard <dev@ibboard.co.uk>
date Sat, 27 Apr 2013 16:10:08 +0100
parents 4023a9bdcb8b
children
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;
144
4023a9bdcb8b Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
18 private string initialLang;
140
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 public FrmPreferences(Preferences preferences)
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 {
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 prefs = preferences;
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 InitializeComponent();
144
4023a9bdcb8b Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
24 preferenceSections.Nodes.Add("language");
140
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 TranslateForm();
144
4023a9bdcb8b Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
26 initialLang = Translation.GetTranslationLanguage();
140
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 SetValues();
144
4023a9bdcb8b Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
28 Translation.TranslationChanged += new MethodInvoker(TranslateForm);
140
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 }
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 private void TranslateForm()
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 ControlTranslator.TranslateComponent(this);
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 languagesGroup.Text = Translation.GetTranslation("languagesGroup", "language");
144
4023a9bdcb8b Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
35 //HACK: This will break as soon as we get multiple sections!
4023a9bdcb8b Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
36 preferenceSections.Nodes[0].Text = Translation.GetTranslation("languagePrefSection", "language");
140
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 }
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 private void SetValues()
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 {
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 ICollection<TranslationLanguage> langs = Translation.GetLanguages();
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 List<TranslationLanguage> sortedLangs = new List<TranslationLanguage>(langs);
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 sortedLangs.Sort(CompareLanguages);
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 languageList.DataSource = sortedLangs;
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 languageList.DisplayMember = "Name";
144
4023a9bdcb8b Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
46 languageList.SelectedItem = Translation.GetTranslationSet(initialLang).Language;
140
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 languageList.SelectedIndexChanged += new EventHandler(languageList_SelectedIndexChanged);
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 languageList_SelectedIndexChanged(object sender, EventArgs e)
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 {
144
4023a9bdcb8b Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
52 TranslationLanguage lang = GetSelectedLanguage();
4023a9bdcb8b Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
53 bttnOkay.Enabled = !(lang.Equals(Translation.GetTranslationLanguage()));
4023a9bdcb8b Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
54 Translation.LoadTranslation(lang.Code);
4023a9bdcb8b Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
55 }
4023a9bdcb8b Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
56
4023a9bdcb8b Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
57 private TranslationLanguage GetSelectedLanguage()
4023a9bdcb8b Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
58 {
4023a9bdcb8b Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
59 return (TranslationLanguage)languageList.SelectedItem;
140
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60 }
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 private void bttnCancel_Click(object sender, EventArgs e)
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 {
144
4023a9bdcb8b Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
64 Translation.LoadTranslation(initialLang);
140
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 Close();
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
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 private void bttnOkay_Click(object sender, EventArgs e)
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 {
144
4023a9bdcb8b Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents: 140
diff changeset
70 prefs["language"] = Translation.GetTranslationLanguage();
140
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 prefs.Save();
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 Close();
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 }
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 private int CompareLanguages(TranslationLanguage lang1, TranslationLanguage lang2)
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 {
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 CompareOptions options = CompareOptions.IgnoreCase | CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth;
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 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
79 }
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 }
60c795eca8de Re #265: Add language preference UI
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 }