annotate FrmPreferences.cs @ 121:3ec818926241

Code cleanup - remove warnings * Remove unused event * Fix null check * Commit change that MD insisted on making to objects.xml
author IBBoard <dev@ibboard.co.uk>
date Sun, 25 Sep 2011 20:59:44 +0100
parents b4416ca69153
children
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();
96
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
29
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
30 Translation.TranslationChanged += Retranslate;
95
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 Translate();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33
96
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
34 private void Retranslate()
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
35 {
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
36 Translate();
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
37 }
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
38
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
39 public override void Dispose()
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
40 {
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
41 Translation.TranslationChanged -= Retranslate;
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
42 base.Dispose();
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
43 }
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
44
95
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 protected override void Translate()
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 base.Translate();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 frameLabel.Text = Translation.GetTranslation("languagesGroup", "languages");
96
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
49 TreeStore model = ((TreeStore)preferencesTree.Model);
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
50 TreeIter iter;
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
51 model.GetIterFirst(out iter);
b4416ca69153 Fixes #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents: 95
diff changeset
52 model.SetValue(iter, 0, Translation.GetTranslation("languagePrefSection", "Language"));
95
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
53 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
54
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
55 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
56 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
57 object obj = model.GetValue(iter, 0);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
58
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
59 if (obj is string)
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 (cell as CellRendererText).Text = (string)obj;
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 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
64
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
65 private void BuildPreferenceCategoryTree()
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
66 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
67 TreeViewColumn mainColumn = new TreeViewColumn();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
68 CellRendererText mainCell = new CellRendererText();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
69 mainColumn.PackStart(mainCell, true);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
70 preferencesTree.AppendColumn(mainColumn);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
71 mainColumn.SetCellDataFunc(mainCell, new TreeCellDataFunc(RenderPreference));
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
72 TreeStore model = new TreeStore(typeof(string));
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
73 preferencesTree.Model = model;
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 model.AppendValues(Translation.GetTranslation("languagePrefSection", "Language"));
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
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 private void BuildLanguageList()
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 ICollection<TranslationLanguage> langs = Translation.GetLanguages();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80 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
81 sortedLangs.Sort(CompareLanguages);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 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
83 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
84 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86 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
87 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88 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
89 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
90 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92 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
93 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 prefs["language"] = Translation.GetTranslationLanguage();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 prefs.Save();
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96 Respond(ResponseType.Ok);
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 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
100 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 Translation.LoadTranslation(initialLang);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102 Respond(ResponseType.Cancel);
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
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
105 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
106 {
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
107 TranslationLanguage selectedLang = ComboBoxUtils.GetSelectedItem<TranslationLanguage>(languageList);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
108 string code = selectedLang == null ? "" : selectedLang.Code;
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
109 logger.Debug("New language: " + code);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
110 Translation.LoadTranslation(code);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
111 bttnOkay.Sensitive = !initialLang.Equals(code);
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
112
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
113 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
114
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
115
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
116
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
117
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
118 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
119 }
ea4069bbe6e9 Re #309: Add initial preference dialog with language support
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
120