view FrmPreferences.cs @ 167:9808adf2d566

Re #419: Remove assumptions of a file-based install * Update GTK# GUI to use Streams version of XSLT export
author IBBoard <dev@ibboard.co.uk>
date Wed, 28 Nov 2012 20:25:53 +0000
parents ea4069bbe6e9
children
line source
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.
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;
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;
22 public FrmPreferences(Preferences preferences)
23 {
24 prefs = preferences;
25 initialLang = Translation.GetTranslationLanguage();
26 this.Build();
27 BuildPreferenceCategoryTree();
28 BuildLanguageList();
30 Translation.TranslationChanged += Retranslate;
31 Translate();
32 }
34 private void Retranslate()
35 {
36 Translate();
37 }
39 public override void Dispose()
40 {
41 Translation.TranslationChanged -= Retranslate;
42 base.Dispose();
43 }
45 protected override void Translate()
46 {
47 base.Translate();
48 frameLabel.Text = Translation.GetTranslation("languagesGroup", "languages");
49 TreeStore model = ((TreeStore)preferencesTree.Model);
50 TreeIter iter;
51 model.GetIterFirst(out iter);
52 model.SetValue(iter, 0, Translation.GetTranslation("languagePrefSection", "Language"));
53 }
55 private void RenderPreference(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
56 {
57 object obj = model.GetValue(iter, 0);
59 if (obj is string)
60 {
61 (cell as CellRendererText).Text = (string)obj;
62 }
63 }
65 private void BuildPreferenceCategoryTree()
66 {
67 TreeViewColumn mainColumn = new TreeViewColumn();
68 CellRendererText mainCell = new CellRendererText();
69 mainColumn.PackStart(mainCell, true);
70 preferencesTree.AppendColumn(mainColumn);
71 mainColumn.SetCellDataFunc(mainCell, new TreeCellDataFunc(RenderPreference));
72 TreeStore model = new TreeStore(typeof(string));
73 preferencesTree.Model = model;
74 model.AppendValues(Translation.GetTranslation("languagePrefSection", "Language"));
75 }
77 private void BuildLanguageList()
78 {
79 ICollection<TranslationLanguage> langs = Translation.GetLanguages();
80 List<TranslationLanguage> sortedLangs = new List<TranslationLanguage>(langs);
81 sortedLangs.Sort(CompareLanguages);
82 ComboBoxUtils.FillCombo(languageList, sortedLangs, delegate(TranslationLanguage lang){return lang.Name;});
83 ComboBoxUtils.SelectItem(languageList, Translation.GetTranslationSet(initialLang).Language);
84 }
86 private int CompareLanguages(TranslationLanguage lang1, TranslationLanguage lang2)
87 {
88 CompareOptions options = CompareOptions.IgnoreCase | CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth;
89 return CultureInfo.CurrentCulture.CompareInfo.Compare(lang1.Name, lang2.Name, options);
90 }
92 protected virtual void bttnOkayClicked(object sender, System.EventArgs e)
93 {
94 prefs["language"] = Translation.GetTranslationLanguage();
95 prefs.Save();
96 Respond(ResponseType.Ok);
97 }
99 protected virtual void bttnCancelClicked(object sender, System.EventArgs e)
100 {
101 Translation.LoadTranslation(initialLang);
102 Respond(ResponseType.Cancel);
103 }
105 protected virtual void languageListChanged(object sender, System.EventArgs e)
106 {
107 TranslationLanguage selectedLang = ComboBoxUtils.GetSelectedItem<TranslationLanguage>(languageList);
108 string code = selectedLang == null ? "" : selectedLang.Code;
109 logger.Debug("New language: " + code);
110 Translation.LoadTranslation(code);
111 bttnOkay.Sensitive = !initialLang.Equals(code);
113 }
118 }
119 }