view FrmEditArmy.cs @ 139:d4b726cec12c

Fixes #326: Make army names and sizes modifiable after creation * Only invoke command on change * Make use of new "generate default name" function for consistency * Commit missed auto-generated code file
author IBBoard <dev@ibboard.co.uk>
date Wed, 12 Oct 2011 20:36:02 +0100
parents 33962c2ef550
children
line wrap: on
line source

// This file (FrmEditArmy.cs) is a part of the IBBoard.WarFoundry.GUI.GTK project and is copyright 2011 IBBoard
// 
// 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.
using System;
using IBBoard.WarFoundry.API.Objects;
using IBBoard.Commands;
using IBBoard.WarFoundry.API.Commands;

namespace IBBoard.WarFoundry.GUI.GTK
{
	public partial class FrmEditArmy : IBBoard.GtkSharp.Translatable.TranslatableDialog
	{
		private Army army;
		private CommandStack stack;

		public FrmEditArmy(CommandStack cmdStack, Army toEdit)
		{
			stack = cmdStack;
			army = toEdit;
			this.Build();
			txtArmyName.Text = army.Name;
			sbPointsValue.Value = army.MaxPoints;
			Translate();
		}

		protected void OnButtonOkClicked (object sender, System.EventArgs e)
		{
			if (IsChanged())
			{
				DoUpdate();
			}
			Respond(Gtk.ResponseType.Ok);
		}

		private bool IsChanged()
		{
			string trimmedName = txtArmyName.Text.Trim();
			return army.MaxPoints != sbPointsValue.Value || army.Name != trimmedName;
		}

		private void DoUpdate()
		{
			EditArmyCommand command = new EditArmyCommand(army);
			command.NewName = txtArmyName.Text;
			command.NewSize = (int)sbPointsValue.Value;
			stack.Execute(command);
		}

		protected void OnButtonCancelClicked (object sender, System.EventArgs e)
		{
			Respond(Gtk.ResponseType.Cancel);
		}
	}
}