changeset 138:33962c2ef550

Re #326: Make army names and sizes modifiable after creation * Add army editing form * Hook up to events to update main window * Add edit army option to Edit menu
author IBBoard <dev@ibboard.co.uk>
date Tue, 11 Oct 2011 21:05:10 +0100
parents 5b92d2be69d8
children d4b726cec12c
files FrmEditArmy.cs FrmMainWindow.cs IBBoard.WarFoundry.GUI.GTK.csproj gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmEditArmy.cs gtk-gui/gui.stetic translations/en.translation
diffstat 6 files changed, 383 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FrmEditArmy.cs	Tue Oct 11 21:05:10 2011 +0100
@@ -0,0 +1,46 @@
+// 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();
+		}
+
+		private void DoUpdate()
+		{
+			EditArmyCommand command = new EditArmyCommand(army);
+			command.NewName = txtArmyName.Text;
+			command.NewSize = (int)sbPointsValue.Value;
+			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/FrmMainWindow.cs	Tue Oct 11 20:24:11 2011 +0100
+++ b/FrmMainWindow.cs	Tue Oct 11 21:05:10 2011 +0100
@@ -520,6 +520,8 @@
 				oldArmy.UnitAdded -= UnitAddedMethod;
 				oldArmy.UnitRemoved -= UnitRemovedMethod;
 				oldArmy.PointsValueChanged -= PointsValueChangedMethod;
+				oldArmy.NameChanged -= OnArmyNameChanged;
+				oldArmy.MaxPointsValueChanged -= OnMaxPointsValueChanged;
 			}
 
 			unitToWidgetMap.Clear();
@@ -538,6 +540,8 @@
 				newArmy.UnitAdded += UnitAddedMethod;
 				newArmy.UnitRemoved += UnitRemovedMethod;
 				newArmy.PointsValueChanged += PointsValueChangedMethod;
+				newArmy.NameChanged += OnArmyNameChanged;
+				newArmy.MaxPointsValueChanged += OnMaxPointsValueChanged;
 				//TODO: Clear all buttons
 				EnableCategoryButtons();
 
@@ -552,6 +556,7 @@
 			miCloseArmy.Sensitive = nonNullNewArmy;
 			miSaveArmyAs.Sensitive = nonNullNewArmy;
 			miExportArmyAs.Sensitive = nonNullNewArmy;
+			miEditArmy.Sensitive = nonNullNewArmy;
 			hpaned2.Visible = nonNullNewArmy;
 			loadedArmyPath = null;
 			//New army has no changes, so we can't save it
@@ -562,6 +567,16 @@
 			SetPointsPanelText();
 		}
 
+		private void OnArmyNameChanged (WarFoundryObject obj, string oldValue, string newValue)
+		{
+			SetAppTitle();
+		}
+
+		private void OnMaxPointsValueChanged (WarFoundryObject obj, int oldValue, int newValue)
+		{
+			SetPointsPanelText();
+		}
+
 		private void SetArmyTree(Army army)
 		{
 			logger.Debug("Resetting tree");
@@ -1175,12 +1190,20 @@
 			}
 		}
 
-		protected void OnTransformedXmlActionActivated (object sender, System.EventArgs e)
+		protected void OnTransformedXmlActionActivated(object sender, System.EventArgs e)
 		{
 			FrmExportXml form = new FrmExportXml(WarFoundryCore.CurrentArmy);
 			form.Run();
 			form.Hide();
 			form.Dispose();
 		}
+
+		protected void OnMiEditArmyActivated(object sender, System.EventArgs e)
+		{
+			FrmEditArmy form = new FrmEditArmy(commandStack, WarFoundryCore.CurrentArmy);
+			form.Run();
+			form.Hide();
+			form.Dispose();
+		}
 	}
 }
--- a/IBBoard.WarFoundry.GUI.GTK.csproj	Tue Oct 11 20:24:11 2011 +0100
+++ b/IBBoard.WarFoundry.GUI.GTK.csproj	Tue Oct 11 21:05:10 2011 +0100
@@ -75,6 +75,8 @@
     <Compile Include="FrmExportXml.cs" />
     <Compile Include="Widgets\TransformXmlWidget.cs" />
     <Compile Include="gtk-gui\IBBoard.WarFoundry.GUI.GTK.TransformXmlWidget.cs" />
