diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FrmPreferences.cs	Sat Jan 01 20:55:07 2011 +0000
@@ -0,0 +1,104 @@
+//  This file (FrmPreferences.cs) is a part of the IBBoard.WarFoundry.GUI.GTK project and is copyright 2011 IBBoard
+// 
+//  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.
+
+using System;
+using IBBoard.GtkSharp.Translatable;
+using IBBoard.Lang;
+using Gtk;
+using System.Collections.Generic;
+using IBBoard.GtkSharp;
+using System.Globalization;
+using log4net;
+
+namespace IBBoard.WarFoundry.GUI.GTK
+{
+	public partial class FrmPreferences : TranslatableDialog
+	{
+		private ILog logger = LogManager.GetLogger(typeof(FrmPreferences));
+		private Preferences prefs;
+		private string initialLang;
+
+		public FrmPreferences(Preferences preferences)
+		{
+			prefs = preferences;
+			initialLang = Translation.GetTranslationLanguage();
+			this.Build();
+			BuildPreferenceCategoryTree();
+			BuildLanguageList();
+			Translate();
+		}
+
+		protected override void Translate()
+		{
+			base.Translate();
+			frameLabel.Text = Translation.GetTranslation("languagesGroup", "languages");
+
+		}
+
+		private void RenderPreference(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter)
+		{
+			object obj = model.GetValue(iter, 0);
+
+			if (obj is string)
+			{
+				(cell as CellRendererText).Text = (string)obj;
+			}
+		}
+
+		private void BuildPreferenceCategoryTree()
+		{
+			TreeViewColumn mainColumn = new TreeViewColumn();
+			CellRendererText mainCell = new CellRendererText();
+			mainColumn.PackStart(mainCell, true);
+			preferencesTree.AppendColumn(mainColumn);
+			mainColumn.SetCellDataFunc(mainCell, new TreeCellDataFunc(RenderPreference));
+			TreeStore model = new TreeStore(typeof(string));
+			preferencesTree.Model = model;
+			model.AppendValues(Translation.GetTranslation("languagePrefSection", "Language"));
+		}
+
+		private void BuildLanguageList()
+		{
+			ICollection<TranslationLanguage> langs = Translation.GetLanguages();
+			List<TranslationLanguage> sortedLangs = new List<TranslationLanguage>(langs);
+			sortedLangs.Sort(CompareLanguages);
+			ComboBoxUtils.FillCombo(languageList, sortedLangs, delegate(TranslationLanguage lang){return lang.Name;});
+			ComboBoxUtils.SelectItem(languageList, Translation.GetTranslationSet(initialLang).Language);
+		}
+
+		private int CompareLanguages(TranslationLanguage lang1, TranslationLanguage lang2)
+		{
+			CompareOptions options = CompareOptions.IgnoreCase | CompareOptions.IgnoreKanaType | CompareOptions.IgnoreWidth;
+			return CultureInfo.CurrentCulture.CompareInfo.Compare(lang1.Name, lang2.Name, options);
+		}
+
+		protected virtual void bttnOkayClicked(object sender, System.EventArgs e)
+		{
+			prefs["language"] = Translation.GetTranslationLanguage();
+			prefs.Save();
+			Respond(ResponseType.Ok);
+		}
+
+		protected virtual void bttnCancelClicked(object sender, System.EventArgs e)
+		{
+			Translation.LoadTranslation(initialLang);
+			Respond(ResponseType.Cancel);
+		}
+
+		protected virtual void languageListChanged(object sender, System.EventArgs e)
+		{
+			TranslationLanguage selectedLang = ComboBoxUtils.GetSelectedItem<TranslationLanguage>(languageList);
+			string code = selectedLang == null ? "" : selectedLang.Code;
+			logger.Debug("New language: " + code);
+			Translation.LoadTranslation(code);
+			bttnOkay.Sensitive = !initialLang.Equals(code);
+
+		}
+
+
+
+
+	}
+}
+