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 diff
     1.1 --- a/FrmArmyTree.cs	Sat Sep 19 10:53:04 2009 +0000
     1.2 +++ b/FrmArmyTree.cs	Sat Sep 19 11:50:04 2009 +0000
     1.3 @@ -8,9 +8,10 @@
     1.4  using System.ComponentModel;
     1.5  using System.Windows.Forms;
     1.6  using IBBoard.Commands;
     1.7 +using IBBoard.Windows.Forms.I18N;
     1.8 +using IBBoard.Windows.Forms;
     1.9  using IBBoard.WarFoundry.API;
    1.10  using IBBoard.WarFoundry.API.Commands;
    1.11 -using IBBoard.Windows.Forms;
    1.12  using IBBoard.WarFoundry.API.Objects;
    1.13  
    1.14  namespace IBBoard.WarFoundry.GUI.WinForms
    1.15 @@ -21,19 +22,20 @@
    1.16  	public class FrmArmyTree : IBBoard.Windows.Forms.IBBForm
    1.17  	{
    1.18  		private System.Windows.Forms.TreeView treeView;
    1.19 -		/// <summary>
    1.20 -		/// Required designer variable.
    1.21 -		/// </summary>
    1.22 -		private System.ComponentModel.Container components = null;
    1.23 +		private IContainer components;
    1.24  		private Dictionary<string, TreeNode> nodes;
    1.25  		private System.Windows.Forms.ContextMenu contextMenu;
    1.26 -		private System.Windows.Forms.MenuItem miDelete;
    1.27 -		private System.Windows.Forms.MenuItem miEdit;
    1.28 +		private IBBMenuItem miDelete;
    1.29 +		private IBBMenuItem miEdit;
    1.30  		private Dictionary<string, FrmUnit> unitWindows;
    1.31  		
    1.32  		private ObjectAddDelegate UnitAddedMethod;
    1.33  		private ObjectRemoveDelegate UnitRemovedMethod;
    1.34  		private StringValChangedDelegate UnitNameChangedMethod, ArmyNameChangedMethod, TreeNameChangedMethod;
    1.35 +		private ToolBar toolBar;
    1.36 +		private IBBToolBarButton bttnEdit;
    1.37 +		private IBBToolBarButton bttnDelete;
    1.38 +		private ImageList imageList;
    1.39  		private CommandStack commandStack;
    1.40  
    1.41  		public FrmArmyTree(CommandStack cmdStack)
    1.42 @@ -49,6 +51,21 @@
    1.43  			unitWindows = new Dictionary<string, FrmUnit>();
    1.44  			this.Name = "ArmyTree";			
    1.45  			WarFoundryCore.ArmyChanged+= new ArmyChangedDelegate(FrmArmyTree_ArmyChanged);
    1.46 +
    1.47 +			foreach (Control ctrl in Controls)
    1.48 +			{
    1.49 +				ControlTranslator.TranslateControl(ctrl);
    1.50 +			}
    1.51 +
    1.52 +			foreach (Component comp in components.Components)
    1.53 +			{
    1.54 +				ControlTranslator.TranslateComponent(comp);
    1.55 +			}
    1.56 +
    1.57 +			foreach (IBBMenuItem mi in contextMenu.MenuItems)
    1.58 +			{
    1.59 +				ControlTranslator.TranslateComponent(mi);
    1.60 +			}
    1.61  		}
    1.62  
    1.63  		public FrmArmyTree(Army army, CommandStack cmdStack) : this(cmdStack)
    1.64 @@ -78,52 +95,92 @@
    1.65  		/// </summary>
    1.66  		private void InitializeComponent()
    1.67  		{
    1.68 +			this.components = new System.ComponentModel.Container();
    1.69 +			System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmArmyTree));
    1.70 +			this.contextMenu = new System.Windows.Forms.ContextMenu();
    1.71 +			this.miEdit = new IBBoard.Windows.Forms.IBBMenuItem();
    1.72 +			this.miDelete = new IBBoard.Windows.Forms.IBBMenuItem();
    1.73 +			this.imageList = new System.Windows.Forms.ImageList(this.components);
    1.74 +			this.toolBar = new System.Windows.Forms.ToolBar();
    1.75 +			this.bttnEdit = new IBBoard.Windows.Forms.IBBToolBarButton();
    1.76 +			this.bttnDelete = new IBBoard.Windows.Forms.IBBToolBarButton();
    1.77  			this.treeView = new System.Windows.Forms.TreeView();
    1.78 -			this.contextMenu = new System.Windows.Forms.ContextMenu();
    1.79 -			this.miEdit = new System.Windows.Forms.MenuItem();
    1.80 -			this.miDelete = new System.Windows.Forms.MenuItem();
    1.81  			this.SuspendLayout();
    1.82  			// 
    1.83 -			// treeView
    1.84 -			// 
    1.85 -			this.treeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
    1.86 -				| System.Windows.Forms.AnchorStyles.Left) 
    1.87 -				| System.Windows.Forms.AnchorStyles.Right)));
    1.88 -			this.treeView.ContextMenu = this.contextMenu;
    1.89 -			this.treeView.FullRowSelect = true;
    1.90 -			this.treeView.ImageIndex = -1;
    1.91 -			this.treeView.Location = new System.Drawing.Point(0, 0);
    1.92 -			this.treeView.Name = "treeView";
    1.93 -			this.treeView.SelectedImageIndex = -1;
    1.94 -			this.treeView.Size = new System.Drawing.Size(240, 278);
    1.95 -			this.treeView.TabIndex = 0;
    1.96 -			this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseDown);
    1.97 -			this.treeView.DoubleClick += new System.EventHandler(this.treeView_DoubleClick);
    1.98 -			// 
    1.99  			// contextMenu
   1.100  			// 
   1.101  			this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
   1.102 -																						this.miEdit,
   1.103 -																						this.miDelete});
   1.104 +            this.miEdit,
   1.105 +            this.miDelete});
   1.106  			this.contextMenu.Popup += new System.EventHandler(this.contextMenu_Popup);
   1.107  			// 
   1.108  			// miEdit
   1.109  			// 
   1.110  			this.miEdit.Index = 0;
   1.111 -			this.miEdit.Text = "&Edit unit";
   1.112 +			this.miEdit.Text = "&edit unit";
   1.113  			this.miEdit.Click += new System.EventHandler(this.miEdit_Click);
   1.114  			// 
   1.115  			// miDelete
   1.116  			// 
   1.117  			this.miDelete.Index = 1;
   1.118 -			this.miDelete.Text = "&Delete unit";
   1.119 +			this.miDelete.Text = "&delete unit";
   1.120  			this.miDelete.Click += new System.EventHandler(this.miDelete_Click);
   1.121  			// 
   1.122 +			// imageList
   1.123 +			// 
   1.124 +			this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer) (resources.GetObject("imageList.ImageStream")));
   1.125 +			this.imageList.TransparentColor = System.Drawing.Color.Transparent;
   1.126 +			this.imageList.Images.SetKeyName(0, "gtk-edit.png");
   1.127 +			this.imageList.Images.SetKeyName(1, "edit-delete.png");
   1.128 +			// 
   1.129 +			// toolBar
   1.130 +			// 
   1.131 +			this.toolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
   1.132 +            this.bttnEdit,
   1.133 +            this.bttnDelete});
   1.134 +			this.toolBar.ButtonSize = new System.Drawing.Size(16, 16);
   1.135 +			this.toolBar.DropDownArrows = true;
   1.136 +			this.toolBar.ImageList = this.imageList;
   1.137 +			this.toolBar.Location = new System.Drawing.Point(0, 0);
   1.138 +			this.toolBar.Name = "toolBar";
   1.139 +			this.toolBar.ShowToolTips = true;
   1.140 +			this.toolBar.Size = new System.Drawing.Size(240, 28);
   1.141 +			this.toolBar.TabIndex = 3;
   1.142 +			this.toolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar_ButtonClick);
   1.143 +			// 
   1.144 +			// bttnEdit
   1.145 +			// 
   1.146 +			this.bttnEdit.Enabled = false;
   1.147 +			this.bttnEdit.ImageIndex = 0;
   1.148 +			this.bttnEdit.Name = "bttnEdit";
   1.149 +			// 
   1.150 +			// bttnDelete
   1.151 +			// 
   1.152 +			this.bttnDelete.Enabled = false;
   1.153 +			this.bttnDelete.ImageIndex = 1;
   1.154 +			this.bttnDelete.Name = "bttnDelete";
   1.155 +			// 
   1.156 +			// treeView
   1.157 +			// 
   1.158 +			this.treeView.Anchor = ((System.Windows.Forms.AnchorStyles) ((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
   1.159 +						| System.Windows.Forms.AnchorStyles.Left)
   1.160 +						| System.Windows.Forms.AnchorStyles.Right)));
   1.161 +			this.treeView.ContextMenu = this.contextMenu;
   1.162 +			this.treeView.FullRowSelect = true;
   1.163 +			this.treeView.Location = new System.Drawing.Point(0, 28);
   1.164 +			this.treeView.Name = "treeView";
   1.165 +			this.treeView.Size = new System.Drawing.Size(240, 250);
   1.166 +			this.treeView.TabIndex = 0;
   1.167 +			this.treeView.DoubleClick += new System.EventHandler(this.treeView_DoubleClick);
   1.168 +			this.treeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView_AfterSelect);
   1.169 +			this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseDown);
   1.170 +			// 
   1.171  			// FrmArmyTree
   1.172  			// 
   1.173  			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
   1.174  			this.ClientSize = new System.Drawing.Size(240, 277);
   1.175  			this.ControlBox = false;
   1.176 +			this.Controls.Add(this.toolBar);
   1.177  			this.Controls.Add(this.treeView);
   1.178  			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
   1.179  			this.MaximizeBox = false;
   1.180 @@ -131,6 +188,7 @@
   1.181  			this.Name = "FrmArmyTree";
   1.182  			this.Text = "FrmArmyTree";
   1.183  			this.ResumeLayout(false);
   1.184 +			this.PerformLayout();
   1.185  
   1.186  		}
   1.187  		#endregion
   1.188 @@ -257,6 +315,7 @@
   1.189  		private void contextMenu_Popup(object sender, System.EventArgs e)
   1.190  		{
   1.191  			TreeNode node = treeView.SelectedNode;
   1.192 +
   1.193  			if (node!=null && node.Tag is Unit)
   1.194  			{
   1.195  				foreach(MenuItem item in contextMenu.MenuItems)
   1.196 @@ -292,11 +351,17 @@
   1.197  
   1.198  		private void miDelete_Click(object sender, System.EventArgs e)
   1.199  		{
   1.200 +			DeleteUnit();
   1.201 +		}
   1.202 +
   1.203 +		private void DeleteUnit()
   1.204 +		{
   1.205 +
   1.206  			TreeNode selected = treeView.SelectedNode;
   1.207  
   1.208 -			if (selected.Tag!=null && selected.Tag is Unit)
   1.209 +			if (selected.Tag != null && selected.Tag is Unit)
   1.210  			{
   1.211 -				Unit unit = (Unit)selected.Tag;
   1.212 +				Unit unit = (Unit) selected.Tag;
   1.213  				commandStack.Execute(new RemoveUnitCommand(unit));
   1.214  			}
   1.215  		}
   1.216 @@ -382,5 +447,25 @@
   1.217  				node.Text = obj.Name;
   1.218  			}
   1.219  		}
   1.220 +
   1.221 +		private void toolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
   1.222 +		{
   1.223 +			if (e.Button == bttnDelete)
   1.224 +			{
   1.225 +				DeleteUnit();
   1.226 +			}
   1.227 +			else if (e.Button == bttnEdit)
   1.228 +			{
   1.229 +				EditUnit();
   1.230 +			}
   1.231 +		}
   1.232 +
   1.233 +		private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
   1.234 +		{
   1.235 +			TreeNode node = treeView.SelectedNode;
   1.236 +
   1.237 +			bttnDelete.Enabled = (node != null && node.Tag is Unit);
   1.238 +			bttnEdit.Enabled = bttnDelete.Enabled;
   1.239 +		}
   1.240  	}
   1.241  }