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 diff
     1.1 --- a/FrmMainWindow.cs	Sat Oct 15 16:07:13 2011 +0100
     1.2 +++ b/FrmMainWindow.cs	Mon Oct 17 20:53:07 2011 +0100
     1.3 @@ -30,11 +30,13 @@
     1.4  using WFObjects = IBBoard.WarFoundry.API.Objects;
     1.5  using IBBoard.WarFoundry.API.Savers.Xml;
     1.6  using IBBoard.WarFoundry.API.Objects.Requirement;
     1.7 +using System.Text;
     1.8  
     1.9  namespace IBBoard.WarFoundry.GUI.GTK
    1.10  {
    1.11  	public partial class FrmMainWindow: TranslatableWindowWithActions
    1.12  	{
    1.13 +		private static readonly string VALIDATION_RESULTS_KEY = "WarFoundryValidationFailureMessages";
    1.14  		private static readonly string AppTitle = "WarFoundry";
    1.15  		private const int CATEGORY_BUTTON_SEPARATOR_INDEX = 6;
    1.16  		private Preferences preferences;
    1.17 @@ -158,24 +160,29 @@
    1.18  			WarFoundryLoader.GetDefault().RegisterFactory(WarFoundryXmlFactory.GetFactory());
    1.19  			WarFoundryLoader.GetDefault().FileLoadingFinished += FileLoadingFinished;
    1.20  			WarFoundrySaver.SetFileSaver(new WarFoundryXmlFileSaver());
    1.21 +			SetStatusBarText();
    1.22  
    1.23 +			LoadFilesFromArgs(args);
    1.24 +		}
    1.25 +
    1.26 +		private void LoadFilesFromArgs(string[] args)
    1.27 +		{
    1.28  			logger.Debug("Initialising complete - seeing if we can load default army or system");
    1.29 -
    1.30  			if (args.Length == 1)
    1.31  			{
    1.32  				logger.Debug("Attempting to load from file");
    1.33  				FileInfo file = new FileInfo(args[0]);
    1.34 -
    1.35 +			
    1.36  				try
    1.37  				{
    1.38  					ICollection<IWarFoundryObject> objects = WarFoundryLoader.GetDefault().LoadFile(file);
    1.39 -
    1.40 +			
    1.41  					if (objects.Count == 1)
    1.42  					{
    1.43  						List<IWarFoundryObject> objectList = new List<IWarFoundryObject>();
    1.44  						objectList.AddRange(objects);
    1.45  						IWarFoundryObject loadedObject = objectList[0];
    1.46 -
    1.47 +			
    1.48  						if (loadedObject is Army)
    1.49  						{
    1.50  							WarFoundryCore.CurrentArmy = (Army)loadedObject;
    1.51 @@ -188,7 +195,7 @@
    1.52  								WarFoundryCore.CurrentGameSystem = (GameSystem)loadedObject;
    1.53  								logger.InfoFormat("Loaded game system from {0}", file.FullName);
    1.54  							}
    1.55 -
    1.56 +			
    1.57  						}
    1.58  					}
    1.59  				}
    1.60 @@ -201,12 +208,12 @@
    1.61  			else
    1.62  			{
    1.63  				string gameSystemID = Preferences.GetStringProperty("currSystem");
    1.64 -
    1.65 +			
    1.66  				if (gameSystemID != null && !"".Equals(gameSystemID))
    1.67  				{
    1.68  					logger.Debug("Attempting to load current game system from properties");
    1.69  					GameSystem sys = WarFoundryLoader.GetDefault().GetGameSystem(gameSystemID);
    1.70 -
    1.71 +			
    1.72  					if (sys != null)
    1.73  					{
    1.74  						WarFoundryCore.CurrentGameSystem = sys;
    1.75 @@ -675,7 +682,7 @@
    1.76  			else
    1.77  			{
    1.78  				statusbar.Push(1, "");
    1.79 -				lblValidationWarning.Text = "";
    1.80 +				SetBlankValidationText();
    1.81  			}
    1.82  		}
    1.83  
    1.84 @@ -696,7 +703,7 @@
    1.85  			}
    1.86  			else
    1.87  			{
    1.88 -				lblValidationWarning.Text = "";
    1.89 +				SetBlankValidationText();
    1.90  			}
    1.91  		}
    1.92  
    1.93 @@ -706,6 +713,7 @@
    1.94  			Validation result = RequirementHandler.ValidateArmy(WarFoundryCore.CurrentArmy, out failureMessages);
    1.95  			string pluralHack = (failureMessages.Count == 1 ? "" : "s");
    1.96  			lblValidationWarning.Text = String.Format("{0} validation warning{1}", failureMessages.Count, pluralHack);
    1.97 +			lblValidationWarning.Data[VALIDATION_RESULTS_KEY] = failureMessages;
    1.98  			
    1.99  			if (Validates.AsOkay(result))
   1.100  			{
   1.101 @@ -719,6 +727,13 @@
   1.102  			}
   1.103  		}
   1.104  
   1.105 +		private void SetBlankValidationText()
   1.106 +		{
   1.107 +			lblValidationWarning.Text = "";
   1.108 +			lblValidationWarning.Data[VALIDATION_RESULTS_KEY] = new string[0];
   1.109 +			lblValidationWarning.ModifyFg(StateType.Normal, Gdk.Color.Zero);
   1.110 +		}
   1.111 +
   1.112  		private void commandStack_CommandStackUpdated()
   1.113  		{
   1.114  			undoMenuButton.Sensitive = commandStack.CanUndo();
   1.115 @@ -1255,5 +1270,31 @@
   1.116  			form.Hide();
   1.117  			form.Dispose();
   1.118  		}
   1.119 +
   1.120 +		protected void OnLblValidationWarningButtonReleaseEvent(object o, Gtk.ButtonReleaseEventArgs args)
   1.121 +		{
   1.122 +			if (args.Event.Button != (uint)MouseButton.Left)
   1.123 +			{
   1.124 +				return;
   1.125 +			}
   1.126 +
   1.127 +			ICollection<string> failureMessages = lblValidationWarning.Data[VALIDATION_RESULTS_KEY] as ICollection<string>;
   1.128 +
   1.129 +			if (failureMessages != null && failureMessages.Count > 0)
   1.130 +			{
   1.131 +				StringBuilder sb = new StringBuilder();
   1.132 +
   1.133 +				foreach (string msg in failureMessages)
   1.134 +				{
   1.135 +					sb.AppendLine(msg);
   1.136 +				}
   1.137 +
   1.138 +				MessageDialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Warning, ButtonsType.Ok, false, sb.ToString());
   1.139 +				dialog.Title = "Validation errors";
   1.140 +				dialog.Run();
   1.141 +				dialog.Hide();
   1.142 +				dialog.Dispose();
   1.143 +			}
   1.144 +		}
   1.145  	}
   1.146  }
     2.1 --- a/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmMainWindow.cs	Sat Oct 15 16:07:13 2011 +0100
     2.2 +++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmMainWindow.cs	Mon Oct 17 20:53:07 2011 +0100
     2.3 @@ -35,6 +35,7 @@
     2.4  		private global::Gtk.MenuBar menubar1;
     2.5  		private global::Gtk.Toolbar toolbar;
     2.6  		private global::Gtk.Statusbar statusbar;
     2.7 +		private global::Gtk.EventBox validationEventbox;
     2.8  		private global::Gtk.Label lblValidationWarning;
     2.9  		private global::Gtk.HPaned mainContent;
    2.10  		private global::Gtk.TreeView treeUnits;
    2.11 @@ -164,20 +165,23 @@
    2.12  			this.statusbar.Spacing = 6;
    2.13  			this.statusbar.BorderWidth = ((uint)(1));
    2.14  			// Container child statusbar.Gtk.Box+BoxChild
    2.15 +			this.validationEventbox = new global::Gtk.EventBox ();
    2.16 +			this.validationEventbox.Name = "validationEventbox";
    2.17 +			// Container child validationEventbox.Gtk.Container+ContainerChild
    2.18  			this.lblValidationWarning = new global::Gtk.Label ();
    2.19  			this.lblValidationWarning.Name = "lblValidationWarning";
    2.20 -			this.statusbar.Add (this.lblValidationWarning);
    2.21 -			global::Gtk.Box.BoxChild w4 = ((global::Gtk.Box.BoxChild)(this.statusbar [this.lblValidationWarning]));
    2.22 -			w4.PackType = ((global::Gtk.PackType)(1));
    2.23 -			w4.Position = 1;
    2.24 -			w4.Expand = false;
    2.25 -			w4.Fill = false;
    2.26 -			this.vbox1.Add (this.statusbar);
    2.27 -			global::Gtk.Box.BoxChild w5 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.statusbar]));
    2.28 -			w5.PackType = ((global::Gtk.PackType)(1));
    2.29 -			w5.Position = 2;
    2.30 +			this.validationEventbox.Add (this.lblValidationWarning);
    2.31 +			this.statusbar.Add (this.validationEventbox);
    2.32 +			global::Gtk.Box.BoxChild w5 = ((global::Gtk.Box.BoxChild)(this.statusbar [this.validationEventbox]));
    2.33 +			w5.Position = 1;
    2.34  			w5.Expand = false;
    2.35  			w5.Fill = false;
    2.36 +			this.vbox1.Add (this.statusbar);
    2.37 +			global::Gtk.Box.BoxChild w6 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.statusbar]));
    2.38 +			w6.PackType = ((global::Gtk.PackType)(1));
    2.39 +			w6.Position = 2;
    2.40 +			w6.Expand = false;
    2.41 +			w6.Fill = false;
    2.42  			// Container child vbox1.Gtk.Box+BoxChild
    2.43  			this.mainContent = new global::Gtk.HPaned ();
    2.44  			this.mainContent.CanFocus = true;
    2.45 @@ -188,8 +192,8 @@
    2.46  			this.treeUnits.CanFocus = true;
    2.47  			this.treeUnits.Name = "treeUnits";
    2.48  			this.mainContent.Add (this.treeUnits);
    2.49 -			global::Gtk.Paned.PanedChild w6 = ((global::Gtk.Paned.PanedChild)(this.mainContent [this.treeUnits]));
    2.50 -			w6.Resize = false;
    2.51 +			global::Gtk.Paned.PanedChild w7 = ((global::Gtk.Paned.PanedChild)(this.mainContent [this.treeUnits]));
    2.52 +			w7.Resize = false;
    2.53  			// Container child mainContent.Gtk.Paned+PanedChild
    2.54  			this.unitsNotebook = new global::Gtk.Notebook ();
    2.55  			this.unitsNotebook.CanFocus = true;
    2.56 @@ -197,12 +201,12 @@
    2.57  			this.unitsNotebook.CurrentPage = -1;
    2.58  			this.unitsNotebook.Scrollable = true;
    2.59  			this.mainContent.Add (this.unitsNotebook);
    2.60 -			global::Gtk.Paned.PanedChild w7 = ((global::Gtk.Paned.PanedChild)(this.mainContent [this.unitsNotebook]));
    2.61 -			w7.Shrink = false;
    2.62 +			global::Gtk.Paned.PanedChild w8 = ((global::Gtk.Paned.PanedChild)(this.mainContent [this.unitsNotebook]));
    2.63 +			w8.Shrink = false;
    2.64  			this.vbox1.Add (this.mainContent);
    2.65 -			global::Gtk.Box.BoxChild w8 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.mainContent]));
    2.66 -			w8.PackType = ((global::Gtk.PackType)(1));
    2.67 -			w8.Position = 3;
    2.68 +			global::Gtk.Box.BoxChild w9 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.mainContent]));
    2.69 +			w9.PackType = ((global::Gtk.PackType)(1));
    2.70 +			w9.Position = 3;
    2.71  			this.Add (this.vbox1);
    2.72  			if ((this.Child != null)) {
    2.73  				this.Child.ShowAll ();
    2.74 @@ -232,6 +236,7 @@
    2.75  			this.treeUnits.PopupMenu += new global::Gtk.PopupMenuHandler (this.OnTreeUnitsPopupMenu);
    2.76  			this.treeUnits.ButtonPressEvent += new global::Gtk.ButtonPressEventHandler (this.UnitTreeButtonPressed);
    2.77  			this.unitsNotebook.Removed += new global::Gtk.RemovedHandler (this.NotebookPageRemoved);
    2.78 +			this.validationEventbox.ButtonReleaseEvent += new global::Gtk.ButtonReleaseEventHandler (this.OnLblValidationWarningButtonReleaseEvent);
    2.79  		}
    2.80  	}
    2.81  }
     3.1 --- a/gtk-gui/gui.stetic	Sat Oct 15 16:07:13 2011 +0100
     3.2 +++ b/gtk-gui/gui.stetic	Mon Oct 17 20:53:07 2011 +0100
     3.3 @@ -256,11 +256,16 @@
     3.4              <property name="Spacing">6</property>
     3.5              <property name="BorderWidth">1</property>
     3.6              <child>
     3.7 -              <widget class="Gtk.Label" id="lblValidationWarning">
     3.8 +              <widget class="Gtk.EventBox" id="validationEventbox">
     3.9                  <property name="MemberName" />
    3.10 +                <signal name="ButtonReleaseEvent" handler="OnLblValidationWarningButtonReleaseEvent" />
    3.11 +                <child>
    3.12 +                  <widget class="Gtk.Label" id="lblValidationWarning">
    3.13 +                    <property name="MemberName" />
    3.14 +                  </widget>
    3.15 +                </child>
    3.16                </widget>
    3.17                <packing>
    3.18 -                <property name="PackType">End</property>
    3.19                  <property name="Position">1</property>
    3.20                  <property name="AutoSize">True</property>
    3.21                  <property name="Expand">False</property>