comparison 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
comparison
equal deleted inserted replaced
94:26e4525b49cf 95:ea4069bbe6e9
1 // This file (FrmPreferences.cs) is a part of the IBBoard.WarFoundry.GUI.GTK project and is copyright 2011 IBBoard
2 //
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.
4
5 using System;
6 using IBBoard.GtkSharp.Translatable;
7 using IBBoard.Lang;
8 using Gtk;
9 using System.Collections.Generic;
10 using IBBoard.GtkSharp;
11 using System.Globalization;
12 using log4net;
13
14 namespace IBBoard.WarFoundry.GUI.GTK
15 {
16 public partial class FrmPreferences : TranslatableDialog
17 {
18 private ILog logger = LogManager.GetLogger(typeof(FrmPreferences));
19 private Preferences prefs;
20 private string initialLang;
21
22 public FrmPreferences(Preferences preferences)
23 {
24 prefs = preferences;
25 initialLang = Translation.GetTranslationLanguage();
26 this.Build();
27 BuildPreferenceCategoryTree();
28 BuildLanguageList();
29 Translate();
30 }
31
32 protected override void Translate()
33 {
34 base.Translate();
35 frameLabel.Text = Translation.GetTranslation("languagesGroup", "languages");
36
37 }
38
39 private void RenderPreference(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
40 {
41 object obj = model.GetValue(iter, 0);
42
43 if (obj is string)
44 {
45 (cell as CellRendererText).Text = (string)obj;
46 }
47 }
48
49 private void BuildPreferenceCategoryTree()
50 {
51 TreeViewColumn mainColumn = new TreeViewColumn();
52 CellRendererText mainCell = new CellRendererText();
53 mainColumn.PackStart(mainCell, true);
54 preferencesTree.AppendColumn(mainColumn);
55 mainColumn.SetCellDataFunc(mainCell, new TreeCellDataFunc(RenderPreference));
56 TreeStore model = new TreeStore(typeof(string));
57 preferencesTree.Model = model;
58 model.AppendValues(Translation.GetTranslation("languagePrefSection", "Language"));
59 }
60
61 private void BuildLanguageList()
62 {
63 ICollection<TranslationLanguage> langs = Translation.GetLanguages();
64 List<TranslationLanguage> sortedLangs = new List<TranslationLanguage>(langs);
65 sortedLangs.Sort(CompareLanguages);
66 ComboBoxUtils.FillCombo(languageList, sortedLangs, delegate(TranslationLanguage lang){return lang.Name;});
67 ComboBoxUtils.SelectItem(languageList, Translation.GetTranslationSet(initialLang).Language);
68 }
69
70 private int CompareLanguages(TranslationLanguage lang1, TranslationLanguage lang2)
71 {
72 CompareOptions options = CompareOptions.IgnoreCase | CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth;
73 return CultureInfo.CurrentCulture.CompareInfo.Compare(lang1.Name, lang2.Name, options);
74 }
75
76 protected virtual void bttnOkayClicked(object sender, System.EventArgs e)
77 {
78 prefs["language"] = Translation.GetTranslationLanguage();
79 prefs.Save();
80 Respond(ResponseType.Ok);
81 }
82
83 protected virtual void bttnCancelClicked(object sender, System.EventArgs e)
84 {
85 Translation.LoadTranslation(initialLang);
86 Respond(ResponseType.Cancel);
87 }
88
89 protected virtual void languageListChanged(object sender, System.EventArgs e)
90 {
91 TranslationLanguage selectedLang = ComboBoxUtils.GetSelectedItem<TranslationLanguage>(languageList);
92 string code = selectedLang == null ? "" : selectedLang.Code;
93 logger.Debug("New language: " + code);
94 Translation.LoadTranslation(code);
95 bttnOkay.Sensitive = !initialLang.Equals(code);
96
97 }
98
99
100
101
102 }
103 }
104