Refactored the SuperIOHardware class.
3 This Source Code Form is subject to the terms of the Mozilla Public
4 License, v. 2.0. If a copy of the MPL was not distributed with this
5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 Copyright (C) 2009-2010 Michael Möller <mmoeller@openhardwaremonitor.org>
13 using System.Collections.Generic;
14 using System.Collections.ObjectModel;
16 using Aga.Controls.Tree;
18 namespace OpenHardwareMonitor.GUI {
21 private TreeModel treeModel;
23 private NodeCollection nodes;
29 private TreeModel RootTreeModel() {
31 while (node != null) {
32 if (node.Model != null)
39 public Node() : this(string.Empty) { }
41 public Node(string text) {
43 this.nodes = new NodeCollection(this);
47 public TreeModel Model {
48 get { return treeModel; }
49 set { treeModel = value; }
53 get { return parent; }
55 if (value != parent) {
57 parent.nodes.Remove(this);
59 value.nodes.Add(this);
64 public Collection<Node> Nodes {
68 public virtual string Text {
86 public virtual bool IsVisible {
87 get { return visible; }
89 if (value != visible) {
91 TreeModel model = RootTreeModel();
92 if (model != null && parent != null) {
94 for (int i = 0; i < parent.nodes.Count; i++) {
95 Node node = parent.nodes[i];
98 if (node.IsVisible || model.ForceVisible)
101 if (model.ForceVisible) {
102 model.OnNodeChanged(parent, index, this);
105 model.OnNodeInserted(parent, index, this);
107 model.OnNodeRemoved(parent, index, this);
110 if (IsVisibleChanged != null)
111 IsVisibleChanged(this);
116 public delegate void NodeEventHandler(Node node);
118 public event NodeEventHandler IsVisibleChanged;
119 public event NodeEventHandler NodeAdded;
120 public event NodeEventHandler NodeRemoved;
122 private class NodeCollection : Collection<Node> {
125 public NodeCollection(Node owner) {
129 protected override void ClearItems() {
130 while (this.Count != 0)
131 this.RemoveAt(this.Count - 1);
134 protected override void InsertItem(int index, Node item) {
136 throw new ArgumentNullException("item");
138 if (item.parent != owner) {
139 if (item.parent != null)
140 item.parent.nodes.Remove(item);
142 base.InsertItem(index, item);
144 TreeModel model = owner.RootTreeModel();
146 model.OnStructureChanged(owner);
147 if (owner.NodeAdded != null)
148 owner.NodeAdded(item);
152 protected override void RemoveItem(int index) {
153 Node item = this[index];
155 base.RemoveItem(index);
157 TreeModel model = owner.RootTreeModel();
159 model.OnStructureChanged(owner);
160 if (owner.NodeRemoved != null)
161 owner.NodeRemoved(item);
164 protected override void SetItem(int index, Node item) {
166 throw new ArgumentNullException("item");
169 InsertItem(index, item);