# HG changeset patch # User IBBoard # Date 1318968215 -3600 # Node ID f23e5b40ca9dcb99c52c9b2dbe48a4045e50434c # Parent 1ce4fe9ae3c1af4cac34024f57bb69a2c6b579c2 Re #344: Show unit requirement failures * Add new widget for displaying failures nicely * Use widget for displaying failures in main window * Use widget for displaying failures in new unit dialog diff -r 1ce4fe9ae3c1 -r f23e5b40ca9d FrmMainWindow.cs --- a/FrmMainWindow.cs Mon Oct 17 20:53:07 2011 +0100 +++ b/FrmMainWindow.cs Tue Oct 18 21:03:35 2011 +0100 @@ -1258,6 +1258,7 @@ protected void OnTransformedXmlActionActivated(object sender, System.EventArgs e) { FrmExportXml form = new FrmExportXml(WarFoundryCore.CurrentArmy); + form.ParentWindow = this.GdkWindow; form.Run(); form.Hide(); form.Dispose(); @@ -1266,6 +1267,8 @@ protected void OnMiEditArmyActivated(object sender, System.EventArgs e) { FrmEditArmy form = new FrmEditArmy(commandStack, WarFoundryCore.CurrentArmy); + form.TransientFor = this; + form.WindowPosition = WindowPosition.CenterOnParent; form.Run(); form.Hide(); form.Dispose(); @@ -1282,15 +1285,8 @@ if (failureMessages != null && failureMessages.Count > 0) { - StringBuilder sb = new StringBuilder(); - - foreach (string msg in failureMessages) - { - sb.AppendLine(msg); - } - - MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Warning, ButtonsType.Ok, false, sb.ToString()); - dialog.Title = "Validation errors"; + ValidationFailureWidget failureWidget = new ValidationFailureWidget(failureMessages); + Dialog dialog = new SimpleDialog("Validation errors", this, DialogFlags.Modal, failureWidget); dialog.Run(); dialog.Hide(); dialog.Dispose(); diff -r 1ce4fe9ae3c1 -r f23e5b40ca9d FrmNewUnit.cs --- a/FrmNewUnit.cs Mon Oct 17 20:53:07 2011 +0100 +++ b/FrmNewUnit.cs Tue Oct 18 21:03:35 2011 +0100 @@ -108,24 +108,17 @@ ICollection failureMessages; Validation result = RequirementHandler.AllowsAdding(type, unitArmy, out failureMessages); bool validationFailed = !Validates.AsOkay(result); - lblNewUnitWarning.Visible = validationFailed; + validationWidget.Visible = validationFailed; if (validationFailed) { - StringBuilder sb = new StringBuilder(); - - foreach (string msg in failureMessages) - { - sb.AppendLine(msg); - } - - lblNewUnitWarning.Text = sb.ToString(); + validationWidget.SetMessages(failureMessages); } } else { bttnCreate.Sensitive = false; - lblNewUnitWarning.Visible = false; + validationWidget.Visible = false; } } diff -r 1ce4fe9ae3c1 -r f23e5b40ca9d IBBoard.WarFoundry.GUI.GTK.csproj --- a/IBBoard.WarFoundry.GUI.GTK.csproj Mon Oct 17 20:53:07 2011 +0100 +++ b/IBBoard.WarFoundry.GUI.GTK.csproj Tue Oct 18 21:03:35 2011 +0100 @@ -77,6 +77,8 @@ + + diff -r 1ce4fe9ae3c1 -r f23e5b40ca9d Widgets/ValidationFailureWidget.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Widgets/ValidationFailureWidget.cs Tue Oct 18 21:03:35 2011 +0100 @@ -0,0 +1,36 @@ +// This file (ValidationFailureWidget.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 System.Collections.Generic; +using System.Text; + +namespace IBBoard.WarFoundry.GUI.GTK +{ + [System.ComponentModel.ToolboxItem(true)] + public partial class ValidationFailureWidget : Gtk.Bin + { + public ValidationFailureWidget() + { + this.Build(); + } + + public ValidationFailureWidget(ICollection messages) : this() + { + SetMessages(messages); + } + + public void SetMessages(ICollection messages) + { + StringBuilder sb = new StringBuilder(); + + foreach (string msg in messages) + { + sb.AppendLine("• " + msg); + } + + validationMessages.Text = sb.ToString(); + } + } +} + diff -r 1ce4fe9ae3c1 -r f23e5b40ca9d gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmNewUnit.cs --- a/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmNewUnit.cs Mon Oct 17 20:53:07 2011 +0100 +++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmNewUnit.cs Tue Oct 18 21:03:35 2011 +0100 @@ -9,7 +9,7 @@ private global::IBBoard.GtkSharp.Translatable.TranslatableLabel lblUnitList; private global::Gtk.ScrolledWindow GtkScrolledWindow; private global::Gtk.TreeView lstUnitTypes; - private global::IBBoard.GtkSharp.Translatable.TranslatableLabel lblNewUnitWarning; + private global::IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget validationWidget; private global::IBBoard.GtkSharp.Translatable.TranslatableButton bttnCancel; private global::IBBoard.GtkSharp.Translatable.TranslatableButton bttnCreate; @@ -65,12 +65,14 @@ w5.Expand = false; w5.Fill = false; // Container child vbox2.Gtk.Box+BoxChild - this.lblNewUnitWarning = new global::IBBoard.GtkSharp.Translatable.TranslatableLabel (); - this.lblNewUnitWarning.Name = "lblNewUnitWarning"; - this.lblNewUnitWarning.Xalign = 0F; - this.vbox2.Add (this.lblNewUnitWarning); - global::Gtk.Box.BoxChild w6 = ((global::Gtk.Box.BoxChild)(this.vbox2 [this.lblNewUnitWarning])); + this.validationWidget = new global::IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget (); + this.validationWidget.Events = ((global::Gdk.EventMask)(256)); + this.validationWidget.Name = "validationWidget"; + this.vbox2.Add (this.validationWidget); + global::Gtk.Box.BoxChild w6 = ((global::Gtk.Box.BoxChild)(this.vbox2 [this.validationWidget])); w6.Position = 1; + w6.Expand = false; + w6.Fill = false; w1.Add (this.vbox2); global::Gtk.Box.BoxChild w7 = ((global::Gtk.Box.BoxChild)(w1 [this.vbox2])); w7.Position = 0; @@ -109,8 +111,7 @@ this.Child.ShowAll (); } this.DefaultWidth = 403; - this.DefaultHeight = 259; - this.lblNewUnitWarning.Hide (); + this.DefaultHeight = 311; this.Show (); this.lstUnitTypes.RowActivated += new global::Gtk.RowActivatedHandler (this.OnRowActivated); this.bttnCancel.Clicked += new global::System.EventHandler (this.OnButtonCancelActivated); diff -r 1ce4fe9ae3c1 -r f23e5b40ca9d gtk-gui/IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget.cs Tue Oct 18 21:03:35 2011 +0100 @@ -0,0 +1,59 @@ + +// This file has been generated by the GUI designer. Do not modify. +namespace IBBoard.WarFoundry.GUI.GTK +{ + public partial class ValidationFailureWidget + { + private global::Gtk.HBox hbox1; + private global::Gtk.Image image1; + private global::Gtk.ScrolledWindow scrolledwindow1; + private global::Gtk.Label validationMessages; + + protected virtual void Build () + { + global::Stetic.Gui.Initialize (this); + // Widget IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget + global::Stetic.BinContainer.Attach (this); + this.Name = "IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget"; + // Container child IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget.Gtk.Container+ContainerChild + this.hbox1 = new global::Gtk.HBox (); + this.hbox1.Name = "hbox1"; + this.hbox1.Spacing = 6; + // Container child hbox1.Gtk.Box+BoxChild + this.image1 = new global::Gtk.Image (); + this.image1.Name = "image1"; + this.image1.Pixbuf = global::Stetic.IconLoader.LoadIcon (this, "gtk-dialog-warning", global::Gtk.IconSize.Dialog); + this.hbox1.Add (this.image1); + global::Gtk.Box.BoxChild w1 = ((global::Gtk.Box.BoxChild)(this.hbox1 [this.image1])); + w1.Position = 0; + w1.Expand = false; + w1.Fill = false; + // Container child hbox1.Gtk.Box+BoxChild + this.scrolledwindow1 = new global::Gtk.ScrolledWindow (); + this.scrolledwindow1.CanFocus = true; + this.scrolledwindow1.Name = "scrolledwindow1"; + this.scrolledwindow1.HscrollbarPolicy = ((global::Gtk.PolicyType)(2)); + this.scrolledwindow1.ShadowType = ((global::Gtk.ShadowType)(1)); + // Container child scrolledwindow1.Gtk.Container+ContainerChild + global::Gtk.Viewport w2 = new global::Gtk.Viewport (); + w2.ShadowType = ((global::Gtk.ShadowType)(0)); + // Container child GtkViewport.Gtk.Container+ContainerChild + this.validationMessages = new global::Gtk.Label (); + this.validationMessages.Name = "validationMessages"; + this.validationMessages.Xalign = 0F; + this.validationMessages.Yalign = 0F; + this.validationMessages.LabelProp = global::Mono.Unix.Catalog.GetString ("Fibble"); + this.validationMessages.Wrap = true; + w2.Add (this.validationMessages); + this.scrolledwindow1.Add (w2); + this.hbox1.Add (this.scrolledwindow1); + global::Gtk.Box.BoxChild w5 = ((global::Gtk.Box.BoxChild)(this.hbox1 [this.scrolledwindow1])); + w5.Position = 1; + this.Add (this.hbox1); + if ((this.Child != null)) { + this.Child.ShowAll (); + } + this.Hide (); + } + } +} diff -r 1ce4fe9ae3c1 -r f23e5b40ca9d gtk-gui/gui.stetic --- a/gtk-gui/gui.stetic Mon Oct 17 20:53:07 2011 +0100 +++ b/gtk-gui/gui.stetic Tue Oct 18 21:03:35 2011 +0100 @@ -186,7 +186,6 @@ - 0 @@ -378,7 +377,6 @@ - 0 @@ -597,7 +595,7 @@ - + Add new unit stock:gtk-new Menu @@ -660,14 +658,15 @@ - + - False - 0 + ButtonPressMask 1 - False + True + False + False @@ -2647,7 +2646,6 @@ - 0 @@ -2797,4 +2795,53 @@ + + + False + + + + 6 + + + + stock:gtk-dialog-warning Dialog + + + 0 + True + False + False + + + + + + True + Never + In + + + + None + + + + 0 + 0 + Fibble + True + + + + + + + 1 + True + + + + + \ No newline at end of file diff -r 1ce4fe9ae3c1 -r f23e5b40ca9d gtk-gui/objects.xml --- a/gtk-gui/objects.xml Mon Oct 17 20:53:07 2011 +0100 +++ b/gtk-gui/objects.xml Tue Oct 18 21:03:35 2011 +0100 @@ -11,4 +11,8 @@ + + + + \ No newline at end of file