changeset 57:f272e70a9f71

Fixes #169: Add more obvious edit and delete options to Army Tree * Add toolbar with "edit" and "delete" buttons to army tree
author IBBoard <dev@ibboard.co.uk>
date Sat, 19 Sep 2009 11:50:04 +0000
parents 11e81ba85684
children 05df6494f0b7
files FrmArmyTree.cs
diffstat 1 files changed, 117 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/FrmArmyTree.cs	Sat Sep 19 10:53:04 2009 +0000
+++ b/FrmArmyTree.cs	Sat Sep 19 11:50:04 2009 +0000
@@ -8,9 +8,10 @@
 using System.ComponentModel;
 using System.Windows.Forms;
 using IBBoard.Commands;
+using IBBoard.Windows.Forms.I18N;
+using IBBoard.Windows.Forms;
 using IBBoard.WarFoundry.API;
 using IBBoard.WarFoundry.API.Commands;
-using IBBoard.Windows.Forms;
 using IBBoard.WarFoundry.API.Objects;
 
 namespace IBBoard.WarFoundry.GUI.WinForms
@@ -21,19 +22,20 @@
 	public class FrmArmyTree : IBBoard.Windows.Forms.IBBForm
 	{
 		private System.Windows.Forms.TreeView treeView;
-		/// <summary>
-		/// Required designer variable.
-		/// </summary>
-		private System.ComponentModel.Container components = null;
+		private IContainer components;
 		private Dictionary<string, TreeNode> nodes;
 		private System.Windows.Forms.ContextMenu contextMenu;
-		private System.Windows.Forms.MenuItem miDelete;
-		private System.Windows.Forms.MenuItem miEdit;
+		private IBBMenuItem miDelete;
+		private IBBMenuItem miEdit;
 		private Dictionary<string, FrmUnit> unitWindows;
 		
 		private ObjectAddDelegate UnitAddedMethod;
 		private ObjectRemoveDelegate UnitRemovedMethod;
 		private StringValChangedDelegate UnitNameChangedMethod, ArmyNameChangedMethod, TreeNameChangedMethod;
+		private ToolBar toolBar;
+		private IBBToolBarButton bttnEdit;
+		private IBBToolBarButton bttnDelete;
+		private ImageList imageList;
 		private CommandStack commandStack;
 
 		public FrmArmyTree(CommandStack cmdStack)
@@ -49,6 +51,21 @@
 			unitWindows = new Dictionary<string, FrmUnit>();
 			this.Name = "ArmyTree";			
 			WarFoundryCore.ArmyChanged+= new ArmyChangedDelegate(FrmArmyTree_ArmyChanged);
+
+			foreach (Control ctrl in Controls)
+			{
+				ControlTranslator.TranslateControl(ctrl);
+			}
+
+			foreach (Component comp in components.Components)
+			{
+				ControlTranslator.TranslateComponent(comp);
+			}
+
+			foreach (IBBMenuItem mi in contextMenu.MenuItems)
+			{
+				ControlTranslator.TranslateComponent(mi);
+			}
 		}
 
 		public FrmArmyTree(Army army, CommandStack cmdStack) : this(cmdStack)
@@ -78,52 +95,92 @@
 		/// </summary>
 		private void InitializeComponent()
 		{
-			this.treeView = new System.Windows.Forms.TreeView();
+			this.components = new System.ComponentModel.Container();
+			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmArmyTree));
 			this.contextMenu = new System.Windows.Forms.ContextMenu();
-			this.miEdit = new System.Windows.Forms.MenuItem();
-			this.miDelete = new System.Windows.Forms.MenuItem();
+			this.miEdit = new IBBoard.Windows.Forms.IBBMenuItem();
+			this.miDelete = new IBBoard.Windows.Forms.IBBMenuItem();
+			this.imageList = new System.Windows.Forms.ImageList(this.components);
+			this.toolBar = new System.Windows.Forms.ToolBar();
+			this.bttnEdit = new IBBoard.Windows.Forms.IBBToolBarButton();
+			this.bttnDelete = new IBBoard.Windows.Forms.IBBToolBarButton();
+			this.treeView = new System.Windows.Forms.TreeView();
 			this.SuspendLayout();
 			// 
-			// treeView
-			// 
-			this.treeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
-				| System.Windows.Forms.AnchorStyles.Left) 
-				| System.Windows.Forms.AnchorStyles.Right)));
-			this.treeView.ContextMenu = this.contextMenu;
-			this.treeView.FullRowSelect = true;
-			this.treeView.ImageIndex = -1;
-			this.treeView.Location = new System.Drawing.Point(0, 0);
-			this.treeView.Name = "treeView";
-			this.treeView.SelectedImageIndex = -1;
-			this.treeView.Size = new System.Drawing.Size(240, 278);
-			this.treeView.TabIndex = 0;
-			this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseDown);
-			this.treeView.DoubleClick += new System.EventHandler(this.treeView_DoubleClick);
-			// 
 			// contextMenu
 			// 
 			this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
