changeset 141:1ce4fe9ae3c1

Re #344: Show unit requirement failures * Add an initial way to access requirement failures after adding units
author IBBoard <dev@ibboard.co.uk>
date Mon, 17 Oct 2011 20:53:07 +0100
parents 2b9fabd65309
children f23e5b40ca9d
files FrmMainWindow.cs gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmMainWindow.cs gtk-gui/gui.stetic
diffstat 3 files changed, 79 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/FrmMainWindow.cs	Sat Oct 15 16:07:13 2011 +0100
+++ b/FrmMainWindow.cs	Mon Oct 17 20:53:07 2011 +0100
@@ -30,11 +30,13 @@
 using WFObjects = IBBoard.WarFoundry.API.Objects;
 using IBBoard.WarFoundry.API.Savers.Xml;
 using IBBoard.WarFoundry.API.Objects.Requirement;
+using System.Text;
 
 namespace IBBoard.WarFoundry.GUI.GTK
 {
 	public partial class FrmMainWindow: TranslatableWindowWithActions
 	{
+		private static readonly string VALIDATION_RESULTS_KEY = "WarFoundryValidationFailureMessages";
 		private static readonly string AppTitle = "WarFoundry";
 		private const int CATEGORY_BUTTON_SEPARATOR_INDEX = 6;
 		private Preferences preferences;
@@ -158,24 +160,29 @@
 			WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory());
 			WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished;
 			WarFoundrySaver.SetFileSaver(new WarFoundryXmlFileSaver());
+			SetStatusBarText();
 
+			LoadFilesFromArgs(args);
+		}
+
+		private void LoadFilesFromArgs(string[] args)
+		{
 			logger.Debug("Initialising complete - seeing if we can load default army or system");
-
 			if (args.Length == 1)
 			{
 				logger.Debug("Attempting to load from file");
 				FileInfo file = new FileInfo(args[0]);
-
+			
 				try
 				{
 					ICollection<IWarFoundryObject> objects = WarFoundryLoader.GetDefault().LoadFile(file);
-
+			
 					if (objects.Count == 1)
 					{
 						List<IWarFoundryObject> objectList = new List<IWarFoundryObject>();
 						objectList.AddRange(objects);
 						IWarFoundryObject loadedObject = objectList[0];
-
+			
 						if (loadedObject is Army)
 						{
 							WarFoundryCore.CurrentArmy = (Army)loadedObject;
@@ -188,7 +195,7 @@
 								WarFoundryCore.CurrentGameSystem = (GameSystem)loadedObject;
 								logger.InfoFormat("Loaded game system from {0}", file.FullName);
 							}
-
+			
 						}
 					}
 				}
@@ -201,12 +208,12 @@
 			else
 			{
 				string gameSystemID = Preferences.GetStringProperty("currSystem");
-
+			
 				if (gameSystemID != null && !"".Equals(gameSystemID))
 				{
 					logger.Debug("Attempting to load current game system from properties");
 					GameSystem sys = WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID);
-
+			
 					if (sys != null)
 					{
 						WarFoundryCore.CurrentGameSystem = sys;
@@ -675,7 +682,7 @@
 			else
 			{
 				statusbar.Push(1, "");
-				lblValidationWarning.Text = "";
+				SetBlankValidationText();
 			}
 		}
 
@@ -696,7 +703,7 @@
 			}
 			else
 			{
-				lblValidationWarning.Text = "";
+				SetBlankValidationText();
 			}
 		}
 
@@ -706,6 +713,7 @@
 			Validation result = RequirementHandler.ValidateArmy(WarFoundryCore.CurrentArmy, out failureMessages);
 			string pluralHack = (failureMessages.Count == 1 ? "" : "s");
 			lblValidationWarning.Text = String.Format("{0} validation warning{1}", failureMessages.Count, pluralHack);
+			lblValidationWarning.Data[VALIDATION_RESULTS_KEY] = failureMessages;
 			
 			if (Validates.AsOkay(result))
 			{
@@ -719,6 +727,13 @@
 			}
 		}
 
+		private void SetBlankValidationText()
+		{
+			lblValidationWarning.Text = "";
+			lblValidationWarning.Data[VALIDATION_RESULTS_KEY] = new string[0];
+			lblValidationWarning.ModifyFg(StateType.Normal, Gdk.Color.Zero);
+		}
+
 		private void commandStack_CommandStackUpdated()
 		{
 			undoMenuButton.Sensitive = commandStack.CanUndo();
@@ -1255,5 +1270,31 @@
 			form.Hide();
 			form.Dispose();
 		}
+
+		protected void OnLblValidationWarningButtonReleaseEvent(object o, Gtk.ButtonReleaseEventArgs args)
+		{
+			if (args.Event.Button != (uint)MouseButton.Left)
+			{
+				return;
+			}
+
+			ICollection<string> failureMessages = lblValidationWarning.Data[VALIDATION_RESULTS_KEY] as ICollection<string>;
+
+			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";
+				dialog.Run();
+				dialog.Hide();
+				dialog.Dispose();
+			}
+		}
 	}
 }
--- a/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmMainWindow.cs	Sat Oct 15 16:07:13 2011 +0100
+++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmMainWindow.cs	Mon Oct 17 20:53:07 2011 +0100
@@ -35,6 +35,7 @@
 		private global::Gtk.MenuBar menubar1;
 		private global::Gtk.Toolbar toolbar;
 		private global::Gtk.Statusbar statusbar;
