changeset 54:f9f6e9db5350

Re #60: Add UI to add/remove/edit weapons in GTK * Add selection change notification from equipment list * Make ShowControl method return a boolean to say what the user did with it * Re-implement ShowControl to use Run() instead of ShowNow() so we can get a response result
author IBBoard <dev@ibboard.co.uk>
date Wed, 25 Aug 2010 16:01:12 +0000
parents 28b242612ad7
children eb7db8495bb5
files FrmAddEquipment.cs UIControl/Interfaces/IAddEquipmentUI.cs Util/GtkWarFoundryUtil.cs gtk-gui/gui.stetic
diffstat 4 files changed, 20 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/FrmAddEquipment.cs	Wed Aug 25 15:21:56 2010 +0000
+++ b/FrmAddEquipment.cs	Wed Aug 25 16:01:12 2010 +0000
@@ -6,14 +6,17 @@
 using IBBoard.WarFoundry.API.Objects;
 using Gtk;
 using IBBoard.WarFoundry.GUI.GTK.Util;
+using IBBoard.GtkSharp;
 namespace IBBoard.WarFoundry.GUI.GTK
 {
 	public partial class FrmAddEquipment : Gtk.Dialog, IAddEquipmentUI
 	{
+		public event SingleArgMethodInvoker<UnitEquipmentItem> UnitEquipmentItemChoiceChanged;
+		
 		public FrmAddEquipment()
 		{
 			this.Build();
-			
+			lstEquipment.Selection.Changed += OnSelectionChanged;
 			TreeViewColumn equipColumn = new TreeViewColumn();
 			equipColumn.Title = "Equipment";
 			CellRendererText equipCell = new CellRendererText();
@@ -21,8 +24,14 @@
 			equipColumn.SetCellDataFunc(equipCell, GtkWarFoundryUtil.RenderWarFoundryObjectName);
 			lstEquipment.AppendColumn(equipColumn);
 		}
-
-		public event SingleArgMethodInvoker<UnitEquipmentItem> UnitEquipmentItemChoiceChanged;
+		
+		protected virtual void OnSelectionChanged(object o, EventArgs e)
+		{
+			if (UnitEquipmentItemChoiceChanged!=null)
+			{
+				UnitEquipmentItemChoiceChanged((UnitEquipmentItem)TreeUtils.GetSelectedItem(lstEquipment));
+			}
+		}
 
 		public void SetUnitEquipmentItems(UnitEquipmentItem[] items)
 		{
@@ -46,17 +55,15 @@
 			
 		}
 
-		public void ShowControl()
+		public bool ShowControl()
 		{
-			ShowNow();
+			return Run() == (int)ResponseType.Ok;
 		}
 		
 		protected virtual void CancelButtonClicked (object sender, System.EventArgs e)
 		{
 			Respond(ResponseType.Cancel);
-		}
-		
-		
+		}		
 	}
 }
 
--- a/UIControl/Interfaces/IAddEquipmentUI.cs	Wed Aug 25 15:21:56 2010 +0000
+++ b/UIControl/Interfaces/IAddEquipmentUI.cs	Wed Aug 25 16:01:12 2010 +0000
@@ -15,8 +15,6 @@
 		/// </summary>
 		event SingleArgMethodInvoker<UnitEquipmentItem> UnitEquipmentItemChoiceChanged;
 		
-		
-		
 		/// <summary>
 		/// Sets the equipment items that should be displayed on the form
 		/// </summary>
@@ -56,7 +54,10 @@
 		/// <summary>
 		/// Shows the control and awaits a user action (close or okay)
 		/// </summary>
-		void ShowControl();
+		/// <returns>
+		/// <code>true</code> if the control was closed with "Okay", else <code>false</code>
+		/// </returns>
+		bool ShowControl();
 	}
 }
 
--- a/Util/GtkWarFoundryUtil.cs	Wed Aug 25 15:21:56 2010 +0000
+++ b/Util/GtkWarFoundryUtil.cs	Wed Aug 25 16:01:12 2010 +0000
@@ -14,5 +14,4 @@
 			(cell as CellRendererText).Text = equip.Name;
 		}
 	}
-}
-
+}
\ No newline at end of file
--- a/gtk-gui/gui.stetic	Wed Aug 25 15:21:56 2010 +0000
+++ b/gtk-gui/gui.stetic	Wed Aug 25 16:01:12 2010 +0000
@@ -1066,7 +1066,6 @@
                         <property name="MemberName" />
                         <property name="CanFocus">True</property>
                         <property name="Label" translatable="yes" />
-                        <property name="Active">True</property>
                         <property name="DrawIndicator">True</property>
                         <property name="HasLabel">True</property>
                         <property name="UseUnderline">True</property>