comparison FrmArmyTree.cs @ 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 c972fb283675
children a0ec03c24cd9
comparison
equal deleted inserted replaced
56:11e81ba85684 57:f272e70a9f71
6 using System.Drawing; 6 using System.Drawing;
7 using System.Collections.Generic; 7 using System.Collections.Generic;
8 using System.ComponentModel; 8 using System.ComponentModel;
9 using System.Windows.Forms; 9 using System.Windows.Forms;
10 using IBBoard.Commands; 10 using IBBoard.Commands;
11 using IBBoard.Windows.Forms.I18N;
12 using IBBoard.Windows.Forms;
11 using IBBoard.WarFoundry.API; 13 using IBBoard.WarFoundry.API;
12 using IBBoard.WarFoundry.API.Commands; 14 using IBBoard.WarFoundry.API.Commands;
13 using IBBoard.Windows.Forms;
14 using IBBoard.WarFoundry.API.Objects; 15 using IBBoard.WarFoundry.API.Objects;
15 16
16 namespace IBBoard.WarFoundry.GUI.WinForms 17 namespace IBBoard.WarFoundry.GUI.WinForms
17 { 18 {
18 /// <summary> 19 /// <summary>
19 /// Summary description for FrmArmyTree. 20 /// Summary description for FrmArmyTree.
20 /// </summary> 21 /// </summary>
21 public class FrmArmyTree : IBBoard.Windows.Forms.IBBForm 22 public class FrmArmyTree : IBBoard.Windows.Forms.IBBForm
22 { 23 {
23 private System.Windows.Forms.TreeView treeView; 24 private System.Windows.Forms.TreeView treeView;
24 /// <summary> 25 private IContainer components;
25 /// Required designer variable.
26 /// </summary>
27 private System.ComponentModel.Container components = null;
28 private Dictionary<string, TreeNode> nodes; 26 private Dictionary<string, TreeNode> nodes;
29 private System.Windows.Forms.ContextMenu contextMenu; 27 private System.Windows.Forms.ContextMenu contextMenu;
30 private System.Windows.Forms.MenuItem miDelete; 28 private IBBMenuItem miDelete;
31 private System.Windows.Forms.MenuItem miEdit; 29 private IBBMenuItem miEdit;
32 private Dictionary<string, FrmUnit> unitWindows; 30 private Dictionary<string, FrmUnit> unitWindows;
33 31
34 private ObjectAddDelegate UnitAddedMethod; 32 private ObjectAddDelegate UnitAddedMethod;
35 private ObjectRemoveDelegate UnitRemovedMethod; 33 private ObjectRemoveDelegate UnitRemovedMethod;
36 private StringValChangedDelegate UnitNameChangedMethod, ArmyNameChangedMethod, TreeNameChangedMethod; 34 private StringValChangedDelegate UnitNameChangedMethod, ArmyNameChangedMethod, TreeNameChangedMethod;
35 private ToolBar toolBar;
36 private IBBToolBarButton bttnEdit;
37 private IBBToolBarButton bttnDelete;
38 private ImageList imageList;
37 private CommandStack commandStack; 39 private CommandStack commandStack;
38 40
39 public FrmArmyTree(CommandStack cmdStack) 41 public FrmArmyTree(CommandStack cmdStack)
40 { 42 {
41 commandStack = cmdStack; 43 commandStack = cmdStack;
47 TreeNameChangedMethod = new StringValChangedDelegate(FrmArmyTree_TreeNameChanged); 49 TreeNameChangedMethod = new StringValChangedDelegate(FrmArmyTree_TreeNameChanged);
48 nodes = new Dictionary<string, TreeNode>(); 50 nodes = new Dictionary<string, TreeNode>();
49 unitWindows = new Dictionary<string, FrmUnit>(); 51 unitWindows = new Dictionary<string, FrmUnit>();
50 this.Name = "ArmyTree"; 52 this.Name = "ArmyTree";
51 WarFoundryCore.ArmyChanged+= new ArmyChangedDelegate(FrmArmyTree_ArmyChanged); 53 WarFoundryCore.ArmyChanged+= new ArmyChangedDelegate(FrmArmyTree_ArmyChanged);
54
55 foreach (Control ctrl in Controls)
56 {
57 ControlTranslator.TranslateControl(ctrl);
58 }
59
60 foreach (Component comp in components.Components)
61 {
62 ControlTranslator.TranslateComponent(comp);
63 }
64
65 foreach (IBBMenuItem mi in contextMenu.MenuItems)
66 {
67 ControlTranslator.TranslateComponent(mi);
68 }
52 } 69 }
53 70
54 public FrmArmyTree(Army army, CommandStack cmdStack) : this(cmdStack) 71 public FrmArmyTree(Army army, CommandStack cmdStack) : this(cmdStack)
55 { 72 {
56 SetArmy(army); 73 SetArmy(army);
76 /// Required method for Designer support - do not modify 93 /// Required method for Designer support - do not modify
77 /// the contents of this method with the code editor. 94 /// the contents of this method with the code editor.
78 /// </summary> 95 /// </summary>
79 private void InitializeComponent() 96 private void InitializeComponent()
80 { 97 {
98 this.components = new System.ComponentModel.Container();
99 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmArmyTree));
100 this.contextMenu = new System.Windows.Forms.ContextMenu();
101 this.miEdit = new IBBoard.Windows.Forms.IBBMenuItem();
102 this.miDelete = new IBBoard.Windows.Forms.IBBMenuItem();
103 this.imageList = new System.Windows.Forms.ImageList(this.components);
104 this.toolBar = new System.Windows.Forms.ToolBar();
105 this.bttnEdit = new IBBoard.Windows.Forms.IBBToolBarButton();
106 this.bttnDelete = new IBBoard.Windows.Forms.IBBToolBarButton();
81 this.treeView = new System.Windows.Forms.TreeView(); 107 this.treeView = new System.Windows.Forms.TreeView();
82 this.contextMenu = new System.Windows.Forms.ContextMenu();
83 this.miEdit = new System.Windows.Forms.MenuItem();
84 this.miDelete = new System.Windows.Forms.MenuItem();
85 this.SuspendLayout(); 108 this.SuspendLayout();
86 // 109 //
110 // contextMenu
111 //
112 this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
113 this.miEdit,
114 this.miDelete});
115 this.contextMenu.Popup += new System.EventHandler(this.contextMenu_Popup);
116 //
117 // miEdit
118 //
119 this.miEdit.Index = 0;
120 this.miEdit.Text = "&edit unit";
121 this.miEdit.Click += new System.EventHandler(this.miEdit_Click);
122 //
123 // miDelete
124 //
125 this.miDelete.Index = 1;
126 this.miDelete.Text = "&delete unit";
127 this.miDelete.Click += new System.EventHandler(this.miDelete_Click);
128 //
129 // imageList
130 //
131 this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer) (resources.GetObject("imageList.ImageStream")));
132 this.imageList.TransparentColor = System.Drawing.Color.Transparent;
133 this.imageList.Images.SetKeyName(0, "gtk-edit.png");
134 this.imageList.Images.SetKeyName(1, "edit-delete.png");
135 //
136 // toolBar
137 //
138 this.toolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
139 this.bttnEdit,
140 this.bttnDelete});
141 this.toolBar.ButtonSize = new System.Drawing.Size(16, 16);
142 this.toolBar.DropDownArrows = true;
143 this.toolBar.ImageList = this.imageList;
144 this.toolBar.Location = new System.Drawing.Point(0, 0);
145 this.toolBar.Name = "toolBar";
146 this.toolBar.ShowToolTips = true;
147 this.toolBar.Size = new System.Drawing.Size(240, 28);
148 this.toolBar.TabIndex = 3;
149 this.toolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar_ButtonClick);
150 //
151 // bttnEdit
152 //
153 this.bttnEdit.Enabled = false;
154 this.bttnEdit.ImageIndex = 0;
155 this.bttnEdit.Name = "bttnEdit";
156 //
157 // bttnDelete
158 //
159 this.bttnDelete.Enabled = false;
160 this.bttnDelete.ImageIndex = 1;
161 this.bttnDelete.Name = "bttnDelete";
162 //
87 // treeView 163 // treeView
88 // 164 //
89 this.treeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 165 this.treeView.Anchor = ((System.Windows.Forms.AnchorStyles) ((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
90 | System.Windows.Forms.AnchorStyles.Left) 166 | System.Windows.Forms.AnchorStyles.Left)
91 | System.Windows.Forms.AnchorStyles.Right))); 167 | System.Windows.Forms.AnchorStyles.Right)));
92 this.treeView.ContextMenu = this.contextMenu; 168 this.treeView.ContextMenu = this.contextMenu;
93 this.treeView.FullRowSelect = true; 169 this.treeView.FullRowSelect = true;
94 this.treeView.ImageIndex = -1; 170 this.treeView.Location = new System.Drawing.Point(0, 28);
95 this.treeView.Location = new System.Drawing.Point(0, 0);
96 this.treeView.Name = "treeView"; 171 this.treeView.Name = "treeView";
97 this.treeView.SelectedImageIndex = -1; 172 this.treeView.Size = new System.Drawing.Size(240, 250);
98 this.treeView.Size = new System.Drawing.Size(240, 278);
99 this.treeView.TabIndex = 0; 173 this.treeView.TabIndex = 0;
174 this.treeView.DoubleClick += new System.EventHandler(this.treeView_DoubleClick);
175 this.treeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView_AfterSelect);
100 this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseDown); 176 this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseDown);
101 this.treeView.DoubleClick += new System.EventHandler(this.treeView_DoubleClick);
102 //
103 // contextMenu
104 //
105 this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
106 this.miEdit,
107 this.miDelete});
108 this.contextMenu.Popup += new System.EventHandler(this.contextMenu_Popup);
109 //
110 // miEdit
111 //
112 this.miEdit.Index = 0;
113 this.miEdit.Text = "&Edit unit";
114 this.miEdit.Click += new System.EventHandler(this.miEdit_Click);
115 //
116 // miDelete
117 //
118 this.miDelete.Index = 1;
119 this.miDelete.Text = "&Delete unit";
120 this.miDelete.Click += new System.EventHandler(this.miDelete_Click);
121 // 177 //
122 // FrmArmyTree 178 // FrmArmyTree
123 // 179 //
124 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); 180 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
125 this.ClientSize = new System.Drawing.Size(240, 277); 181 this.ClientSize = new System.Drawing.Size(240, 277);
126 this.ControlBox = false; 182 this.ControlBox = false;
183 this.Controls.Add(this.toolBar);
127 this.Controls.Add(this.treeView); 184 this.Controls.Add(this.treeView);
128 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; 185 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
129 this.MaximizeBox = false; 186 this.MaximizeBox = false;
130 this.MinimizeBox = false; 187 this.MinimizeBox = false;
131 this.Name = "FrmArmyTree"; 188 this.Name = "FrmArmyTree";
132 this.Text = "FrmArmyTree"; 189 this.Text = "FrmArmyTree";
133 this.ResumeLayout(false); 190 this.ResumeLayout(false);
191 this.PerformLayout();
134 192
135 } 193 }
136 #endregion 194 #endregion
137 195
138 private void ClearArmy() 196 private void ClearArmy()
255 313
256 314
257 private void contextMenu_Popup(object sender, System.EventArgs e) 315 private void contextMenu_Popup(object sender, System.EventArgs e)
258 { 316 {
259 TreeNode node = treeView.SelectedNode; 317 TreeNode node = treeView.SelectedNode;
318
260 if (node!=null && node.Tag is Unit) 319 if (node!=null && node.Tag is Unit)
261 { 320 {
262 foreach(MenuItem item in contextMenu.MenuItems) 321 foreach(MenuItem item in contextMenu.MenuItems)
263 { 322 {
264 item.Visible = true; 323 item.Visible = true;
290 } 349 }
291 } 350 }
292 351
293 private void miDelete_Click(object sender, System.EventArgs e) 352 private void miDelete_Click(object sender, System.EventArgs e)
294 { 353 {
354 DeleteUnit();
355 }
356
357 private void DeleteUnit()
358 {
359
295 TreeNode selected = treeView.SelectedNode; 360 TreeNode selected = treeView.SelectedNode;
296 361
297 if (selected.Tag!=null && selected.Tag is Unit) 362 if (selected.Tag != null && selected.Tag is Unit)
298 { 363 {
299 Unit unit = (Unit)selected.Tag; 364 Unit unit = (Unit) selected.Tag;
300 commandStack.Execute(new RemoveUnitCommand(unit)); 365 commandStack.Execute(new RemoveUnitCommand(unit));
301 } 366 }
302 } 367 }
303 368
304 private void miEdit_Click(object sender, System.EventArgs e) 369 private void miEdit_Click(object sender, System.EventArgs e)
380 if (node!=null) 445 if (node!=null)
381 { 446 {
382 node.Text = obj.Name; 447 node.Text = obj.Name;
383 } 448 }
384 } 449 }
450
451 private void toolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
452 {
453 if (e.Button == bttnDelete)
454 {
455 DeleteUnit();
456 }
457 else if (e.Button == bttnEdit)
458 {
459 EditUnit();
460 }
461 }
462
463 private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
464 {
465 TreeNode node = treeView.SelectedNode;
466
467 bttnDelete.Enabled = (node != null && node.Tag is Unit);
468 bttnEdit.Enabled = bttnDelete.Enabled;
469 }
385 } 470 }
386 } 471 }