mirror of
https://github.com/openhardwaremonitor/openhardwaremonitor
synced 2025-08-29 05:18:14 +00:00
Added code to persist and restore the expanded state of the tree view (hardware and type nodes).
This commit is contained in:
parent
bcb3186d49
commit
87c6f02d33
BIN
External/Aga.Controls.dll
vendored
BIN
External/Aga.Controls.dll
vendored
Binary file not shown.
1
External/Aga.Controls/Aga.Controls.csproj
vendored
1
External/Aga.Controls/Aga.Controls.csproj
vendored
@ -91,6 +91,7 @@
|
|||||||
<Compile Include="TimeCounter.cs" />
|
<Compile Include="TimeCounter.cs" />
|
||||||
<Compile Include="Tree\Input\ReorderColumnState.cs" />
|
<Compile Include="Tree\Input\ReorderColumnState.cs" />
|
||||||
<Compile Include="Tree\ListModel.cs" />
|
<Compile Include="Tree\ListModel.cs" />
|
||||||
|
<Compile Include="Tree\MemberAdapter.cs" />
|
||||||
<Compile Include="Tree\NodeControls\EditEventArgs.cs" />
|
<Compile Include="Tree\NodeControls\EditEventArgs.cs" />
|
||||||
<Compile Include="Tree\NodeControls\LabelEventArgs.cs" />
|
<Compile Include="Tree\NodeControls\LabelEventArgs.cs" />
|
||||||
<Compile Include="Tree\NodeControls\NodeIntegerTextBox.cs">
|
<Compile Include="Tree\NodeControls\NodeIntegerTextBox.cs">
|
||||||
|
62
External/Aga.Controls/Tree/MemberAdapter.cs
vendored
Normal file
62
External/Aga.Controls/Tree/MemberAdapter.cs
vendored
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Aga.Controls.Tree {
|
||||||
|
internal struct MemberAdapter
|
||||||
|
{
|
||||||
|
private object _obj;
|
||||||
|
private PropertyInfo _pi;
|
||||||
|
private FieldInfo _fi;
|
||||||
|
|
||||||
|
public static readonly MemberAdapter Empty = new MemberAdapter();
|
||||||
|
|
||||||
|
public Type MemberType
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_pi != null)
|
||||||
|
return _pi.PropertyType;
|
||||||
|
else if (_fi != null)
|
||||||
|
return _fi.FieldType;
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public object Value
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_pi != null && _pi.CanRead)
|
||||||
|
return _pi.GetValue(_obj, null);
|
||||||
|
else if (_fi != null)
|
||||||
|
return _fi.GetValue(_obj);
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_pi != null && _pi.CanWrite)
|
||||||
|
_pi.SetValue(_obj, value, null);
|
||||||
|
else if (_fi != null)
|
||||||
|
_fi.SetValue(_obj, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MemberAdapter(object obj, PropertyInfo pi)
|
||||||
|
{
|
||||||
|
_obj = obj;
|
||||||
|
_pi = pi;
|
||||||
|
_fi = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MemberAdapter(object obj, FieldInfo fi)
|
||||||
|
{
|
||||||
|
_obj = obj;
|
||||||
|
_fi = fi;
|
||||||
|
_pi = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,64 +6,10 @@ using System.ComponentModel;
|
|||||||
|
|
||||||
namespace Aga.Controls.Tree.NodeControls
|
namespace Aga.Controls.Tree.NodeControls
|
||||||
{
|
{
|
||||||
|
|
||||||
public abstract class BindableControl : NodeControl
|
public abstract class BindableControl : NodeControl
|
||||||
{
|
{
|
||||||
private struct MemberAdapter
|
|
||||||
{
|
|
||||||
private object _obj;
|
|
||||||
private PropertyInfo _pi;
|
|
||||||
private FieldInfo _fi;
|
|
||||||
|
|
||||||
public static readonly MemberAdapter Empty = new MemberAdapter();
|
|
||||||
|
|
||||||
public Type MemberType
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_pi != null)
|
|
||||||
return _pi.PropertyType;
|
|
||||||
else if (_fi != null)
|
|
||||||
return _fi.FieldType;
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public object Value
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_pi != null && _pi.CanRead)
|
|
||||||
return _pi.GetValue(_obj, null);
|
|
||||||
else if (_fi != null)
|
|
||||||
return _fi.GetValue(_obj);
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (_pi != null && _pi.CanWrite)
|
|
||||||
_pi.SetValue(_obj, value, null);
|
|
||||||
else if (_fi != null)
|
|
||||||
_fi.SetValue(_obj, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public MemberAdapter(object obj, PropertyInfo pi)
|
|
||||||
{
|
|
||||||
_obj = obj;
|
|
||||||
_pi = pi;
|
|
||||||
_fi = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MemberAdapter(object obj, FieldInfo fi)
|
|
||||||
{
|
|
||||||
_obj = obj;
|
|
||||||
_fi = fi;
|
|
||||||
_pi = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
|
|
||||||
private bool _virtualMode = false;
|
private bool _virtualMode = false;
|
||||||
|
36
External/Aga.Controls/Tree/TreeNodeAdv.cs
vendored
36
External/Aga.Controls/Tree/TreeNodeAdv.cs
vendored
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Reflection;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using System.Security.Permissions;
|
using System.Security.Permissions;
|
||||||
|
|
||||||
@ -205,7 +206,12 @@ namespace Aga.Controls.Tree
|
|||||||
|
|
||||||
internal void AssignIsExpanded(bool value)
|
internal void AssignIsExpanded(bool value)
|
||||||
{
|
{
|
||||||
_isExpanded = value;
|
if (_isExpanded != value)
|
||||||
|
{
|
||||||
|
_isExpanded = value;
|
||||||
|
var ma = GetMemberAdapter("IsExpanded");
|
||||||
|
ma.Value = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TreeNodeAdv _parent;
|
private TreeNodeAdv _parent;
|
||||||
@ -336,7 +342,7 @@ namespace Aga.Controls.Tree
|
|||||||
set { _isExpandingNow = value; }
|
set { _isExpandingNow = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _autoExpandOnStructureChanged = true;
|
private bool _autoExpandOnStructureChanged = false;
|
||||||
public bool AutoExpandOnStructureChanged
|
public bool AutoExpandOnStructureChanged
|
||||||
{
|
{
|
||||||
get { return _autoExpandOnStructureChanged; }
|
get { return _autoExpandOnStructureChanged; }
|
||||||
@ -357,6 +363,12 @@ namespace Aga.Controls.Tree
|
|||||||
_nodes = new NodeCollection(this);
|
_nodes = new NodeCollection(this);
|
||||||
_children = new ReadOnlyCollection<TreeNodeAdv>(_nodes);
|
_children = new ReadOnlyCollection<TreeNodeAdv>(_nodes);
|
||||||
_tag = tag;
|
_tag = tag;
|
||||||
|
|
||||||
|
var value = GetMemberAdapter("IsExpanded").Value;
|
||||||
|
if (value != null && value is bool)
|
||||||
|
{
|
||||||
|
_isExpanded = (bool)value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
@ -402,11 +414,29 @@ namespace Aga.Controls.Tree
|
|||||||
private void SetIsExpanded(bool value, bool ignoreChildren)
|
private void SetIsExpanded(bool value, bool ignoreChildren)
|
||||||
{
|
{
|
||||||
if (Tree == null)
|
if (Tree == null)
|
||||||
_isExpanded = value;
|
AssignIsExpanded(value);
|
||||||
else
|
else
|
||||||
Tree.SetIsExpanded(this, value, ignoreChildren);
|
Tree.SetIsExpanded(this, value, ignoreChildren);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MemberAdapter GetMemberAdapter(string propertyName)
|
||||||
|
{
|
||||||
|
if (this.Tag != null && !string.IsNullOrEmpty(propertyName))
|
||||||
|
{
|
||||||
|
Type type = this.Tag.GetType();
|
||||||
|
PropertyInfo pi = type.GetProperty(propertyName);
|
||||||
|
if (pi != null)
|
||||||
|
return new MemberAdapter(this.Tag, pi);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FieldInfo fi = type.GetField(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
|
||||||
|
if (fi != null)
|
||||||
|
return new MemberAdapter(this.Tag, fi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return MemberAdapter.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
#region ISerializable Members
|
#region ISerializable Members
|
||||||
|
|
||||||
private TreeNodeAdv(SerializationInfo info, StreamingContext context)
|
private TreeNodeAdv(SerializationInfo info, StreamingContext context)
|
||||||
|
@ -4,21 +4,21 @@
|
|||||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
|
Copyright (C) 2009-2020 Michael Möller <mmoeller@openhardwaremonitor.org>
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
|
||||||
using OpenHardwareMonitor.Hardware;
|
using OpenHardwareMonitor.Hardware;
|
||||||
|
|
||||||
namespace OpenHardwareMonitor.GUI {
|
namespace OpenHardwareMonitor.GUI {
|
||||||
public class HardwareNode : Node {
|
public class HardwareNode : Node {
|
||||||
|
|
||||||
private PersistentSettings settings;
|
private readonly PersistentSettings settings;
|
||||||
private UnitManager unitManager;
|
private readonly UnitManager unitManager;
|
||||||
private IHardware hardware;
|
private readonly IHardware hardware;
|
||||||
|
private readonly Identifier expandedIdentifier;
|
||||||
|
|
||||||
private List<TypeNode> typeNodes = new List<TypeNode>();
|
private List<TypeNode> typeNodes = new List<TypeNode>();
|
||||||
|
|
||||||
@ -31,13 +31,17 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
this.Image = HardwareTypeImage.Instance.GetImage(hardware.HardwareType);
|
this.Image = HardwareTypeImage.Instance.GetImage(hardware.HardwareType);
|
||||||
|
|
||||||
foreach (SensorType sensorType in Enum.GetValues(typeof(SensorType)))
|
foreach (SensorType sensorType in Enum.GetValues(typeof(SensorType)))
|
||||||
typeNodes.Add(new TypeNode(sensorType));
|
typeNodes.Add(new TypeNode(sensorType, hardware, settings));
|
||||||
|
|
||||||
foreach (ISensor sensor in hardware.Sensors)
|
foreach (ISensor sensor in hardware.Sensors)
|
||||||
SensorAdded(sensor);
|
SensorAdded(sensor);
|
||||||
|
|
||||||
hardware.SensorAdded +=new SensorEventHandler(SensorAdded);
|
hardware.SensorAdded +=new SensorEventHandler(SensorAdded);
|
||||||
hardware.SensorRemoved += new SensorEventHandler(SensorRemoved);
|
hardware.SensorRemoved += new SensorEventHandler(SensorRemoved);
|
||||||
|
|
||||||
|
this.expandedIdentifier = new Identifier(hardware.Identifier, "expanded");
|
||||||
|
base.IsExpanded =
|
||||||
|
settings.GetValue(expandedIdentifier.ToString(), base.IsExpanded);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string Text {
|
public override string Text {
|
||||||
@ -49,6 +53,18 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
get { return hardware; }
|
get { return hardware; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool IsExpanded {
|
||||||
|
get {
|
||||||
|
return base.IsExpanded;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if (base.IsExpanded != value) {
|
||||||
|
base.IsExpanded = value;
|
||||||
|
settings.SetValue(expandedIdentifier.ToString(), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateNode(TypeNode node) {
|
private void UpdateNode(TypeNode node) {
|
||||||
if (node.Nodes.Count > 0) {
|
if (node.Nodes.Count > 0) {
|
||||||
if (!Nodes.Contains(node)) {
|
if (!Nodes.Contains(node)) {
|
||||||
|
15
GUI/Node.cs
15
GUI/Node.cs
@ -4,7 +4,7 @@
|
|||||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
Copyright (C) 2009-2010 Michael Möller <mmoeller@openhardwaremonitor.org>
|
Copyright (C) 2009-2020 Michael Möller <mmoeller@openhardwaremonitor.org>
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -25,6 +25,7 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
private string text;
|
private string text;
|
||||||
private Image image;
|
private Image image;
|
||||||
private bool visible;
|
private bool visible;
|
||||||
|
private bool expanded;
|
||||||
|
|
||||||
private TreeModel RootTreeModel() {
|
private TreeModel RootTreeModel() {
|
||||||
Node node = this;
|
Node node = this;
|
||||||
@ -42,6 +43,7 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
this.text = text;
|
this.text = text;
|
||||||
this.nodes = new NodeCollection(this);
|
this.nodes = new NodeCollection(this);
|
||||||
this.visible = true;
|
this.visible = true;
|
||||||
|
this.expanded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TreeModel Model {
|
public TreeModel Model {
|
||||||
@ -83,6 +85,17 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual bool IsExpanded {
|
||||||
|
get {
|
||||||
|
return expanded;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if (value != expanded) {
|
||||||
|
expanded = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public virtual bool IsVisible {
|
public virtual bool IsVisible {
|
||||||
get { return visible; }
|
get { return visible; }
|
||||||
set {
|
set {
|
||||||
|
@ -4,21 +4,26 @@
|
|||||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
|
Copyright (C) 2009-2020 Michael Möller <mmoeller@openhardwaremonitor.org>
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using OpenHardwareMonitor.Hardware;
|
using OpenHardwareMonitor.Hardware;
|
||||||
|
|
||||||
namespace OpenHardwareMonitor.GUI {
|
namespace OpenHardwareMonitor.GUI {
|
||||||
public class TypeNode : Node {
|
public class TypeNode : Node {
|
||||||
|
|
||||||
private SensorType sensorType;
|
private readonly PersistentSettings settings;
|
||||||
|
private readonly SensorType sensorType;
|
||||||
|
private readonly IHardware hardware;
|
||||||
|
private readonly Identifier expandedIdentifier;
|
||||||
|
|
||||||
public TypeNode(SensorType sensorType) : base() {
|
public TypeNode(SensorType sensorType, IHardware hardware,
|
||||||
|
PersistentSettings settings) : base()
|
||||||
|
{
|
||||||
|
this.settings = settings;
|
||||||
this.sensorType = sensorType;
|
this.sensorType = sensorType;
|
||||||
|
this.hardware = hardware;
|
||||||
|
|
||||||
switch (sensorType) {
|
switch (sensorType) {
|
||||||
case SensorType.Voltage:
|
case SensorType.Voltage:
|
||||||
@ -77,6 +82,11 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
|
|
||||||
NodeAdded += new NodeEventHandler(TypeNode_NodeAdded);
|
NodeAdded += new NodeEventHandler(TypeNode_NodeAdded);
|
||||||
NodeRemoved += new NodeEventHandler(TypeNode_NodeRemoved);
|
NodeRemoved += new NodeEventHandler(TypeNode_NodeRemoved);
|
||||||
|
|
||||||
|
this.expandedIdentifier = new Identifier(new Identifier(hardware.Identifier,
|
||||||
|
sensorType.ToString().ToLowerInvariant()), "expanded");
|
||||||
|
base.IsExpanded =
|
||||||
|
settings.GetValue(expandedIdentifier.ToString(), base.IsExpanded);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TypeNode_NodeRemoved(Node node) {
|
private void TypeNode_NodeRemoved(Node node) {
|
||||||
@ -101,5 +111,17 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
public SensorType SensorType {
|
public SensorType SensorType {
|
||||||
get { return sensorType; }
|
get { return sensorType; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool IsExpanded {
|
||||||
|
get {
|
||||||
|
return base.IsExpanded;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if (base.IsExpanded != value) {
|
||||||
|
base.IsExpanded = value;
|
||||||
|
settings.SetValue(expandedIdentifier.ToString(), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user