+    <Compile Include="FrmEditArmy.cs" />
+    <Compile Include="gtk-gui\IBBoard.WarFoundry.GUI.GTK.FrmEditArmy.cs" />
   </ItemGroup>
   <ItemGroup>
     <Content Include="App.png" />
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gtk-gui/IBBoard.WarFoundry.GUI.GTK.FrmEditArmy.cs	Tue Oct 11 21:05:10 2011 +0100
@@ -0,0 +1,130 @@
+
+// This file has been generated by the GUI designer. Do not modify.
+namespace IBBoard.WarFoundry.GUI.GTK
+{
+	public partial class FrmEditArmy
+	{
+		private global::Gtk.Table table1;
+		private global::Gtk.HBox hbox2;
+		private global::Gtk.SpinButton sbPointsValue;
+		private global::IBBoard.GtkSharp.Translatable.TranslatableLabel lblArmyName;
+		private global::IBBoard.GtkSharp.Translatable.TranslatableLabel lblArmySize;
+		private global::Gtk.Entry txtArmyName;
+		private global::Gtk.Button buttonCancel;
+		private global::Gtk.Button buttonOk;
+		
+		protected virtual void Build ()
+		{
+			global::Stetic.Gui.Initialize (this);
+			// Widget IBBoard.WarFoundry.GUI.GTK.FrmEditArmy
+			this.Name = "IBBoard.WarFoundry.GUI.GTK.FrmEditArmy";
+			this.WindowPosition = ((global::Gtk.WindowPosition)(4));
+			// Internal child IBBoard.WarFoundry.GUI.GTK.FrmEditArmy.VBox
+			global::Gtk.VBox w1 = this.VBox;
+			w1.Name = "dialog1_VBox";
+			w1.BorderWidth = ((uint)(2));
+			// Container child dialog1_VBox.Gtk.Box+BoxChild
+			this.table1 = new global::Gtk.Table (((uint)(2)), ((uint)(2)), false);
+			this.table1.Name = "table1";
+			this.table1.RowSpacing = ((uint)(6));
+			this.table1.ColumnSpacing = ((uint)(6));
+			// Container child table1.Gtk.Table+TableChild
+			this.hbox2 = new global::Gtk.HBox ();
+			this.hbox2.Name = "hbox2";
+			// Container child hbox2.Gtk.Box+BoxChild
+			this.sbPointsValue = new global::Gtk.SpinButton (0, 2000000000, 100);
+			this.sbPointsValue.WidthRequest = 150;
+			this.sbPointsValue.CanFocus = true;
+			this.sbPointsValue.Name = "sbPointsValue";
+			this.sbPointsValue.Adjustment.PageIncrement = 1000;
+			this.sbPointsValue.ClimbRate = 100;
+			this.sbPointsValue.Numeric = true;
+			this.sbPointsValue.Value = 1000;
+			this.hbox2.Add (this.sbPointsValue);
+			global::Gtk.Box.BoxChild w2 = ((global::Gtk.Box.BoxChild)(this.hbox2 [this.sbPointsValue]));
+			w2.Position = 0;
+			w2.Expand = false;
+			w2.Fill = false;
+			this.table1.Add (this.hbox2);
+			global::Gtk.Table.TableChild w3 = ((global::Gtk.Table.TableChild)(this.table1 [this.hbox2]));
+			w3.TopAttach = ((uint)(1));
+			w3.BottomAttach = ((uint)(2));
+			w3.LeftAttach = ((uint)(1));
+			w3.RightAttach = ((uint)(2));
+			w3.YOptions = ((global::Gtk.AttachOptions)(4));
+			// Container child table1.Gtk.Table+TableChild
+			this.lblArmyName = new global::IBBoard.GtkSharp.Translatable.TranslatableLabel ();
+			this.lblArmyName.Name = "lblArmyName";
+			this.lblArmyName.LabelProp = global::Mono.Unix.Catalog.GetString ("army name:");
+			this.table1.Add (this.lblArmyName);
+			global::Gtk.Table.TableChild w4 = ((global::Gtk.Table.TableChild)(this.table1 [this.lblArmyName]));
+			w4.XOptions = ((global::Gtk.AttachOptions)(4));
+			w4.YOptions = ((global::Gtk.AttachOptions)(4));
+			// Container child table1.Gtk.Table+TableChild
+			this.lblArmySize = new global::IBBoard.GtkSharp.Translatable.TranslatableLabel ();
+			this.lblArmySize.Name = "lblArmySize";
+			this.lblArmySize.LabelProp = global::Mono.Unix.Catalog.GetString ("army size:");
+			this.table1.Add (this.lblArmySize);
+			global::Gtk.Table.TableChild w5 = ((global::Gtk.Table.TableChild)(this.table1 [this.lblArmySize]));
+			w5.TopAttach = ((uint)(1));
+			w5.BottomAttach = ((uint)(2));
+			w5.XOptions = ((global::Gtk.AttachOptions)(4));
+			w5.YOptions = ((global::Gtk.AttachOptions)(4));
+			// Container child table1.Gtk.Table+TableChild
+			this.txtArmyName = new global::Gtk.Entry ();
+			this.txtArmyName.CanFocus = true;
+			this.txtArmyName.Name = "txtArmyName";
+			this.txtArmyName.IsEditable = true;
+			this.txtArmyName.InvisibleChar = '●';
+			this.table1.Add (this.txtArmyName);
+			global::Gtk.Table.TableChild w6 = ((global::Gtk.Table.TableChild)(this.table1 [this.txtArmyName]));
+			w6.LeftAttach = ((uint)(1));
+			w6.RightAttach = ((uint)(2));
+			w6.YOptions = ((global::Gtk.AttachOptions)(4));
+			w1.Add (this.table1);
+			global::Gtk.Box.BoxChild w7 = ((global::Gtk.Box.BoxChild)(w1 [this.table1]));
+			w7.Position = 0;
+			w7.Expand = false;
+			w7.Fill = false;
+			// Internal child IBBoard.WarFoundry.GUI.GTK.FrmEditArmy.ActionArea
+			global::Gtk.HButtonBox w8 = this.ActionArea;
+			w8.Name = "dialog1_ActionArea";
+			w8.Spacing = 10;
+			w8.BorderWidth = ((uint)(5));
+			w8.LayoutStyle = ((global::Gtk.ButtonBoxStyle)(4));
+			// Container child dialog1_ActionArea.Gtk.ButtonBox+ButtonBoxChild
+			this.buttonCancel = new global::Gtk.Button ();
+			this.buttonCancel.CanDefault = true;
+			this.buttonCancel.CanFocus = true;
+			this.buttonCancel.Name = "buttonCancel";
+			this.buttonCancel.UseStock = true;
+			this.buttonCancel.UseUnderline = true;
+			this.buttonCancel.Label = "gtk-cancel";
+			this.AddActionWidget (this.buttonCancel, -6);
+			global::Gtk.ButtonBox.ButtonBoxChild w9 = ((global::Gtk.ButtonBox.ButtonBoxChild)(w8 [this.buttonCancel]));
+			w9.Expand = false;
+			w9.Fill = false;
+			// Container child dialog1_ActionArea.Gtk.ButtonBox+ButtonBoxChild
+			this.buttonOk = new global::Gtk.Button ();
+			this.buttonOk.CanDefault = true;
+			this.buttonOk.CanFocus = true;
+			this.buttonOk.Name = "buttonOk";
+			this.buttonOk.UseStock = true;
+			this.buttonOk.UseUnderline = true;
+			this.buttonOk.Label = "gtk-ok";
+			this.AddActionWidget (this.buttonOk, -5);
+			global::Gtk.ButtonBox.ButtonBoxChild w10 = ((global::Gtk.ButtonBox.ButtonBoxChild)(w8 [this.buttonOk]));
+			w10.Position = 1;
+			w10.Expand = false;
+			w10.Fill = false;
+			if ((this.Child != null)) {
+				this.Child.ShowAll ();
+			}
+			this.DefaultWidth = 400;
+			this.DefaultHeight = 135;
+			this.Show ();
+			this.buttonCancel.Clicked += new global::System.EventHandler (this.OnButtonCancelClicked);
+			this.buttonOk.Clicked += new global::System.EventHandler (this.OnButtonOkClicked);
+		}
+	}
+}
--- a/gtk-gui/gui.stetic	Tue Oct 11 20:24:11 2011 +0100
+++ b/gtk-gui/gui.stetic	Tue Oct 11 21:05:10 2011 +0100
@@ -171,6 +171,14 @@
         <property name="ShortLabel" translatable="yes">transformed xml</property>
         <signal name="Activated" handler="OnTransformedXmlActionActivated" />
       </action>
