# HG changeset patch # User IBBoard # Date 1294002195 0 # Node ID fac0636ae13bec9ed13c7019f86338d59c1c1555 # Parent 6d2c8ad0d8f144d127408844be8a616cf5568bf7 Re #308: Make GTK# UI translatable * Make undo/redo menus translate on language change * Organise English language file * Resolve warnings by adding in dialogs that use translated strings when equipment amounts are out of range diff -r 6d2c8ad0d8f1 -r fac0636ae13b FrmMainWindow.cs --- a/FrmMainWindow.cs Sun Jan 02 15:50:29 2011 +0000 +++ b/FrmMainWindow.cs Sun Jan 02 21:03:15 2011 +0000 @@ -40,7 +40,6 @@ private Preferences preferences; private ILog logger = LogManager.GetLogger(typeof(FrmMainWindow)); private CommandStack commandStack; - private Dictionary categoryMap = new Dictionary(); private Dictionary unitToWidgetMap = new Dictionary(); private ObjectAddDelegate UnitAddedMethod; private ObjectRemoveDelegate UnitRemovedMethod; @@ -225,6 +224,7 @@ base.Translate(); SetAppTitle(); treeUnits.GetColumn(0).Title = Translation.GetTranslation("armyCategoryColumnTitle", "categories"); + RebuildUndoRedoMenus(); } private void Retranslate() @@ -414,11 +414,6 @@ set { preferences = value; } } - /*public AbstractNativeWarFoundryFactory Factory - { - get { return WarFoundryFactoryFactory.GetFactoryFactory().GetFactory(Constants.ExecutablePath, factoryType); } - }*/ - protected void OnDeleteEvent(object sender, DeleteEventArgs a) { Application.Quit(); @@ -464,8 +459,8 @@ { if (sender is ToolButton) { - Category cat = null; - categoryMap.TryGetValue((ToolButton)sender, out cat); + ToolButton toolButton = (ToolButton)sender; + Category cat = (Category)toolButton.Data["Category"]; if (cat != null) { @@ -634,8 +629,6 @@ { toolbar.Remove(toolbar.Children[i]); } - - categoryMap.Clear(); } private void AddCategoryButtons(Category[] cats) @@ -649,8 +642,7 @@ ToolButton button = new ToolButton("gtk-add"); button.Label = cat.Name; button.TooltipText = Translation.GetTranslation("bttnCreateFromCat", "{0}", cat.Name); - //TODO: See if we can associate data in some way, the same as we can with SWF. For now we just use the map. - categoryMap.Add(button, cat); + button.Data["Category"] = cat; button.Clicked += new System.EventHandler(OnAddUnitActivated); toolbar.Insert(button, -1); } @@ -672,26 +664,33 @@ miUndo.Sensitive = undoMenuButton.Sensitive; redoMenuButton.Sensitive = commandStack.CanRedo(); miRedo.Sensitive = redoMenuButton.Sensitive; + + RebuildUndoRedoMenus(); + + bttnSaveArmy.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy != null; + miSaveArmy.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy != null; + } + + private void RebuildUndoRedoMenus() + { int redoLength = commandStack.RedoLength; - int maxRedo = Math.Min(10, redoLength); - //TODO: Add tooltips if (redoLength > 0) { Menu menu = new Menu(); Command com; MenuItem mi; - + for (int i = 0; i < maxRedo; i++) { com = commandStack.PeekRedoCommand(i + 1); - + if (com == null) { break; } - + mi = new MenuItem(com.Description); mi.Activated += new EventHandler(RedoMenuActivated); menu.Append(mi); @@ -707,22 +706,22 @@ int undoLength = commandStack.UndoLength; int maxUndo = Math.Min(10, undoLength); - + if (undoLength > 0) { Menu menu = new Menu(); Command com; MenuItem mi; - + for (int i = 0; i < maxUndo; i++) { com = commandStack.PeekUndoCommand(i + 1); - + if (com == null) { break; } - + mi = new MenuItem(com.UndoDescription); mi.Activated += new EventHandler(UndoMenuActivated); menu.Add(mi); @@ -735,9 +734,6 @@ { undoMenuButton.Menu = null; } - - bttnSaveArmy.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy != null; - miSaveArmy.Sensitive = commandStack.IsDirty() && WarFoundryCore.CurrentArmy != null; } private void RedoMenuActivated(object sender, EventArgs e) @@ -793,10 +789,13 @@ private bool OpenArmy() { - FileChooserDialog fileDialog = new FileChooserDialog("Open army", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept); + string title = Translation.GetTranslation("openArmyDialog", "open army"); + string cancelText = Translation.GetTranslation("bttnCancel", "cancel"); + string openText = Translation.GetTranslation("bttnOpen", "open"); + FileChooserDialog fileDialog = new FileChooserDialog(title, this, FileChooserAction.Open, cancelText, ResponseType.Cancel, openText, ResponseType.Accept); FileFilter filter = new FileFilter(); filter.AddPattern("*.army"); - filter.Name = "WarFoundry Army files (*.army)"; + filter.Name = Translation.GetTranslation("armyFileFilter", "WarFoundry .army files"); fileDialog.AddFilter(filter); int response = fileDialog.Run(); string filePath = null; @@ -814,7 +813,16 @@ if (filePath != null) { FileInfo file = new FileInfo(filePath); - Army army = WarFoundryLoader.GetDefault().LoadArmy(file); + Army army = null; + + try + { + army = WarFoundryLoader.GetDefault().LoadArmy(file); + } + catch (Exception ex) + { + logger.Error("Error while loading army file " + filePath, ex); + } if (army != null) { @@ -826,9 +834,8 @@ } else { - logger.ErrorFormat("Failed to load {0} as an army file", filePath); - MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, file.Name + " could not be loaded.\n\nIf the file is an army file then please check your file loaders."); - dialog.Title = "Failed to open army"; + MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, Translation.GetTranslation("OpenFailed", "File open failed. Please check log file")); + dialog.Title = Translation.GetTranslation("OpenFailedTitle", "File open failed"); dialog.Run(); dialog.Hide(); dialog.Dispose(); @@ -856,10 +863,13 @@ private bool SaveCurrentArmyAs() { - FileChooserDialog fileDialog = new FileChooserDialog("Save file as", this, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", ResponseType.Accept); + string title = Translation.GetTranslation("saveArmyDialog", "save army"); + string cancelText = Translation.GetTranslation("bttnCancel", "cancel"); + string saveText = Translation.GetTranslation("bttnSave", "save"); + FileChooserDialog fileDialog = new FileChooserDialog(title, this, FileChooserAction.Save, cancelText, ResponseType.Cancel, saveText, ResponseType.Accept); FileFilter filter = new FileFilter(); filter.AddPattern("*.army"); - filter.Name = "WarFoundry Army files (*.army)"; + filter.Name = Translation.GetTranslation("armyFileFilter", "WarFoundry .army files"); fileDialog.AddFilter(filter); int response = fileDialog.Run(); string filePath = null; @@ -881,7 +891,18 @@ if (filePath != null) { - if (WarFoundrySaver.GetSaver().Save(WarFoundryCore.CurrentArmy, filePath)) + bool saveSuccess = false; + + try + { + saveSuccess = WarFoundrySaver.GetSaver().Save(WarFoundryCore.CurrentArmy, filePath); + } + catch (Exception ex) + { + logger.Error("Error while saving army file to " + filePath, ex); + } + + if (saveSuccess) { miSaveArmy.Sensitive = false; bttnSaveArmy.Sensitive = false; @@ -891,8 +912,8 @@ } else { - MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Failed to save file to " + filePath); - dialog.Title = "Army save failed"; + MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, Translation.GetTranslation("SaveFailed", "File save failed. Please check log file")); + dialog.Title = Translation.GetTranslation("SaveFailedTitle", "File save failed"); dialog.Run(); dialog.Hide(); dialog.Dispose(); @@ -911,8 +932,14 @@ if (CommandStack.IsDirty()) { - MessageDialog dia = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Question, ButtonsType.YesNo, "The army \"" + WarFoundryCore.CurrentArmy.Name + "\" has been modified.\r\nSave changes before closing army?"); - dia.AddButton("Cancel", ResponseType.Cancel); + string message = Translation.GetTranslation("SaveChangesQuestion", "Save changes to army before closing?", WarFoundryCore.CurrentArmy.Name); + MessageDialog dia = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Question, ButtonsType.None, message); + dia.AddButton(Translation.GetTranslation("bttnDiscard", "lose changes"), ResponseType.No); + Button button = (Button)dia.AddButton(Translation.GetTranslation("bttnCancel", "cancel"), ResponseType.Cancel); + button.Image = new Image("gtk-cancel", IconSize.Button); + button = (Button)dia.AddButton(Translation.GetTranslation("bttnSave", "save"), ResponseType.Yes); + button.Image = new Image("gtk-save", IconSize.Button); + dia.Title = Translation.GetTranslation("SaveChangesTitle", "Save changes?"); ResponseType dr = (ResponseType)dia.Run(); dia.Hide(); dia.Dispose(); diff -r 6d2c8ad0d8f1 -r fac0636ae13b UIControl/AbstractBaseEquipmentUIControl.cs --- a/UIControl/AbstractBaseEquipmentUIControl.cs Sun Jan 02 15:50:29 2011 +0000 +++ b/UIControl/AbstractBaseEquipmentUIControl.cs Sun Jan 02 21:03:15 2011 +0000 @@ -21,7 +21,7 @@ protected int minNumber, maxNumber; protected bool isRatioAmount; protected double equipmentAmount; - + public AbstractBaseEquipmentUIControl(Unit unit, CommandStack commandStack) { this.unit = unit; @@ -56,12 +56,12 @@ { //Do nothing } - + protected void HandleUnitEquipmentAmountChanged() { SetUnitEquipmentValuesFromUI(); } - + protected void SetUnitEquipmentLimits(UnitEquipmentItem equip) { ui.IgnoreWidgets(); @@ -90,7 +90,7 @@ ui.ListenToWidgets(); } - + protected void SetUnitEquipmentValuesFromEquipment(UnitEquipmentItem equip) { isRatioAmount = UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip); @@ -119,7 +119,7 @@ SetUnitEquipmentValues(); } - + private void SetUnitEquipmentValues() { ui.IgnoreWidgets(); @@ -144,7 +144,7 @@ { string percentageTooLarge = Translation.GetTranslation("equipPercentageTooLarge", "the current percentage ({0}%) was larger than the maximum for the equipment item ({1}%) - the maximum value will be used instead", equipAmount, maxPercentage); string percentageTooLargeTitle = Translation.GetTranslation("equipPercentageTooLargeTitle", "equipment percentage too large"); - // MessageBox.Show(ParentForm, percentageTooLarge, percentageTooLargeTitle); + ShowMessage(percentageTooLarge, percentageTooLargeTitle); equipAmount = maxPercentage; } else @@ -153,7 +153,7 @@ { string percentageTooSmall = Translation.GetTranslation("equipPercentageTooSmall", "the current percentage ({0}%) was smaller than the minimum for the equipment item ({1}%) - the minimum value will be used instead", equipAmount, minPercentage); string percentageTooSmallTitle = Translation.GetTranslation("equipPercentageTooSmallTitle", "equipment percentage too small"); - // MessageBox.Show(ParentForm, percentageTooSmall, percentageTooSmallTitle); + ShowMessage(percentageTooSmall, percentageTooSmallTitle); equipAmount = minPercentage; } @@ -168,13 +168,22 @@ return Math.Min(Math.Max(calcedAmount, minNumber), maxNumber); } + private void ShowMessage(string message, string title) + { + Gtk.MessageDialog dialog = new Gtk.MessageDialog(null, Gtk.DialogFlags.Modal, Gtk.MessageType.Warning, Gtk.ButtonsType.Ok, false, message); + dialog.Title = title; + dialog.Run(); + dialog.Hide(); + dialog.Dispose(); + } + private void SetEquipmentAmountsFromNumber(int equipAmount) { if (equipAmount > maxNumber) { string amountTooLarge = Translation.GetTranslation("equipNumberTooLarge", "the current amount ({0}) was larger than the maximum for the equipment item ({1}) - the maximum value will be used instead", equipAmount, maxNumber); string amountTooLargeTitle = Translation.GetTranslation("equipNumberTooLargeTitle", "equipment amount too large"); - //MessageBox.Show(ParentForm, amountTooLarge, amountTooLargeTitle); + ShowMessage(amountTooLarge, amountTooLargeTitle); equipAmount = maxNumber; } else @@ -183,7 +192,7 @@ { string amountTooSmall = Translation.GetTranslation("equipNumberTooSmall", "the current amount ({0}) was smaller than the minimum for the equipment item ({1}) - the minimum value will be used instead", equipAmount, minNumber); string amountTooSmallTitle = Translation.GetTranslation("equipNumberTooSmallTitle", "equipment amount too small"); - //MessageBox.Show(ParentForm, amountTooSmall, amountTooSmallTitle); + ShowMessage(amountTooSmall, amountTooSmallTitle); equipAmount = minNumber; } @@ -221,7 +230,7 @@ int maxNumber = UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip); return Math.Max(0, maxNumber); } - + protected int GetMinNumericLimit(UnitEquipmentItem equip) { int minNumber = UnitEquipmentUtil.GetMinEquipmentCount(unit, equip); @@ -248,7 +257,7 @@ { return Math.Round(percent, 1); } - + public void Show() { SetupUI(); diff -r 6d2c8ad0d8f1 -r fac0636ae13b gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmAddEquipment.cs --- a/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmAddEquipment.cs Sun Jan 02 15:50:29 2011 +0000 +++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmAddEquipment.cs Sun Jan 02 21:03:15 2011 +0000 @@ -120,6 +120,7 @@ this.rbEquipAll = new global::Gtk.RadioButton(""); this.rbEquipAll.CanFocus = true; this.rbEquipAll.Name = "rbEquipAll"; + this.rbEquipAll.Active = true; this.rbEquipAll.DrawIndicator = true; this.rbEquipAll.UseUnderline = true; this.rbEquipAll.Group = new global::GLib.SList(global::System.IntPtr.Zero); diff -r 6d2c8ad0d8f1 -r fac0636ae13b gtk-gui/gui.stetic --- a/gtk-gui/gui.stetic Sun Jan 02 15:50:29 2011 +0000 +++ b/gtk-gui/gui.stetic Sun Jan 02 21:03:15 2011 +0000 @@ -1189,6 +1189,7 @@ True + True True True True @@ -1835,7 +1836,6 @@ True - True True True True diff -r 6d2c8ad0d8f1 -r fac0636ae13b translations/en.translation --- a/translations/en.translation Sun Jan 02 15:50:29 2011 +0000 +++ b/translations/en.translation Sun Jan 02 21:03:15 2011 +0000 @@ -1,8 +1,17 @@ - + + +Cancel +OK +Close +Create + +{0} pts / {1} pts + _File _Edit _Help + Create _new army _Open army _Save army @@ -12,25 +21,40 @@ _Close army _Reload files _Quit + _Undo _Redo _Preferences + _About + Create new army Open army Save army Undo Redo Add unit from {0} + Army Categories Remove Unit + WarFoundry Army Files (*.army) -Cancel -OK -Select system + +Open army +Open +WarFoundry could not open the specified file. Please check the log for more information. +File load failed + Save army -Unit of {0} {1} -{0} pts / {1} pts +Save +WarFoundry was unable to save the file. Please check the log for more details +File save failed + +The army "{0}" has been modified. +Save changes before closing army? +Unsaved changes +Close without saving + Add Edit Remove @@ -38,13 +62,18 @@ Equipment: Abilities: Notes: + Create Army Game systems: Races: Army name: Army size: -Create Race + +Add New {0} Choice +Unit Type +Unit Type: + The current percentage ({0}%) was larger than the maximum for the equipment item ({1}%). The maximum value will be used instead. Equipment percentage too large The current percentage ({0}%) was smaller than the minimum for the equipment item ({1}%). The minimum value will be used instead. @@ -53,35 +82,38 @@ Equipment amount too large The current amount ({0}) was smaller than the minimum for the equipment item ({1}). The minimum value will be used instead. Equipment amount too small -Add New {0} Choice -Unit Type -Unit Type: -Add Equipment -Equipment Equip All % Amount: -Equipment: +Equipment: + +Add Equipment +Equipment + Edit Equipment Equipment + Replace Equipment + +Preferences +Language +Language: +Language + About WarFoundry -Close -Credits © 2007-2010, IBBoard and others WarFoundry is an open-source army creation tool that lets you create rosters for multiple game systems. +Credits + +Credits +Developers: +Testers (General WarFoundry): +Testers (GTK UI): + Export army Cancel Export HTML pages (*.html) -Credits -Developers: -Testers (General WarFoundry): -Testers (GTK UI): -Preferences -Language -Language: -Language {0} - {1}pts Name Notes @@ -90,9 +122,8 @@ {0}% ({1}) {0} {0} for {1} -all ({1}) -{0}% ({1}) -{0} + +Unit of {0} {1} Set {0} amount for {1} to {2} Set {0} amount for {1} to {2} Replace {0} with {1} for {2} @@ -105,4 +136,7 @@ Rename "{0}" to "{1}" Set size of {0} to {1} Set size of {0} to {1} +all ({1}) +{0}% ({1}) +{0} \ No newline at end of file diff -r 6d2c8ad0d8f1 -r fac0636ae13b translations/fr.translation --- a/translations/fr.translation Sun Jan 02 15:50:29 2011 +0000 +++ b/translations/fr.translation Sun Jan 02 21:03:15 2011 +0000 @@ -127,4 +127,8 @@ Créer Équipement % +_Ouvrir +WarFoundry ne peut pas ouvrir le fichier. Veillez vérifier le log pour plus d'informations +Échec de la ouvrir du fichier +Sauvegarder