diff FrmEditArmy.cs @ 225:5233147ca7e4

Re #101: Make army names and sizes modifiable after creation * Add form for editing name and size * Add edit options from army tree * Add edit options from Edit menu
author IBBoard <dev@ibboard.co.uk>
date Mon, 29 Aug 2011 20:06:54 +0100
parents
children 4ada3252d1ea
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FrmEditArmy.cs	Mon Aug 29 20:06:54 2011 +0100
@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Text;
+using System.Windows.Forms;
+using IBBoard.Commands;
+using IBBoard.WarFoundry.API.Commands;
+using IBBoard.WarFoundry.API.Objects;
+
+namespace IBBoard.WarFoundry.GUI.WinForms
+{
+	public partial class FrmEditArmy : Form
+	{
+		private Army army;
+		private CommandStack stack;
+
+		public FrmEditArmy(CommandStack cmdStack, Army toEdit)
+		{
+			army = toEdit;
+			stack = cmdStack;
+			InitializeComponent();
+			txtArmyName.Text = army.Name;
+			armySize.Value = army.MaxPoints;
+		}
+
+		private void bttnOkay_Click(object sender, EventArgs e)
+		{
+			EditArmyCommand command = new EditArmyCommand(army);
+			command.NewName = txtArmyName.Text;
+			command.NewSize = (int)armySize.Value;
+			stack.Execute(command);
+			DialogResult = DialogResult.OK;
+			Close();
+		}
+
+		private void bttnCancel_Click(object sender, EventArgs e)
+		{
+			Close();
+		}
+
+		private void armySize_ValueChanged(object sender, EventArgs e)
+		{
+			SetOkayEnabled();
+		}
+
+		private void SetOkayEnabled()
+		{
+			string trimmedName = txtArmyName.Text.Trim();
+			bttnOkay.Enabled = ((army.MaxPoints != armySize.Value || army.Name != trimmedName) && trimmedName != "");
+		}
+
+		private void txtArmyName_TextChanged(object sender, EventArgs e)
+		{
+			SetOkayEnabled();
+		}
+
+		private void armySize_KeyUp(object sender, KeyEventArgs e)
+		{
+			SetOkayEnabled();
+		}
+	}
+}