2 * Copyright (C) 2006-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 using System.Collections;
25 using System.ComponentModel;
26 using System.Windows.Forms;
27 using TeamXBMC.TranslatorCore;
29 namespace TeamXBMC.Translator
32 /// Shows all available languages. The user can choose
33 /// the language to be translated.
35 public sealed class ChooseLanguageForm : System.Windows.Forms.Form
37 private System.Windows.Forms.ListBox listBox1;
38 private System.Windows.Forms.Button buttonOK;
39 private System.Windows.Forms.Button buttonCancel;
40 private System.Windows.Forms.Label label1;
42 /// Required designer variable.
44 private System.ComponentModel.Container components = null;
46 public ChooseLanguageForm()
49 // Required for Windows Form Designer support
51 InitializeComponent();
54 // TODO: Add any constructor code after InitializeComponent call
59 /// Clean up any resources being used.
61 protected override void Dispose( bool disposing )
65 if(components != null)
70 base.Dispose( disposing );
73 #region Windows Form Designer generated code
75 /// Required method for Designer support - do not modify
76 /// the contents of this method with the code editor.
78 private void InitializeComponent()
80 this.buttonOK = new System.Windows.Forms.Button();
81 this.buttonCancel = new System.Windows.Forms.Button();
82 this.listBox1 = new System.Windows.Forms.ListBox();
83 this.label1 = new System.Windows.Forms.Label();
88 this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
89 this.buttonOK.FlatStyle = System.Windows.Forms.FlatStyle.System;
90 this.buttonOK.Location = new System.Drawing.Point(80, 200);
91 this.buttonOK.Name = "buttonOK";
92 this.buttonOK.TabIndex = 3;
93 this.buttonOK.Text = "OK";
94 this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
98 this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
99 this.buttonCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
100 this.buttonCancel.Location = new System.Drawing.Point(168, 200);
101 this.buttonCancel.Name = "buttonCancel";
102 this.buttonCancel.TabIndex = 4;
103 this.buttonCancel.Text = "Cancel";
107 this.listBox1.Location = new System.Drawing.Point(8, 32);
108 this.listBox1.Name = "listBox1";
109 this.listBox1.Size = new System.Drawing.Size(232, 160);
110 this.listBox1.Sorted = true;
111 this.listBox1.TabIndex = 2;
112 this.listBox1.DoubleClick += new System.EventHandler(this.listBox1_DoubleClick);
113 this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
117 this.label1.Location = new System.Drawing.Point(8, 8);
118 this.label1.Name = "label1";
119 this.label1.Size = new System.Drawing.Size(240, 23);
120 this.label1.TabIndex = 1;
121 this.label1.Text = "Select the language to be translated";
123 // ChooseLanguageForm
125 this.AcceptButton = this.buttonOK;
126 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
127 this.CancelButton = this.buttonCancel;
128 this.ClientSize = new System.Drawing.Size(250, 232);
129 this.Controls.Add(this.label1);
130 this.Controls.Add(this.listBox1);
131 this.Controls.Add(this.buttonCancel);
132 this.Controls.Add(this.buttonOK);
133 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
134 this.MaximizeBox = false;
135 this.MinimizeBox = false;
136 this.Name = "ChooseLanguageForm";
137 this.ShowInTaskbar = false;
138 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
139 this.Text = "Choose Language";
140 this.Load += new System.EventHandler(this.ChooseLanguageForm_Load);
141 this.ResumeLayout(false);
146 #region Form initialization
149 /// Fills the listbox with all available languages and selects the one currently edited
151 private void ChooseLanguageForm_Load(object sender, System.EventArgs e)
153 string root=Settings.Instance.LanguageFolder;
154 string[] languages=TranslationManager.Instance.Languages;
156 foreach (string language in languages)
158 listBox1.Items.Add(language);
160 if (Settings.Instance.Language==language)
162 listBox1.SelectedItem=language;
166 if (Settings.Instance.Language=="")
167 { // No language selected yet, disable ok button
168 buttonOK.Enabled=false;
175 #region Control Events
178 /// The double clicked language in the listbox is selected as the current one
179 /// and afterwards the dialog is closed
181 private void listBox1_DoubleClick(object sender, System.EventArgs e)
183 Settings.Instance.Language=(string)listBox1.SelectedItem;
185 DialogResult=DialogResult.OK;
190 /// Sets the language selected in the listbox as the current one.
192 private void buttonOK_Click(object sender, System.EventArgs e)
194 Settings.Instance.Language=(string)listBox1.SelectedItem;
197 private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
199 buttonOK.Enabled=true;