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 diff
     1.1 --- a/FrmMainWindow.cs	Mon Oct 17 20:53:07 2011 +0100
     1.2 +++ b/FrmMainWindow.cs	Tue Oct 18 21:03:35 2011 +0100
     1.3 @@ -1258,6 +1258,7 @@
     1.4  		protected void OnTransformedXmlActionActivated(object sender, System.EventArgs e)
     1.5  		{
     1.6  			FrmExportXml form = new FrmExportXml(WarFoundryCore.CurrentArmy);
     1.7 +			form.ParentWindow = this.GdkWindow;
     1.8  			form.Run();
     1.9  			form.Hide();
    1.10  			form.Dispose();
    1.11 @@ -1266,6 +1267,8 @@
    1.12  		protected void OnMiEditArmyActivated(object sender, System.EventArgs e)
    1.13  		{
    1.14  			FrmEditArmy form = new FrmEditArmy(commandStack, WarFoundryCore.CurrentArmy);
    1.15 +			form.TransientFor = this;
    1.16 +			form.WindowPosition = WindowPosition.CenterOnParent;
    1.17  			form.Run();
    1.18  			form.Hide();
    1.19  			form.Dispose();
    1.20 @@ -1282,15 +1285,8 @@
    1.21  
    1.22  			if (failureMessages != null && failureMessages.Count > 0)
    1.23  			{
    1.24 -				StringBuilder sb = new StringBuilder();
    1.25 -
    1.26 -				foreach (string msg in failureMessages)
    1.27 -				{
    1.28 -					sb.AppendLine(msg);
    1.29 -				}
    1.30 -
    1.31 -				MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Warning, ButtonsType.Ok, false, sb.ToString());
    1.32 -				dialog.Title = "Validation errors";
    1.33 +				ValidationFailureWidget failureWidget = new ValidationFailureWidget(failureMessages);
    1.34 +				Dialog dialog = new SimpleDialog("Validation errors", this, DialogFlags.Modal, failureWidget);
    1.35  				dialog.Run();
    1.36  				dialog.Hide();
    1.37  				dialog.Dispose();
     2.1 --- a/FrmNewUnit.cs	Mon Oct 17 20:53:07 2011 +0100
     2.2 +++ b/FrmNewUnit.cs	Tue Oct 18 21:03:35 2011 +0100
     2.3 @@ -108,24 +108,17 @@
     2.4  				ICollection<string> failureMessages;
     2.5  				Validation result = RequirementHandler.AllowsAdding(type, unitArmy, out failureMessages);
     2.6  				bool validationFailed = !Validates.AsOkay(result);
     2.7 -				lblNewUnitWarning.Visible = validationFailed;
     2.8 +				validationWidget.Visible = validationFailed;
     2.9  
    2.10  				if (validationFailed)
    2.11  				{
    2.12 -					StringBuilder sb = new StringBuilder();
    2.13 -
    2.14 -					foreach (string msg in failureMessages)
    2.15 -					{
    2.16 -						sb.AppendLine(msg);
    2.17 -					}
    2.18 -
    2.19 -					lblNewUnitWarning.Text = sb.ToString();
    2.20 +					validationWidget.SetMessages(failureMessages);
    2.21  				}
    2.22  			}
    2.23  			else
    2.24  			{
    2.25  				bttnCreate.Sensitive = false;
    2.26 -				lblNewUnitWarning.Visible = false;
    2.27 +				validationWidget.Visible = false;
    2.28  			}
    2.29  		}
    2.30  
     3.1 --- a/IBBoard.WarFoundry.GUI.GTK.csproj	Mon Oct 17 20:53:07 2011 +0100
     3.2 +++ b/IBBoard.WarFoundry.GUI.GTK.csproj	Tue Oct 18 21:03:35 2011 +0100
     3.3 @@ -77,6 +77,8 @@
     3.4      <Compile Include="gtk-gui\IBBoard.WarFoundry.GUI.GTK.TransformXmlWidget.cs" />
     3.5      <Compile Include="FrmEditArmy.cs" />
     3.6      <Compile Include="gtk-gui\IBBoard.WarFoundry.GUI.GTK.FrmEditArmy.cs" />
     3.7 +    <Compile Include="Widgets\ValidationFailureWidget.cs" />
     3.8 +    <Compile Include="gtk-gui\IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget.cs" />
     3.9    </ItemGroup>
    3.10    <ItemGroup>
    3.11      <Content Include="App.png" />
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/Widgets/ValidationFailureWidget.cs	Tue Oct 18 21:03:35 2011 +0100
     4.3 @@ -0,0 +1,36 @@
     4.4 +// This file (ValidationFailureWidget.cs) is a part of the IBBoard.WarFoundry.GUI.GTK project and is copyright 2011 IBBoard
     4.5 +// 
     4.6 +// 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.
     4.7 +using System;
     4.8 +using System.Collections.Generic;
     4.9 +using System.Text;
    4.10 +
    4.11 +namespace IBBoard.WarFoundry.GUI.GTK
    4.12 +{
    4.13 +	[System.ComponentModel.ToolboxItem(true)]
    4.14 +	public partial class ValidationFailureWidget : Gtk.Bin
    4.15 +	{
    4.16 +		public ValidationFailureWidget()
    4.17 +		{
    4.18 +			this.Build();
    4.19 +		}
    4.20 +
    4.21 +		public ValidationFailureWidget(ICollection<string> messages) : this()
    4.22 +		{
    4.23 +			SetMessages(messages);
    4.24 +		}
    4.25 +
    4.26 +		public void SetMessages(ICollection<string> messages)
    4.27 +		{
    4.28 +			StringBuilder sb = new StringBuilder();
    4.29 +			
    4.30 +			foreach (string msg in messages)
    4.31 +			{
    4.32 +				sb.AppendLine("• " + msg);
    4.33 +			}
    4.34 +			
    4.35 +			validationMessages.Text = sb.ToString();
    4.36 +		}
    4.37 +	}
    4.38 +}
    4.39 +
     5.1 --- a/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmNewUnit.cs	Mon Oct 17 20:53:07 2011 +0100
     5.2 +++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmNewUnit.cs	Tue Oct 18 21:03:35 2011 +0100
     5.3 @@ -9,7 +9,7 @@
     5.4  		private global::IBBoard.GtkSharp.Translatable.TranslatableLabel lblUnitList;
     5.5  		private global::Gtk.ScrolledWindow GtkScrolledWindow;
     5.6  		private global::Gtk.TreeView lstUnitTypes;
     5.7 -		private global::IBBoard.GtkSharp.Translatable.TranslatableLabel lblNewUnitWarning;
     5.8 +		private global::IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget validationWidget;
     5.9  		private global::IBBoard.GtkSharp.Translatable.TranslatableButton bttnCancel;
    5.10  		private global::IBBoard.GtkSharp.Translatable.TranslatableButton bttnCreate;
    5.11  		
    5.12 @@ -65,12 +65,14 @@
    5.13  			w5.Expand = false;
    5.14  			w5.Fill = false;
    5.15  			// Container child vbox2.Gtk.Box+BoxChild
    5.16 -			this.lblNewUnitWarning = new global::IBBoard.GtkSharp.Translatable.TranslatableLabel ();
    5.17 -			this.lblNewUnitWarning.Name = "lblNewUnitWarning";
    5.18 -			this.lblNewUnitWarning.Xalign = 0F;
    5.19 -			this.vbox2.Add (this.lblNewUnitWarning);
    5.20 -			global::Gtk.Box.BoxChild w6 = ((global::Gtk.Box.BoxChild)(this.vbox2 [this.lblNewUnitWarning]));
    5.21 +			this.validationWidget = new global::IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget ();
    5.22 +			this.validationWidget.Events = ((global::Gdk.EventMask)(256));
    5.23 +			this.validationWidget.Name = "validationWidget";
    5.24 +			this.vbox2.Add (this.validationWidget);
    5.25 +			global::Gtk.Box.BoxChild w6 = ((global::Gtk.Box.BoxChild)(this.vbox2 [this.validationWidget]));
    5.26  			w6.Position = 1;
    5.27 +			w6.Expand = false;
    5.28 +			w6.Fill = false;
    5.29  			w1.Add (this.vbox2);
    5.30  			global::Gtk.Box.BoxChild w7 = ((global::Gtk.Box.BoxChild)(w1 [this.vbox2]));
    5.31  			w7.Position = 0;
    5.32 @@ -109,8 +111,7 @@
    5.33  				this.Child.ShowAll ();
    5.34  			}
    5.35  			this.DefaultWidth = 403;
    5.36 -			this.DefaultHeight = 259;
    5.37 -			this.lblNewUnitWarning.Hide ();
    5.38 +			this.DefaultHeight = 311;
    5.39  			this.Show ();
    5.40  			this.lstUnitTypes.RowActivated += new global::Gtk.RowActivatedHandler (this.OnRowActivated);
    5.41  			this.bttnCancel.Clicked += new global::System.EventHandler (this.OnButtonCancelActivated);
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget.cs	Tue Oct 18 21:03:35 2011 +0100
     6.3 @@ -0,0 +1,59 @@
     6.4 +
     6.5 +// This file has been generated by the GUI designer. Do not modify.
     6.6 +namespace IBBoard.WarFoundry.GUI.GTK
     6.7 +{
     6.8 +	public partial class ValidationFailureWidget
     6.9 +	{
    6.10 +		private global::Gtk.HBox hbox1;
    6.11 +		private global::Gtk.Image image1;
    6.12 +		private global::Gtk.ScrolledWindow scrolledwindow1;
    6.13 +		private global::Gtk.Label validationMessages;
    6.14 +		
    6.15 +		protected virtual void Build ()
    6.16 +		{
    6.17 +			global::Stetic.Gui.Initialize (this);
    6.18 +			// Widget IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget
    6.19 +			global::Stetic.BinContainer.Attach (this);
    6.20 +			this.Name = "IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget";
    6.21 +			// Container child IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget.Gtk.Container+ContainerChild
    6.22 +			this.hbox1 = new global::Gtk.HBox ();
    6.23 +			this.hbox1.Name = "hbox1";
    6.24 +			this.hbox1.Spacing = 6;
    6.25 +			// Container child hbox1.Gtk.Box+BoxChild
    6.26 +			this.image1 = new global::Gtk.Image ();
    6.27 +			this.image1.Name = "image1";
    6.28 +			this.image1.Pixbuf = global::Stetic.IconLoader.LoadIcon (this, "gtk-dialog-warning", global::Gtk.IconSize.Dialog);
    6.29 +			this.hbox1.Add (this.image1);
    6.30 +			global::Gtk.Box.BoxChild w1 = ((global::Gtk.Box.BoxChild)(this.hbox1 [this.image1]));
    6.31 +			w1.Position = 0;
    6.32 +			w1.Expand = false;
    6.33 +			w1.Fill = false;
    6.34 +			// Container child hbox1.Gtk.Box+BoxChild
    6.35 +			this.scrolledwindow1 = new global::Gtk.ScrolledWindow ();
    6.36 +			this.scrolledwindow1.CanFocus = true;
    6.37 +			this.scrolledwindow1.Name = "scrolledwindow1";
    6.38 +			this.scrolledwindow1.HscrollbarPolicy = ((global::Gtk.PolicyType)(2));
    6.39 +			this.scrolledwindow1.ShadowType = ((global::Gtk.ShadowType)(1));
    6.40 +			// Container child scrolledwindow1.Gtk.Container+ContainerChild
    6.41 +			global::Gtk.Viewport w2 = new global::Gtk.Viewport ();
    6.42 +			w2.ShadowType = ((global::Gtk.ShadowType)(0));
    6.43 +			// Container child GtkViewport.Gtk.Container+ContainerChild
    6.44 +			this.validationMessages = new global::Gtk.Label ();
    6.45 +			this.validationMessages.Name = "validationMessages";
    6.46 +			this.validationMessages.Xalign = 0F;
    6.47 +			this.validationMessages.Yalign = 0F;
    6.48 +			this.validationMessages.LabelProp = global::Mono.Unix.Catalog.GetString ("Fibble");
    6.49 +			this.validationMessages.Wrap = true;
    6.50 +			w2.Add (this.validationMessages);
    6.51 +			this.scrolledwindow1.Add (w2);
    6.52 +			this.hbox1.Add (this.scrolledwindow1);
    6.53 +			global::Gtk.Box.BoxChild w5 = ((global::Gtk.Box.BoxChild)(this.hbox1 [this.scrolledwindow1]));
    6.54 +			w5.Position = 1;
    6.55 +			this.Add (this.hbox1);
    6.56 +			if ((this.Child != null)) {
    6.57 +				this.Child.ShowAll ();
    6.58 +			}
    6.59 +			this.Hide ();
    6.60 +		}
    6.61 +	}
    6.62 +}
     7.1 --- a/gtk-gui/gui.stetic	Mon Oct 17 20:53:07 2011 +0100
     7.2 +++ b/gtk-gui/gui.stetic	Tue Oct 18 21:03:35 2011 +0100
     7.3 @@ -186,7 +186,6 @@
     7.4      <child>
     7.5        <widget class="Gtk.VBox" id="vbox1">
     7.6          <property name="MemberName" />
     7.7 -        <property name="Spacing">0</property>
     7.8          <child>
     7.9            <widget class="Gtk.MenuBar" id="menubar1">
    7.10              <property name="MemberName" />
    7.11 @@ -378,7 +377,6 @@
    7.12              <child>
    7.13                <widget class="Gtk.HBox" id="hbox2">
    7.14                  <property name="MemberName" />
    7.15 -                <property name="Spacing">0</property>
    7.16                  <child>
    7.17                    <widget class="Gtk.SpinButton" id="sbPointsValue">
    7.18                      <property name="MemberName" />
    7.19 @@ -597,7 +595,7 @@
    7.20        </widget>
    7.21      </child>
    7.22    </widget>
    7.23 -  <widget class="Gtk.Dialog" id="IBBoard.WarFoundry.GUI.GTK.FrmNewUnit" design-size="403 259">
    7.24 +  <widget class="Gtk.Dialog" id="IBBoard.WarFoundry.GUI.GTK.FrmNewUnit" design-size="403 311">
    7.25      <property name="MemberName" />
    7.26      <property name="Title" translatable="yes">Add new unit</property>
    7.27      <property name="Icon">stock:gtk-new Menu</property>
    7.28 @@ -660,14 +658,15 @@
    7.29                </packing>
    7.30              </child>
    7.31              <child>
    7.32 -              <widget class="IBBoard.GtkSharp.Translatable.TranslatableLabel" id="lblNewUnitWarning">
    7.33 +              <widget class="IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget" id="validationWidget">
    7.34                  <property name="MemberName" />
    7.35 -                <property name="Visible">False</property>
    7.36 -                <property name="Xalign">0</property>
    7.37 +                <property name="Events">ButtonPressMask</property>
    7.38                </widget>
    7.39                <packing>
    7.40                  <property name="Position">1</property>
    7.41 -                <property name="AutoSize">False</property>
    7.42 +                <property name="AutoSize">True</property>
    7.43 +                <property name="Expand">False</property>
    7.44 +                <property name="Fill">False</property>
    7.45                </packing>
    7.46              </child>
    7.47            </widget>
    7.48 @@ -2647,7 +2646,6 @@
    7.49              <child>
    7.50                <widget class="Gtk.HBox" id="hbox2">
    7.51                  <property name="MemberName" />
    7.52 -                <property name="Spacing">0</property>
    7.53                  <child>
    7.54                    <widget class="Gtk.SpinButton" id="sbPointsValue">
    7.55                      <property name="MemberName" />
    7.56 @@ -2797,4 +2795,53 @@
    7.57        </widget>
    7.58      </child>
    7.59    </widget>
    7.60 +  <widget class="Gtk.Bin" id="IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget" design-size="300 104">
    7.61 +    <property name="MemberName" />
    7.62 +    <property name="Visible">False</property>
    7.63 +    <child>
    7.64 +      <widget class="Gtk.HBox" id="hbox1">
    7.65 +        <property name="MemberName" />
    7.66 +        <property name="Spacing">6</property>
    7.67 +        <child>
    7.68 +          <widget class="Gtk.Image" id="image1">
    7.69 +            <property name="MemberName" />
    7.70 +            <property name="Pixbuf">stock:gtk-dialog-warning Dialog</property>
    7.71 +          </widget>
    7.72 +          <packing>
    7.73 +            <property name="Position">0</property>
    7.74 +            <property name="AutoSize">True</property>
    7.75 +            <property name="Expand">False</property>
    7.76 +            <property name="Fill">False</property>
    7.77 +          </packing>
    7.78 +        </child>
    7.79 +        <child>
    7.80 +          <widget class="Gtk.ScrolledWindow" id="scrolledwindow1">
    7.81 +            <property name="MemberName" />
    7.82 +            <property name="CanFocus">True</property>
    7.83 +            <property name="HscrollbarPolicy">Never</property>
    7.84 +            <property name="ShadowType">In</property>
    7.85 +            <child>
    7.86 +              <widget class="Gtk.Viewport" id="GtkViewport">
    7.87 +                <property name="MemberName" />
    7.88 +                <property name="ShadowType">None</property>
    7.89 +                <child>
    7.90 +                  <widget class="Gtk.Label" id="validationMessages">
    7.91 +                    <property name="MemberName" />
    7.92 +                    <property name="Xalign">0</property>
    7.93 +                    <property name="Yalign">0</property>
    7.94 +                    <property name="LabelProp" translatable="yes">Fibble</property>
    7.95 +                    <property name="Wrap">True</property>
    7.96 +                  </widget>
    7.97 +                </child>
    7.98 +              </widget>
    7.99 +            </child>
   7.100 +          </widget>
   7.101 +          <packing>
   7.102 +            <property name="Position">1</property>
   7.103 +            <property name="AutoSize">True</property>
   7.104 +          </packing>
   7.105 +        </child>
   7.106 +      </widget>
   7.107 +    </child>
   7.108 +  </widget>
   7.109  </stetic-interface>
   7.110 \ No newline at end of file
     8.1 --- a/gtk-gui/objects.xml	Mon Oct 17 20:53:07 2011 +0100
     8.2 +++ b/gtk-gui/objects.xml	Tue Oct 18 21:03:35 2011 +0100
     8.3 @@ -11,4 +11,8 @@
     8.4      <itemgroups />
     8.5      <signals />
     8.6    </object>
     8.7 +  <object type="IBBoard.WarFoundry.GUI.GTK.ValidationFailureWidget" palette-category="General" allow-children="false" base-type="Gtk.Bin">
     8.8 +    <itemgroups />
     8.9 +    <signals />
    8.10 +  </object>
    8.11  </objects>
    8.12 \ No newline at end of file