Mercurial > repos > IBDev-IBBoard.WarFoundry.GUI.GTK
comparison FrmAddEquipment.cs @ 92:58779fcd0166
Re #308: Make GTK# UI translatable
* Switch lots of labels to translatable versions
* Swap some default text to lower-case to make it easier to spot missing translations
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 31 Dec 2010 12:01:18 +0000 |
parents | 7055b24cfc79 |
children | b4416ca69153 |
comparison
equal
deleted
inserted
replaced
91:986fc923c0fa | 92:58779fcd0166 |
---|---|
8 using IBBoard.GtkSharp.Translatable; | 8 using IBBoard.GtkSharp.Translatable; |
9 using IBBoard.WarFoundry.API.Objects; | 9 using IBBoard.WarFoundry.API.Objects; |
10 using IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces; | 10 using IBBoard.WarFoundry.GUI.GTK.UIControl.Interfaces; |
11 using IBBoard.WarFoundry.GUI.GTK.Util; | 11 using IBBoard.WarFoundry.GUI.GTK.Util; |
12 using log4net; | 12 using log4net; |
13 using IBBoard.Lang; | |
13 | 14 |
14 namespace IBBoard.WarFoundry.GUI.GTK | 15 namespace IBBoard.WarFoundry.GUI.GTK |
15 { | 16 { |
16 public partial class FrmAddEquipment : TranslatableDialog, IAddEquipmentUI | 17 public partial class FrmAddEquipment : TranslatableDialog, IAddEquipmentUI |
17 { | 18 { |
18 private static ILog log = LogManager.GetLogger(typeof(FrmAddEquipment)); | 19 private static ILog log = LogManager.GetLogger(typeof(FrmAddEquipment)); |
20 | |
19 public event SingleArgMethodInvoker<UnitEquipmentItem> UnitEquipmentItemChoiceChanged; | 21 public event SingleArgMethodInvoker<UnitEquipmentItem> UnitEquipmentItemChoiceChanged; |
20 public event MethodInvoker UnitEquipmentAmountTypeChanged; | 22 public event MethodInvoker UnitEquipmentAmountTypeChanged; |
21 public event MethodInvoker UnitEquipmentAmountChanged; | 23 public event MethodInvoker UnitEquipmentAmountChanged; |
22 | 24 |
23 private bool isRatioLimited; | 25 private bool isRatioLimited; |
24 | 26 |
25 public FrmAddEquipment() | 27 public FrmAddEquipment() |
26 { | 28 { |
27 this.Build(); | 29 this.Build(); |
28 lstEquipment.Selection.Changed += OnSelectionChanged; | 30 lstEquipment.Selection.Changed += OnSelectionChanged; |
29 TreeViewColumn equipColumn = new TreeViewColumn(); | 31 TreeViewColumn equipColumn = new TreeViewColumn(); |
30 equipColumn.Title = "Equipment"; | |
31 CellRendererText equipCell = new CellRendererText(); | 32 CellRendererText equipCell = new CellRendererText(); |
32 equipColumn.PackStart(equipCell, true); | 33 equipColumn.PackStart(equipCell, true); |
33 equipColumn.SetCellDataFunc(equipCell, GtkWarFoundryUtil.RenderWarFoundryObjectName); | 34 equipColumn.SetCellDataFunc(equipCell, GtkWarFoundryUtil.RenderWarFoundryObjectName); |
34 lstEquipment.AppendColumn(equipColumn); | 35 lstEquipment.AppendColumn(equipColumn); |
35 } | 36 Translate(); |
36 | 37 } |
38 | |
39 protected override void Translate() | |
40 { | |
41 base.Translate(); | |
42 lstEquipment.Columns[0].Title = Translation.GetTranslation("frmAddEquipmentColumnTitle", "equipment"); | |
43 } | |
44 | |
37 private void OnUnitEquipmentAmountChanged() | 45 private void OnUnitEquipmentAmountChanged() |
38 { | 46 { |
39 if (UnitEquipmentAmountChanged != null) | 47 if (UnitEquipmentAmountChanged != null) |
40 { | 48 { |
41 UnitEquipmentAmountChanged(); | 49 UnitEquipmentAmountChanged(); |
42 } | 50 } |
43 } | 51 } |
44 | 52 |
45 private void OnUnitEquipmentAmountTypeChanged() | 53 private void OnUnitEquipmentAmountTypeChanged() |
46 { | 54 { |
47 if (UnitEquipmentAmountChanged != null) | 55 if (UnitEquipmentAmountChanged != null) |
48 { | 56 { |
49 UnitEquipmentAmountTypeChanged(); | 57 UnitEquipmentAmountTypeChanged(); |
50 } | 58 } |
51 } | 59 } |
52 | 60 |
53 protected void OnSelectionChanged(object o, EventArgs e) | 61 protected void OnSelectionChanged(object o, EventArgs e) |
54 { | 62 { |
55 if (UnitEquipmentItemChoiceChanged != null) | 63 if (UnitEquipmentItemChoiceChanged != null) |
56 { | 64 { |
57 UnitEquipmentItemChoiceChanged(SelectedUnitEquipmentItem); | 65 UnitEquipmentItemChoiceChanged(SelectedUnitEquipmentItem); |
106 int result = Run(); | 114 int result = Run(); |
107 bool okayClicked = (result == (int)ResponseType.Ok); | 115 bool okayClicked = (result == (int)ResponseType.Ok); |
108 this.Hide(); | 116 this.Hide(); |
109 return okayClicked; | 117 return okayClicked; |
110 } | 118 } |
111 | 119 |
112 protected virtual void CancelButtonClicked(object sender, System.EventArgs e) | 120 protected virtual void CancelButtonClicked(object sender, System.EventArgs e) |
113 { | 121 { |
114 log.Debug("Cancel clicked"); | 122 log.Debug("Cancel clicked"); |
115 Respond(ResponseType.Cancel); | 123 Respond(ResponseType.Cancel); |
116 } | 124 } |
117 | 125 |
118 protected virtual void OkayButtonClicked(object sender, System.EventArgs e) | 126 protected virtual void OkayButtonClicked(object sender, System.EventArgs e) |
119 { | 127 { |
120 log.Debug("Okay clicked"); | 128 log.Debug("Okay clicked"); |
121 Respond(ResponseType.Ok); | 129 Respond(ResponseType.Ok); |
122 } | 130 } |
123 | 131 |
124 public void SetOkayEnabledState(bool enabled) | 132 public void SetOkayEnabledState(bool enabled) |
125 { | 133 { |
126 buttonOk.Sensitive = enabled; | 134 buttonOk.Sensitive = enabled; |
127 } | 135 } |
128 | 136 |
129 protected virtual void SpinButtonValueChanged(object sender, System.EventArgs e) | 137 protected virtual void SpinButtonValueChanged(object sender, System.EventArgs e) |
130 { | 138 { |
131 OnUnitEquipmentAmountChanged(); | 139 OnUnitEquipmentAmountChanged(); |
132 } | 140 } |
133 | 141 |
134 protected virtual void RadioButtonClicked(object sender, System.EventArgs e) | 142 protected virtual void RadioButtonClicked(object sender, System.EventArgs e) |
135 { | 143 { |
136 OnUnitEquipmentAmountTypeChanged(); | 144 OnUnitEquipmentAmountTypeChanged(); |
137 } | 145 } |
138 | 146 |
139 public void SetNumericAmountEnabledState(bool enabled) | 147 public void SetNumericAmountEnabledState(bool enabled) |
140 { | 148 { |
141 double minPercent = GetMinPercentage(); | 149 double minPercent = GetMinPercentage(); |
142 rbEquipNumeric.Sensitive = enabled && !(isRatioLimited && minPercent == 100); | 150 rbEquipNumeric.Sensitive = enabled && !(isRatioLimited && minPercent == 100); |
143 numericAmount.Sensitive = rbEquipNumeric.Sensitive; | 151 numericAmount.Sensitive = rbEquipNumeric.Sensitive; |
144 } | 152 } |
145 | 153 |
146 public void SetPercentageAmountEnabledState(bool enabled) | 154 public void SetPercentageAmountEnabledState(bool enabled) |
147 { | 155 { |
148 if (enabled) | 156 if (enabled) |
149 { | 157 { |
150 double minPercentage = GetMinPercentage(); | 158 double minPercentage = GetMinPercentage(); |
174 { | 182 { |
175 double min, max; | 183 double min, max; |
176 percentageAmount.GetRange(out min, out max); | 184 percentageAmount.GetRange(out min, out max); |
177 return min; | 185 return min; |
178 } | 186 } |
179 | 187 |
180 public void ListenToWidgets() | 188 public void ListenToWidgets() |
181 { | 189 { |
182 rbEquipAll.Clicked += RadioButtonClicked; | 190 rbEquipAll.Clicked += RadioButtonClicked; |
183 rbEquipNumeric.Clicked += RadioButtonClicked; | 191 rbEquipNumeric.Clicked += RadioButtonClicked; |
184 rbEquipPercent.Clicked += RadioButtonClicked; | 192 rbEquipPercent.Clicked += RadioButtonClicked; |
185 numericAmount.ValueChanged += SpinButtonValueChanged; | 193 numericAmount.ValueChanged += SpinButtonValueChanged; |
186 percentageAmount.ValueChanged += SpinButtonValueChanged; | 194 percentageAmount.ValueChanged += SpinButtonValueChanged; |
187 lstEquipment.Selection.Changed += OnSelectionChanged; | 195 lstEquipment.Selection.Changed += OnSelectionChanged; |
188 } | 196 } |
189 | 197 |
190 public void IgnoreWidgets() | 198 public void IgnoreWidgets() |
191 { | 199 { |
192 rbEquipAll.Clicked -= RadioButtonClicked; | 200 rbEquipAll.Clicked -= RadioButtonClicked; |
193 rbEquipNumeric.Clicked -= RadioButtonClicked; | 201 rbEquipNumeric.Clicked -= RadioButtonClicked; |
194 rbEquipPercent.Clicked -= RadioButtonClicked; | 202 rbEquipPercent.Clicked -= RadioButtonClicked; |
195 numericAmount.ValueChanged -= SpinButtonValueChanged; | 203 numericAmount.ValueChanged -= SpinButtonValueChanged; |
196 percentageAmount.ValueChanged -= SpinButtonValueChanged; | 204 percentageAmount.ValueChanged -= SpinButtonValueChanged; |
197 lstEquipment.Selection.Changed -= OnSelectionChanged; | 205 lstEquipment.Selection.Changed -= OnSelectionChanged; |
198 } | 206 } |
199 | 207 |
200 public UnitEquipmentItem SelectedUnitEquipmentItem | 208 public UnitEquipmentItem SelectedUnitEquipmentItem |
201 { | 209 { |
202 get | 210 get |
203 { | 211 { |
204 return (UnitEquipmentItem)TreeUtils.GetSelectedItem(lstEquipment); | 212 return (UnitEquipmentItem)TreeUtils.GetSelectedItem(lstEquipment); |
205 } | 213 } |
206 } | 214 } |
207 | 215 |
208 public bool IsRatioEquipmentAmount | 216 public bool IsRatioEquipmentAmount |
209 { | 217 { |
210 get | 218 get |
211 { | 219 { |
212 return !rbEquipNumeric.Active; | 220 return !rbEquipNumeric.Active; |
213 } | 221 } |
214 } | 222 } |
215 | 223 |
216 public int EquipmentNumericAmount | 224 public int EquipmentNumericAmount |
217 { | 225 { |
218 get | 226 get |
219 { | 227 { |
220 return (int)numericAmount.Value; | 228 return (int)numericAmount.Value; |
223 set | 231 set |
224 { | 232 { |
225 numericAmount.Value = value; | 233 numericAmount.Value = value; |
226 } | 234 } |
227 } | 235 } |
228 | 236 |
229 public double EquipmentPercentageAmount | 237 public double EquipmentPercentageAmount |
230 { | 238 { |
231 get | 239 get |
232 { | 240 { |
233 double percent; | 241 double percent; |