Persist collapsed nodes (#222)
Signed-off-by: chitza <chitza@gmail.com>
This commit is contained in:
@@ -87,6 +87,7 @@
|
||||
<Compile Include="..\LibreHardwareMonitorLib\Properties\AssemblyVersion.cs">
|
||||
<Link>Properties\AssemblyVersion.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="UI\IExpandPersistNode.cs" />
|
||||
<Compile Include="UI\ScaledPlotModel.cs" />
|
||||
<Compile Include="UI\GadgetWindow.cs" />
|
||||
<Compile Include="UI\Gadget.cs" />
|
||||
|
||||
@@ -4,18 +4,20 @@
|
||||
// Partial Copyright (C) Michael Möller <mmoeller@openhardwaremonitor.org> and Contributors.
|
||||
// All Rights Reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LibreHardwareMonitor.Hardware;
|
||||
using LibreHardwareMonitor.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LibreHardwareMonitor.UI
|
||||
{
|
||||
public class HardwareNode : Node
|
||||
public class HardwareNode : Node, IExpandPersistNode
|
||||
{
|
||||
private readonly PersistentSettings _settings;
|
||||
private readonly UnitManager _unitManager;
|
||||
private readonly List<TypeNode> _typeNodes = new List<TypeNode>();
|
||||
private readonly string _expandedIdentifier;
|
||||
private bool _expanded;
|
||||
|
||||
public event EventHandler PlotSelectionChanged;
|
||||
|
||||
@@ -23,19 +25,23 @@ namespace LibreHardwareMonitor.UI
|
||||
{
|
||||
_settings = settings;
|
||||
_unitManager = unitManager;
|
||||
_expandedIdentifier = new Identifier(hardware.Identifier, "expanded").ToString();
|
||||
Hardware = hardware;
|
||||
Image = HardwareTypeImage.Instance.GetImage(hardware.HardwareType);
|
||||
|
||||
foreach (SensorType sensorType in Enum.GetValues(typeof(SensorType)))
|
||||
_typeNodes.Add(new TypeNode(sensorType));
|
||||
_typeNodes.Add(new TypeNode(sensorType, hardware.Identifier, _settings));
|
||||
|
||||
foreach (ISensor sensor in hardware.Sensors)
|
||||
SensorAdded(sensor);
|
||||
|
||||
hardware.SensorAdded += SensorAdded;
|
||||
hardware.SensorRemoved += SensorRemoved;
|
||||
|
||||
_expanded = settings.GetValue(_expandedIdentifier, true);
|
||||
}
|
||||
|
||||
|
||||
public override string Text
|
||||
{
|
||||
get { return Hardware.Name; }
|
||||
@@ -44,6 +50,16 @@ namespace LibreHardwareMonitor.UI
|
||||
|
||||
public IHardware Hardware { get; }
|
||||
|
||||
public bool Expanded
|
||||
{
|
||||
get => _expanded;
|
||||
set
|
||||
{
|
||||
_expanded = value;
|
||||
_settings.SetValue(_expandedIdentifier, _expanded);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateNode(TypeNode node)
|
||||
{
|
||||
if (node.Nodes.Count > 0)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace LibreHardwareMonitor.UI
|
||||
{
|
||||
public interface IExpandPersistNode
|
||||
{
|
||||
bool Expanded { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public 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/.
|
||||
// Copyright (C) LibreHardwareMonitor and Contributors.
|
||||
// Partial Copyright (C) Michael Möller <mmoeller@openhardwaremonitor.org> and Contributors.
|
||||
// Partial Copyright (C) Michael Möller <mmoeller@openhardwaremonitor.org> and Contributors.
|
||||
// All Rights Reserved.
|
||||
|
||||
using System;
|
||||
@@ -9,13 +9,15 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
using Aga.Controls.Tree;
|
||||
using Aga.Controls.Tree.NodeControls;
|
||||
using LibreHardwareMonitor.Hardware;
|
||||
using LibreHardwareMonitor.Wmi;
|
||||
using LibreHardwareMonitor.Utilities;
|
||||
using LibreHardwareMonitor.Wmi;
|
||||
|
||||
|
||||
namespace LibreHardwareMonitor.UI
|
||||
{
|
||||
@@ -630,6 +632,8 @@ namespace LibreHardwareMonitor.UI
|
||||
|
||||
if (_delayCount < 4)
|
||||
_delayCount++;
|
||||
|
||||
RestoreCollapsedNodeState(treeView);
|
||||
}
|
||||
|
||||
private void SaveConfiguration()
|
||||
@@ -687,9 +691,25 @@ namespace LibreHardwareMonitor.UI
|
||||
newBounds.Y = (Screen.PrimaryScreen.WorkingArea.Height / 2) - (newBounds.Height / 2);
|
||||
}
|
||||
Bounds = newBounds;
|
||||
|
||||
RestoreCollapsedNodeState(treeView);
|
||||
|
||||
FormClosed += MainForm_FormClosed;
|
||||
}
|
||||
|
||||
private void RestoreCollapsedNodeState(TreeViewAdv treeViewAdv)
|
||||
{
|
||||
var collapsedHwNodes = treeViewAdv.AllNodes
|
||||
.Where(n => n.IsExpanded && n.Tag is IExpandPersistNode expandPersistNode && !expandPersistNode.Expanded)
|
||||
.OrderByDescending(n => n.Level)
|
||||
.ToList();
|
||||
|
||||
foreach (TreeNodeAdv node in collapsedHwNodes)
|
||||
{
|
||||
node.IsExpanded = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void CloseApplication()
|
||||
{
|
||||
FormClosed -= MainForm_FormClosed;
|
||||
@@ -718,10 +738,20 @@ namespace LibreHardwareMonitor.UI
|
||||
|
||||
private void TreeView_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!(e is MouseEventArgs m) || m.Button != MouseButtons.Right)
|
||||
if (!(e is MouseEventArgs m) || (m.Button != MouseButtons.Left && m.Button != MouseButtons.Right))
|
||||
return;
|
||||
|
||||
NodeControlInfo info = treeView.GetNodeControlInfoAt(new Point(m.X, m.Y));
|
||||
if (m.Button == MouseButtons.Left && info.Node != null)
|
||||
{
|
||||
if (info.Node.Tag is IExpandPersistNode expandPersistNode)
|
||||
{
|
||||
expandPersistNode.Expanded = info.Node.IsExpanded;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
treeView.SelectedNode = info.Node;
|
||||
if (info.Node != null)
|
||||
{
|
||||
|
||||
@@ -5,14 +5,21 @@
|
||||
// All Rights Reserved.
|
||||
|
||||
using LibreHardwareMonitor.Hardware;
|
||||
using LibreHardwareMonitor.Utilities;
|
||||
|
||||
namespace LibreHardwareMonitor.UI
|
||||
{
|
||||
public sealed class TypeNode : Node
|
||||
public sealed class TypeNode : Node, IExpandPersistNode
|
||||
{
|
||||
public TypeNode(SensorType sensorType)
|
||||
private readonly PersistentSettings _settings;
|
||||
private readonly string _expandedIdentifier;
|
||||
private bool _expanded;
|
||||
|
||||
public TypeNode(SensorType sensorType, Identifier parentId, PersistentSettings settings)
|
||||
{
|
||||
SensorType = sensorType;
|
||||
_expandedIdentifier = new Identifier(parentId, SensorType.ToString(), ".expanded").ToString();
|
||||
_settings = settings;
|
||||
|
||||
switch (sensorType)
|
||||
{
|
||||
@@ -76,6 +83,7 @@ namespace LibreHardwareMonitor.UI
|
||||
|
||||
NodeAdded += TypeNode_NodeAdded;
|
||||
NodeRemoved += TypeNode_NodeRemoved;
|
||||
_expanded = settings.GetValue(_expandedIdentifier, true);
|
||||
}
|
||||
|
||||
private void TypeNode_NodeRemoved(Node node)
|
||||
@@ -104,5 +112,15 @@ namespace LibreHardwareMonitor.UI
|
||||
}
|
||||
|
||||
public SensorType SensorType { get; }
|
||||
|
||||
public bool Expanded
|
||||
{
|
||||
get => _expanded;
|
||||
set
|
||||
{
|
||||
_expanded = value;
|
||||
_settings.SetValue(_expandedIdentifier, _expanded);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user