!B (Sandbox) (CE-21795) Importing models with multisubmaterials via fbx switches...
[CRYENGINE.git] / Code / Tools / LuaRemoteDebugger / Aga.Controls / Tree / Node.cs
blobe1ce05090742e646829e68336a228d4fda7e2314
1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
3 using System;
4 using System.Collections.Generic;
5 using System.Text;
6 using System.Collections.ObjectModel;
7 using System.Windows.Forms;
8 using System.Drawing;
10 namespace Aga.Controls.Tree
12 public class Node
14 #region NodeCollection
16 private class NodeCollection : Collection<Node>
18 private Node _owner;
20 public NodeCollection(Node owner)
22 _owner = owner;
25 protected override void ClearItems()
27 while (this.Count != 0)
28 this.RemoveAt(this.Count - 1);
31 protected override void InsertItem(int index, Node item)
33 if (item == null)
34 throw new ArgumentNullException("item");
36 if (item.Parent != _owner)
38 if (item.Parent != null)
39 item.Parent.Nodes.Remove(item);
40 item._parent = _owner;
41 item._index = index;
42 for (int i = index; i < Count; i++)
43 this[i]._index++;
44 base.InsertItem(index, item);
46 TreeModel model = _owner.FindModel();
47 if (model != null)
48 model.OnNodeInserted(_owner, index, item);
52 protected override void RemoveItem(int index)
54 Node item = this[index];
55 item._parent = null;
56 item._index = -1;
57 for (int i = index + 1; i < Count; i++)
58 this[i]._index--;
59 base.RemoveItem(index);
61 TreeModel model = _owner.FindModel();
62 if (model != null)
63 model.OnNodeRemoved(_owner, index, item);
66 protected override void SetItem(int index, Node item)
68 if (item == null)
69 throw new ArgumentNullException("item");
71 RemoveAt(index);
72 InsertItem(index, item);
76 #endregion
78 #region Properties
80 private TreeModel _model;
81 internal TreeModel Model
83 get { return _model; }
84 set { _model = value; }
87 private NodeCollection _nodes;
88 public Collection<Node> Nodes
90 get { return _nodes; }
93 private Node _parent;
94 public Node Parent
96 get { return _parent; }
97 set
99 if (value != _parent)
101 if (_parent != null)
102 _parent.Nodes.Remove(this);
104 if (value != null)
105 value.Nodes.Add(this);
110 private int _index = -1;
111 public int Index
115 return _index;
119 public Node PreviousNode
123 int index = Index;
124 if (index > 0)
125 return _parent.Nodes[index - 1];
126 else
127 return null;
131 public Node NextNode
135 int index = Index;
136 if (index >= 0 && index < _parent.Nodes.Count - 1)
137 return _parent.Nodes[index + 1];
138 else
139 return null;
143 private string _text;
144 public virtual string Text
146 get { return _text; }
147 set
149 if (_text != value)
151 _text = value;
152 NotifyModel();
157 private CheckState _checkState;
158 public virtual CheckState CheckState
160 get { return _checkState; }
161 set
163 if (_checkState != value)
165 _checkState = value;
166 NotifyModel();
171 private Image _image;
172 public Image Image
174 get { return _image; }
175 set
177 if (_image != value)
179 _image = value;
180 NotifyModel();
185 private object _tag;
186 public object Tag
188 get { return _tag; }
189 set { _tag = value; }
192 public bool IsChecked
194 get
196 return CheckState != CheckState.Unchecked;
198 set
200 if (value)
201 CheckState = CheckState.Checked;
202 else
203 CheckState = CheckState.Unchecked;
207 public virtual bool IsLeaf
211 return false;
215 #endregion
217 public Node()
218 : this(string.Empty)
222 public Node(string text)
224 _text = text;
225 _nodes = new NodeCollection(this);
228 public override string ToString()
230 return Text;
233 private TreeModel FindModel()
235 Node node = this;
236 while (node != null)
238 if (node.Model != null)
239 return node.Model;
240 node = node.Parent;
242 return null;
245 protected void NotifyModel()
247 TreeModel model = FindModel();
248 if (model != null && Parent != null)
250 TreePath path = model.GetPath(Parent);
251 if (path != null)
253 TreeModelEventArgs args = new TreeModelEventArgs(path, new int[] { Index }, new object[] { this });
254 model.OnNodesChanged(args);