+      <action id="miEditArmy">
+        <property name="Type">Action</property>
+        <property name="Label" translatable="yes">_edit army</property>
+        <property name="Sensitive">False</property>
+        <property name="ShortLabel" translatable="yes">_edit army</property>
+        <property name="StockId">gtk-edit</property>
+        <signal name="Activated" handler="OnMiEditArmyActivated" />
+      </action>
     </action-group>
     <property name="MemberName" />
     <property name="Title" translatable="yes">MainWindow</property>
@@ -201,6 +209,8 @@
                 <node type="Menuitem" action="miUndo" />
                 <node type="Menuitem" action="miRedo" />
                 <node type="Separator" />
+                <node type="Menuitem" action="miEditArmy" />
+                <node type="Separator" />
                 <node type="Menuitem" action="miPreferences" />
               </node>
               <node type="Menu" action="menuHelp">
@@ -2610,4 +2620,172 @@
       </widget>
     </child>
   </widget>
+  <widget class="Gtk.Dialog" id="IBBoard.WarFoundry.GUI.GTK.FrmEditArmy" design-size="400 135">
+    <property name="MemberName" />
+    <property name="WindowPosition">CenterOnParent</property>
+    <property name="Buttons">2</property>
+    <property name="HelpButton">False</property>
+    <child internal-child="VBox">
+      <widget class="Gtk.VBox" id="dialog1_VBox">
+        <property name="MemberName" />
+        <property name="BorderWidth">2</property>
+        <child>
+          <widget class="Gtk.Table" id="table1">
+            <property name="MemberName" />
+            <property name="NRows">2</property>
+            <property name="NColumns">2</property>
+            <property name="RowSpacing">6</property>
+            <property name="ColumnSpacing">6</property>
+            <child>
+              <widget class="Gtk.HBox" id="hbox2">
+                <property name="MemberName" />
+                <child>
+                  <widget class="Gtk.SpinButton" id="sbPointsValue">
+                    <property name="MemberName" />
+                    <property name="WidthRequest">150</property>
+                    <property name="CanFocus">True</property>
+                    <property name="Upper">2000000000</property>
+                    <property name="PageIncrement">1000</property>
+                    <property name="StepIncrement">100</property>
+                    <property name="ClimbRate">100</property>
+                    <property name="Numeric">True</property>
+                    <property name="Value">1000</property>
+                  </widget>
+                  <packing>
+                    <property name="Position">0</property>
+                    <property name="AutoSize">True</property>
+                    <property name="Expand">False</property>
+                    <property name="Fill">False</property>
+                  </packing>
+                </child>
+                <child>
+                  <placeholder />
+                </child>
+              </widget>
+              <packing>
+                <property name="TopAttach">1</property>
+                <property name="BottomAttach">2</property>
+                <property name="LeftAttach">1</property>
+                <property name="RightAttach">2</property>
+                <property name="AutoSize">True</property>
+                <property name="YOptions">Fill</property>
+                <property name="XExpand">True</property>
+                <property name="XFill">True</property>
+                <property name="XShrink">False</property>
+                <property name="YExpand">False</property>
+                <property name="YFill">True</property>
+                <property name="YShrink">False</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="IBBoard.GtkSharp.Translatable.TranslatableLabel" id="lblArmyName">
+                <property name="MemberName" />
+                <property name="LabelProp" translatable="yes">army name:</property>
+              </widget>
+              <packing>
+                <property name="AutoSize">True</property>
+                <property name="XOptions">Fill</property>
+                <property name="YOptions">Fill</property>
+                <property name="XExpand">False</property>
+                <property name="XFill">True</property>
+                <property name="XShrink">False</property>
+                <property name="YExpand">False</property>
+                <property name="YFill">True</property>
+                <property name="YShrink">False</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="IBBoard.GtkSharp.Translatable.TranslatableLabel" id="lblArmySize">
+                <property name="MemberName" />
+                <property name="LabelProp" translatable="yes">army size:</property>
+              </widget>
+              <packing>
+                <property name="TopAttach">1</property>
+                <property name="BottomAttach">2</property>
+                <property name="AutoSize">True</property>
+                <property name="XOptions">Fill</property>
+                <property name="YOptions">Fill</property>
+                <property name="XExpand">False</property>
+                <property name="XFill">True</property>
+                <property name="XShrink">False</property>
+                <property name="YExpand">False</property>
+                <property name="YFill">True</property>
+                <property name="YShrink">False</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="Gtk.Entry" id="txtArmyName">
+                <property name="MemberName" />
+                <property name="CanFocus">True</property>
+                <property name="IsEditable">True</property>
+                <property name="InvisibleChar">●</property>
+              </widget>
+              <packing>
+                <property name="LeftAttach">1</property>
+                <property name="RightAttach">2</property>
+                <property name="AutoSize">True</property>
+                <property name="YOptions">Fill</property>
+                <property name="XExpand">True</property>
+                <property name="XFill">True</property>
+                <property name="XShrink">False</property>
+                <property name="YExpand">False</property>
+                <property name="YFill">True</property>
+                <property name="YShrink">False</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="Position">0</property>
+            <property name="AutoSize">True</property>
+            <property name="Expand">False</property>
+            <property name="Fill">False</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+    <child internal-child="ActionArea">
+      <widget class="Gtk.HButtonBox" id="dialog1_ActionArea">
+        <property name="MemberName" />
+        <property name="Spacing">10</property>
+        <property name="BorderWidth">5</property>
+        <property name="Size">2</property>
+        <property name="LayoutStyle">End</property>
+        <child>
+          <widget class="Gtk.Button" id="buttonCancel">
+            <property name="MemberName" />
+            <property name="CanDefault">True</property>
+            <property name="CanFocus">True</property>
+            <property name="UseStock">True</property>
+            <property name="Type">StockItem</property>
+            <property name="StockId">gtk-cancel</property>
+            <property name="ResponseId">-6</property>
+            <signal name="Clicked" handler="OnButtonCancelClicked" />
+            <property name="label">gtk-cancel</property>
+          </widget>
+          <packing>
+            <property name="Expand">False</property>
+            <property name="Fill">False</property>
+          </packing>
+        </child>
+        <child>
+          <widget class="Gtk.Button" id="buttonOk">
+            <property name="MemberName" />
+            <property name="CanDefault">True</property>
+            <property name="CanFocus">True</property>
+            <property name="UseStock">True</property>
+            <property name="Type">StockItem</property>
+            <property name="StockId">gtk-ok</property>
+            <property name="ResponseId">-5</property>
+            <signal name="Clicked" handler="OnButtonOkClicked" />
+            <property name="label">gtk-ok</property>
+          </widget>
+          <packing>
+            <property name="Position">1</property>
+            <property name="Expand">False</property>
+            <property name="Fill">False</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
 </stetic-interface>
\ No newline at end of file
--- a/translations/en.translation	Tue Oct 11 20:24:11 2011 +0100
+++ b/translations/en.translation	Tue Oct 11 21:05:10 2011 +0100
@@ -25,6 +25,7 @@
 <!-- Main Window / Menus / Edit Menu -->
 <translation id="miUndo">_Undo</translation>
 <translation id="miRedo">_Redo</translation>
+<translation id="miEditArmy">_Edit Army</translation>
 <translation id="miPreferences">_Preferences</translation>
 <!-- Main Window / Menus / Help Menu -->
 <translation id="miAbout">_About</translation>
@@ -126,6 +127,8 @@
 <!-- Export / XML -->
 <translation id="lblTransform">Transformation:</translation>
 <translation id="doTransformWidget">Transform Output</translation>
+<!-- Edit Army -->
+<translation id="IBBoard.WarFoundry.GUI.GTK.FrmEditArmy">Edit Army</translation>
 <!-- API -->
 <translation id="defaultUnitName">Unit of {0} {1}</translation>
 <translation id="setEquipmentAmountCommandDescription">Set {0} amount for {1} to {2}</translation>