+		private global::Gtk.EventBox validationEventbox;
 		private global::Gtk.Label lblValidationWarning;
 		private global::Gtk.HPaned mainContent;
 		private global::Gtk.TreeView treeUnits;
@@ -164,20 +165,23 @@
 			this.statusbar.Spacing = 6;
 			this.statusbar.BorderWidth = ((uint)(1));
 			// Container child statusbar.Gtk.Box+BoxChild
+			this.validationEventbox = new global::Gtk.EventBox ();
+			this.validationEventbox.Name = "validationEventbox";
+			// Container child validationEventbox.Gtk.Container+ContainerChild
 			this.lblValidationWarning = new global::Gtk.Label ();
 			this.lblValidationWarning.Name = "lblValidationWarning";
-			this.statusbar.Add (this.lblValidationWarning);
-			global::Gtk.Box.BoxChild w4 = ((global::Gtk.Box.BoxChild)(this.statusbar [this.lblValidationWarning]));
-			w4.PackType = ((global::Gtk.PackType)(1));
-			w4.Position = 1;
-			w4.Expand = false;
-			w4.Fill = false;
-			this.vbox1.Add (this.statusbar);
-			global::Gtk.Box.BoxChild w5 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.statusbar]));
-			w5.PackType = ((global::Gtk.PackType)(1));
-			w5.Position = 2;
+			this.validationEventbox.Add (this.lblValidationWarning);
+			this.statusbar.Add (this.validationEventbox);
+			global::Gtk.Box.BoxChild w5 = ((global::Gtk.Box.BoxChild)(this.statusbar [this.validationEventbox]));
+			w5.Position = 1;
 			w5.Expand = false;
 			w5.Fill = false;
+			this.vbox1.Add (this.statusbar);
+			global::Gtk.Box.BoxChild w6 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.statusbar]));
+			w6.PackType = ((global::Gtk.PackType)(1));
+			w6.Position = 2;
+			w6.Expand = false;
+			w6.Fill = false;
 			// Container child vbox1.Gtk.Box+BoxChild
 			this.mainContent = new global::Gtk.HPaned ();
 			this.mainContent.CanFocus = true;
@@ -188,8 +192,8 @@
 			this.treeUnits.CanFocus = true;
 			this.treeUnits.Name = "treeUnits";
 			this.mainContent.Add (this.treeUnits);
-			global::Gtk.Paned.PanedChild w6 = ((global::Gtk.Paned.PanedChild)(this.mainContent [this.treeUnits]));
-			w6.Resize = false;
+			global::Gtk.Paned.PanedChild w7 = ((global::Gtk.Paned.PanedChild)(this.mainContent [this.treeUnits]));
+			w7.Resize = false;
 			// Container child mainContent.Gtk.Paned+PanedChild
 			this.unitsNotebook = new global::Gtk.Notebook ();
 			this.unitsNotebook.CanFocus = true;
@@ -197,12 +201,12 @@
 			this.unitsNotebook.CurrentPage = -1;
 			this.unitsNotebook.Scrollable = true;
 			this.mainContent.Add (this.unitsNotebook);
-			global::Gtk.Paned.PanedChild w7 = ((global::Gtk.Paned.PanedChild)(this.mainContent [this.unitsNotebook]));
-			w7.Shrink = false;
+			global::Gtk.Paned.PanedChild w8 = ((global::Gtk.Paned.PanedChild)(this.mainContent [this.unitsNotebook]));
+			w8.Shrink = false;
 			this.vbox1.Add (this.mainContent);
-			global::Gtk.Box.BoxChild w8 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.mainContent]));
-			w8.PackType = ((global::Gtk.PackType)(1));
-			w8.Position = 3;
+			global::Gtk.Box.BoxChild w9 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.mainContent]));
+			w9.PackType = ((global::Gtk.PackType)(1));
+			w9.Position = 3;
 			this.Add (this.vbox1);
 			if ((this.Child != null)) {
 				this.Child.ShowAll ();
@@ -232,6 +236,7 @@
 			this.treeUnits.PopupMenu += new global::Gtk.PopupMenuHandler (this.OnTreeUnitsPopupMenu);
 			this.treeUnits.ButtonPressEvent += new global::Gtk.ButtonPressEventHandler (this.UnitTreeButtonPressed);
 			this.unitsNotebook.Removed += new global::Gtk.RemovedHandler (this.NotebookPageRemoved);
+			this.validationEventbox.ButtonReleaseEvent += new global::Gtk.ButtonReleaseEventHandler (this.OnLblValidationWarningButtonReleaseEvent);
 		}
 	}
 }
--- a/gtk-gui/gui.stetic	Sat Oct 15 16:07:13 2011 +0100
+++ b/gtk-gui/gui.stetic	Mon Oct 17 20:53:07 2011 +0100
@@ -256,11 +256,16 @@
             <property name="Spacing">6</property>
             <property name="BorderWidth">1</property>
             <child>
-              <widget class="Gtk.Label" id="lblValidationWarning">
+              <widget class="Gtk.EventBox" id="validationEventbox">
                 <property name="MemberName" />
+                <signal name="ButtonReleaseEvent" handler="OnLblValidationWarningButtonReleaseEvent" />
+                <child>
+                  <widget class="Gtk.Label" id="lblValidationWarning">
+                    <property name="MemberName" />
+                  </widget>
+                </child>
               </widget>
               <packing>
-                <property name="PackType">End</property>
                 <property name="Position">1</property>
                 <property name="AutoSize">True</property>
                 <property name="Expand">False</property>