-																						this.miEdit,
-																						this.miDelete});
+            this.miEdit,
+            this.miDelete});
 			this.contextMenu.Popup += new System.EventHandler(this.contextMenu_Popup);
 			// 
 			// miEdit
 			// 
 			this.miEdit.Index = 0;
-			this.miEdit.Text = "&Edit unit";
+			this.miEdit.Text = "&edit unit";
 			this.miEdit.Click += new System.EventHandler(this.miEdit_Click);
 			// 
 			// miDelete
 			// 
 			this.miDelete.Index = 1;
-			this.miDelete.Text = "&Delete unit";
+			this.miDelete.Text = "&delete unit";
 			this.miDelete.Click += new System.EventHandler(this.miDelete_Click);
 			// 
+			// imageList
+			// 
+			this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer) (resources.GetObject("imageList.ImageStream")));
+			this.imageList.TransparentColor = System.Drawing.Color.Transparent;
+			this.imageList.Images.SetKeyName(0, "gtk-edit.png");
+			this.imageList.Images.SetKeyName(1, "edit-delete.png");
+			// 
+			// toolBar
+			// 
+			this.toolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
+            this.bttnEdit,
+            this.bttnDelete});
+			this.toolBar.ButtonSize = new System.Drawing.Size(16, 16);
+			this.toolBar.DropDownArrows = true;
+			this.toolBar.ImageList = this.imageList;
+			this.toolBar.Location = new System.Drawing.Point(0, 0);
+			this.toolBar.Name = "toolBar";
+			this.toolBar.ShowToolTips = true;
+			this.toolBar.Size = new System.Drawing.Size(240, 28);
+			this.toolBar.TabIndex = 3;
+			this.toolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar_ButtonClick);
+			// 
+			// bttnEdit
+			// 
+			this.bttnEdit.Enabled = false;
+			this.bttnEdit.ImageIndex = 0;
+			this.bttnEdit.Name = "bttnEdit";
+			// 
+			// bttnDelete
+			// 
+			this.bttnDelete.Enabled = false;
+			this.bttnDelete.ImageIndex = 1;
+			this.bttnDelete.Name = "bttnDelete";
+			// 
+			// treeView
+			// 
+			this.treeView.Anchor = ((System.Windows.Forms.AnchorStyles) ((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+						| System.Windows.Forms.AnchorStyles.Left)
+						| System.Windows.Forms.AnchorStyles.Right)));
+			this.treeView.ContextMenu = this.contextMenu;
+			this.treeView.FullRowSelect = true;
+			this.treeView.Location = new System.Drawing.Point(0, 28);
+			this.treeView.Name = "treeView";
+			this.treeView.Size = new System.Drawing.Size(240, 250);
+			this.treeView.TabIndex = 0;
+			this.treeView.DoubleClick += new System.EventHandler(this.treeView_DoubleClick);
+			this.treeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView_AfterSelect);
+			this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseDown);
+			// 
 			// FrmArmyTree
 			// 
 			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
 			this.ClientSize = new System.Drawing.Size(240, 277);
 			this.ControlBox = false;
+			this.Controls.Add(this.toolBar);
 			this.Controls.Add(this.treeView);
 			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
 			this.MaximizeBox = false;
@@ -131,6 +188,7 @@
 			this.Name = "FrmArmyTree";
 			this.Text = "FrmArmyTree";
 			this.ResumeLayout(false);
+			this.PerformLayout();
 
 		}
 		#endregion
@@ -257,6 +315,7 @@
 		private void contextMenu_Popup(object sender, System.EventArgs e)
 		{
 			TreeNode node = treeView.SelectedNode;
+
 			if (node!=null && node.Tag is Unit)
 			{
 				foreach(MenuItem item in contextMenu.MenuItems)
@@ -292,11 +351,17 @@
 
 		private void miDelete_Click(object sender, System.EventArgs e)
 		{
+			DeleteUnit();
+		}
+
+		private void DeleteUnit()
+		{
+
 			TreeNode selected = treeView.SelectedNode;
 
-			if (selected.Tag!=null && selected.Tag is Unit)
+			if (selected.Tag != null && selected.Tag is Unit)
 			{
-				Unit unit = (Unit)selected.Tag;
+				Unit unit = (Unit) selected.Tag;
 				commandStack.Execute(new RemoveUnitCommand(unit));
 			}
 		}
@@ -382,5 +447,25 @@
 				node.Text = obj.Name;
 			}
 		}
+
+		private void toolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
+		{
+			if (e.Button == bttnDelete)
+			{
+				DeleteUnit();
+			}
+			else if (e.Button == bttnEdit)
+			{
+				EditUnit();
+			}
+		}
+
+		private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
+		{
+			TreeNode node = treeView.SelectedNode;
+
+			bttnDelete.Enabled = (node != null && node.Tag is Unit);
+			bttnEdit.Enabled = bttnDelete.Enabled;
+		}
 	}
 }