annotate FrmPreferences.cs @ 95:ea4069bbe6e9

Re #309: Add initial preference dialog with language support * Add first preference dialog * Add French translations (based on WinForms file) Re #308: Make GTK# UI translatable * Add some missing English translations (API strings)
author IBBoard <dev@ibboard.co.uk>
date Sat, 01 Jan 2011 20:55:07 +0000
parents
children b4416ca69153
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
95
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (FrmPreferences.cs) is a part of the IBBoard.WarFoundry.GUI.GTK project and is copyright 2011 IBBoard
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using IBBoard.GtkSharp.Translatable;
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using IBBoard.Lang;
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using Gtk;
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 using System.Collections.Generic;
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 using IBBoard.GtkSharp;
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 using System.Globalization;
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 using log4net;
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 namespace IBBoard.WarFoundry.GUI.GTK
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 public partial class FrmPreferences : TranslatableDialog
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 private ILog logger = LogManager.GetLogger(typeof(FrmPreferences));
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 private Preferences prefs;
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 private string initialLang;
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 public FrmPreferences(Preferences preferences)
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 prefs = preferences;
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 initialLang = Translation.GetTranslationLanguage();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 this.Build();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 BuildPreferenceCategoryTree();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 BuildLanguageList();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 Translate();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 protected override void Translate()
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 base.Translate();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 frameLabel.Text = Translation.GetTranslation("languagesGroup", "languages");
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 private void RenderPreference(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 object obj = model.GetValue(iter, 0);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 if (obj is string)
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 (cell as CellRendererText).Text = (string)obj;
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 private void BuildPreferenceCategoryTree()
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 TreeViewColumn mainColumn = new TreeViewColumn();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
52 CellRendererText mainCell = new CellRendererText();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 mainColumn.PackStart(mainCell, true);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54 preferencesTree.AppendColumn(mainColumn);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 mainColumn.SetCellDataFunc(mainCell, new TreeCellDataFunc(RenderPreference));
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
56 TreeStore model = new TreeStore(typeof(string));
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 preferencesTree.Model = model;
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58 model.AppendValues(Translation.GetTranslation("languagePrefSection", "Language"));
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
60
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
61 private void BuildLanguageList()
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
62 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
63 ICollection<TranslationLanguage> langs = Translation.GetLanguages();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64 List<TranslationLanguage> sortedLangs = new List<TranslationLanguage>(langs);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 sortedLangs.Sort(CompareLanguages);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 ComboBoxUtils.FillCombo(languageList, sortedLangs, delegate(TranslationLanguage lang){return lang.Name;});
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 ComboBoxUtils.SelectItem(languageList, Translation.GetTranslationSet(initialLang).Language);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 private int CompareLanguages(TranslationLanguage lang1, TranslationLanguage lang2)
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 CompareOptions options = CompareOptions.IgnoreCase | CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth;
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 return CultureInfo.CurrentCulture.CompareInfo.Compare(lang1.Name, lang2.Name, options);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76 protected virtual void bttnOkayClicked(object sender, System.EventArgs e)
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 prefs["language"] = Translation.GetTranslationLanguage();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 prefs.Save();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 Respond(ResponseType.Ok);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 protected virtual void bttnCancelClicked(object sender, System.EventArgs e)
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85 Translation.LoadTranslation(initialLang);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86 Respond(ResponseType.Cancel);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89 protected virtual void languageListChanged(object sender, System.EventArgs e)
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 TranslationLanguage selectedLang = ComboBoxUtils.GetSelectedItem<TranslationLanguage>(languageList);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92 string code = selectedLang == null ? "" : selectedLang.Code;
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93 logger.Debug("New language: " + code);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 Translation.LoadTranslation(code);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 bttnOkay.Sensitive = !initialLang.Equals(code);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
104