Mercurial > repos > IBBoard.WarFoundry.GUI.GTK
changeset 142:f23e5b40ca9d
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
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 18 Oct 2011 21:03:35 +0100 |
parents | 1ce4fe9ae3c1 |
children | aca4623b7bdf |
files | FrmMainWindow.cs FrmNewUnit.cs IBBoard.WarFoundry.GUI.GTK.csproj Widgets/ValidationFailureWidget.cs gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmNewUnit.cs gtk-gui/IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget.cs gtk-gui/gui.stetic gtk-gui/objects.xml |
diffstat | 8 files changed, 173 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- 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();
--- 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<string> 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; } }
--- 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 @@ <Compile Include="gtk-gui\IBBoard.WarFoundry.GUI.GTK.TransformXmlWidget.cs" /> <Compile Include="FrmEditArmy.cs" /> <Compile Include="gtk-gui\IBBoard.WarFoundry.GUI.GTK.FrmEditArmy.cs" /> + <Compile Include="Widgets\ValidationFailureWidget.cs" /> + <Compile Include="gtk-gui\IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget.cs" /> </ItemGroup> <ItemGroup> <Content Include="App.png" />
--- /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<string> messages) : this() + { + SetMessages(messages); + } + + public void SetMessages(ICollection<string> messages) + { + StringBuilder sb = new StringBuilder(); + + foreach (string msg in messages) + { + sb.AppendLine("• " + msg); + } + + validationMessages.Text = sb.ToString(); + } + } +} +
--- 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);
--- /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 (); + } + } +}
--- 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 @@ <child> <widget class="Gtk.VBox" id="vbox1"> <property name="MemberName" /> - <property name="Spacing">0</property> <child> <widget class="Gtk.MenuBar" id="menubar1"> <property name="MemberName" /> @@ -378,7 +377,6 @@ <child> <widget class="Gtk.HBox" id="hbox2"> <property name="MemberName" /> - <property name="Spacing">0</property> <child> <widget class="Gtk.SpinButton" id="sbPointsValue"> <property name="MemberName" /> @@ -597,7 +595,7 @@ </widget> </child> </widget> - <widget class="Gtk.Dialog" id="IBBoard.WarFoundry.GUI.GTK.FrmNewUnit" design-size="403 259"> + <widget class="Gtk.Dialog" id="IBBoard.WarFoundry.GUI.GTK.FrmNewUnit" design-size="403 311"> <property name="MemberName" /> <property name="Title" translatable="yes">Add new unit</property> <property name="Icon">stock:gtk-new Menu</property> @@ -660,14 +658,15 @@ </packing> </child> <child> - <widget class="IBBoard.GtkSharp.Translatable.TranslatableLabel" id="lblNewUnitWarning"> + <widget class="IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget" id="validationWidget"> <property name="MemberName" /> - <property name="Visible">False</property> - <property name="Xalign">0</property> + <property name="Events">ButtonPressMask</property> </widget> <packing> <property name="Position">1</property> - <property name="AutoSize">False</property> + <property name="AutoSize">True</property> + <property name="Expand">False</property> + <property name="Fill">False</property> </packing> </child> </widget> @@ -2647,7 +2646,6 @@ <child> <widget class="Gtk.HBox" id="hbox2"> <property name="MemberName" /> - <property name="Spacing">0</property> <child> <widget class="Gtk.SpinButton" id="sbPointsValue"> <property name="MemberName" /> @@ -2797,4 +2795,53 @@ </widget> </child> </widget> + <widget class="Gtk.Bin" id="IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget" design-size="300 104"> + <property name="MemberName" /> + <property name="Visible">False</property> + <child> + <widget class="Gtk.HBox" id="hbox1"> + <property name="MemberName" /> + <property name="Spacing">6</property> + <child> + <widget class="Gtk.Image" id="image1"> + <property name="MemberName" /> + <property name="Pixbuf">stock:gtk-dialog-warning Dialog</property> + </widget> + <packing> + <property name="Position">0</property> + <property name="AutoSize">True</property> + <property name="Expand">False</property> + <property name="Fill">False</property> + </packing> + </child> + <child> + <widget class="Gtk.ScrolledWindow" id="scrolledwindow1"> + <property name="MemberName" /> + <property name="CanFocus">True</property> + <property name="HscrollbarPolicy">Never</property> + <property name="ShadowType">In</property> + <child> + <widget class="Gtk.Viewport" id="GtkViewport"> + <property name="MemberName" /> + <property name="ShadowType">None</property> + <child> + <widget class="Gtk.Label" id="validationMessages"> + <property name="MemberName" /> + <property name="Xalign">0</property> + <property name="Yalign">0</property> + <property name="LabelProp" translatable="yes">Fibble</property> + <property name="Wrap">True</property> + </widget> + </child> + </widget> + </child> + </widget> + <packing> + <property name="Position">1</property> + <property name="AutoSize">True</property> + </packing> + </child> + </widget> + </child> + </widget> </stetic-interface> \ No newline at end of file
--- 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 @@ <itemgroups /> <signals /> </object> + <object type="IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget" palette-category="General" allow-children="false" base-type="Gtk.Bin"> + <itemgroups /> + <signals /> + </object> </objects> \ No newline at end of file