changeset 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 2b9fabd65309
files FrmEditArmy.cs FrmNewArmy.cs gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmMainWindow.cs
diffstat 3 files changed, 24 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/FrmEditArmy.cs	Tue Oct 11 21:05:10 2011 +0100
+++ b/FrmEditArmy.cs	Wed Oct 12 20:36:02 2011 +0100
@@ -23,6 +23,21 @@
 			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);
@@ -31,12 +46,6 @@
 			stack.Execute(command);
 		}
 
-		protected void OnButtonOkClicked (object sender, System.EventArgs e)
-		{
-			DoUpdate();
-			Respond(Gtk.ResponseType.Ok);
-		}
-
 		protected void OnButtonCancelClicked (object sender, System.EventArgs e)
 		{
 			Respond(Gtk.ResponseType.Cancel);
--- a/FrmNewArmy.cs	Tue Oct 11 21:05:10 2011 +0100
+++ b/FrmNewArmy.cs	Wed Oct 12 20:36:02 2011 +0100
@@ -160,7 +160,8 @@
 				if (lstRaces.Selection.CountSelectedRows() == 1)
 		        {
 	                GameSystem currSystem = SelectedGameSystem;
-	                txtArmyName.Text = String.Format(GetSelectedRace().ArmyDefaultName, Translation.GetTranslation("armySizePts", "{0}{1}", sbPointsValue.Value, currSystem.SystemPtsAbbrevSingle));
+	                int points = (int)sbPointsValue.Value;
+					txtArmyName.Text = Army.GenerateDefaultName(GetSelectedRace(), points, currSystem.GetPointsAbbrev(points));
 				}
 				else {
 					txtArmyName.Text = "";
--- a/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmMainWindow.cs	Tue Oct 11 21:05:10 2011 +0100
+++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmMainWindow.cs	Wed Oct 12 20:36:02 2011 +0100
@@ -30,6 +30,7 @@
 		private global::Gtk.Action miExportArmyAsBasicHTML;
 		private global::Gtk.Action miPreferences;
 		private global::Gtk.Action miExportArmyAsTransformedXml;
+		private global::Gtk.Action miEditArmy;
 		private global::Gtk.VBox vbox1;
 		private global::Gtk.MenuBar menubar1;
 		private global::Gtk.Toolbar toolbar;
@@ -122,6 +123,10 @@
 			this.miExportArmyAsTransformedXml = new global::Gtk.Action ("miExportArmyAsTransformedXml", global::Mono.Unix.Catalog.GetString ("transformed xml"), null, null);
 			this.miExportArmyAsTransformedXml.ShortLabel = global::Mono.Unix.Catalog.GetString ("transformed xml");
 			w1.Add (this.miExportArmyAsTransformedXml, null);
+			this.miEditArmy = new global::Gtk.Action ("miEditArmy", global::Mono.Unix.Catalog.GetString ("_edit army"), null, "gtk-edit");
+			this.miEditArmy.Sensitive = false;
+			this.miEditArmy.ShortLabel = global::Mono.Unix.Catalog.GetString ("_edit army");
+			w1.Add (this.miEditArmy, null);
 			this.UIManager.InsertActionGroup (w1, 0);
 			this.AddAccelGroup (this.UIManager.AccelGroup);
 			this.Name = "IBBoard.WarFoundry.GUI.GTK.FrmMainWindow";
@@ -131,7 +136,7 @@
 			this.vbox1 = new global::Gtk.VBox ();
 			this.vbox1.Name = "vbox1";
 			// Container child vbox1.Gtk.Box+BoxChild
-			this.UIManager.AddUiFromString ("<ui><menubar name='menubar1'><menu name='menuFile' action='menuFile'><menuitem name='miNewArmy' action='miNewArmy'/><menuitem name='miOpenArmy' action='miOpenArmy'/><menuitem name='miSaveArmy' action='miSaveArmy'/><menuitem name='miSaveArmyAs' action='miSaveArmyAs'/><menu name='miExportArmyAs' action='miExportArmyAs'><menuitem name='miExportArmyAsBasicHTML' action='miExportArmyAsBasicHTML'/><menuitem name='miExportArmyAsTransformedXml' action='miExportArmyAsTransformedXml'/></menu><menuitem name='miCloseArmy' action='miCloseArmy'/><separator/><menuitem name='miReloadFiles' action='miReloadFiles'/><separator/><menuitem name='miExit' action='miExit'/></menu><menu name='menuEdit' action='menuEdit'><menuitem name='miUndo' action='miUndo'/><menuitem name='miRedo' action='miRedo'/><separator/><menuitem name='miPreferences' action='miPreferences'/></menu><menu name='menuHelp' action='menuHelp'><menuitem name='miAbout' action='miAbout'/></menu></menubar></ui>");
+			this.UIManager.AddUiFromString ("<ui><menubar name='menubar1'><menu name='menuFile' action='menuFile'><menuitem name='miNewArmy' action='miNewArmy'/><menuitem name='miOpenArmy' action='miOpenArmy'/><menuitem name='miSaveArmy' action='miSaveArmy'/><menuitem name='miSaveArmyAs' action='miSaveArmyAs'/><menu name='miExportArmyAs' action='miExportArmyAs'><menuitem name='miExportArmyAsBasicHTML' action='miExportArmyAsBasicHTML'/><menuitem name='miExportArmyAsTransformedXml' action='miExportArmyAsTransformedXml'/></menu><menuitem name='miCloseArmy' action='miCloseArmy'/><separator/><menuitem name='miReloadFiles' action='miReloadFiles'/><separator/><menuitem name='miExit' action='miExit'/></menu><menu name='menuEdit' action='menuEdit'><menuitem name='miUndo' action='miUndo'/><menuitem name='miRedo' action='miRedo'/><separator/><menuitem name='miEditArmy' action='miEditArmy'/><separator/><menuitem name='miPreferences' action='miPreferences'/></menu><menu name='menuHelp' action='menuHelp'><menuitem name='miAbout' action='miAbout'/></menu></menubar></ui>");
 			this.menubar1 = ((global::Gtk.MenuBar)(this.UIManager.GetWidget ("/menubar1")));
 			this.menubar1.Name = "menubar1";
 			this.vbox1.Add (this.menubar1);
@@ -217,6 +222,7 @@
 			this.miExportArmyAsBasicHTML.Activated += new global::System.EventHandler (this.OnMiExportAsBasicHtmlActivated);
 			this.miPreferences.Activated += new global::System.EventHandler (this.miPreferencesClicked);
 			this.miExportArmyAsTransformedXml.Activated += new global::System.EventHandler (this.OnTransformedXmlActionActivated);
+			this.miEditArmy.Activated += new global::System.EventHandler (this.OnMiEditArmyActivated);
 			this.treeUnits.RowActivated += new global::Gtk.RowActivatedHandler (this.ArmyRowActivated);
 			this.treeUnits.PopupMenu += new global::Gtk.PopupMenuHandler (this.OnTreeUnitsPopupMenu);
 			this.treeUnits.ButtonPressEvent += new global::Gtk.ButtonPressEventHandler (this.UnitTreeButtonPressed);