mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-19 15:19:20 +08:00
suspend tree model events during sort, since this can produce a lot of changes
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using mRemoteNG.App;
|
||||
using mRemoteNG.Connection;
|
||||
using mRemoteNG.Messages;
|
||||
|
||||
namespace mRemoteNG.Config.Connections
|
||||
{
|
||||
@@ -46,6 +48,8 @@ namespace mRemoteNG.Config.Connections
|
||||
if (!mRemoteNG.Settings.Default.SaveConnectionsAfterEveryEdit)
|
||||
return;
|
||||
_connectionsService.SaveConnections();
|
||||
|
||||
Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, "Auto saved connections");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,11 @@ using mRemoteNG.Tree.Root;
|
||||
|
||||
namespace mRemoteNG.Tree
|
||||
{
|
||||
public sealed class ConnectionTreeModel : INotifyCollectionChanged, INotifyPropertyChanged
|
||||
public sealed class ConnectionTreeModel : INotifyCollectionChanged, INotifyPropertyChanged
|
||||
{
|
||||
public List<ContainerInfo> RootNodes { get; } = new List<ContainerInfo>();
|
||||
public bool SuspendingCollectionChangedEvents { get; set; }
|
||||
public bool SuspendingPropertyChangedEvents { get; set; }
|
||||
|
||||
public void AddRootNode(ContainerInfo rootNode)
|
||||
{
|
||||
@@ -66,6 +68,9 @@ namespace mRemoteNG.Tree
|
||||
public event NotifyCollectionChangedEventHandler CollectionChanged;
|
||||
private void RaiseCollectionChangedEvent(object sender, NotifyCollectionChangedEventArgs args)
|
||||
{
|
||||
if (SuspendingCollectionChangedEvents)
|
||||
return;
|
||||
|
||||
CollectionChanged?.Invoke(sender, args);
|
||||
}
|
||||
|
||||
@@ -73,6 +78,9 @@ namespace mRemoteNG.Tree
|
||||
|
||||
private void RaisePropertyChangedEvent(object sender, PropertyChangedEventArgs args)
|
||||
{
|
||||
if (SuspendingPropertyChangedEvents)
|
||||
return;
|
||||
|
||||
PropertyChanged?.Invoke(sender, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -311,11 +311,14 @@ namespace mRemoteNG.UI.Controls
|
||||
if (sortTarget == null)
|
||||
sortTarget = GetRootConnectionNode();
|
||||
|
||||
var wasSuspendingEvents = _connectionTreeModel.SuspendingCollectionChangedEvents;
|
||||
_connectionTreeModel.SuspendingCollectionChangedEvents = true;
|
||||
var sortTargetAsContainer = sortTarget as ContainerInfo;
|
||||
if (sortTargetAsContainer != null)
|
||||
sortTargetAsContainer.SortRecursive(sortDirection);
|
||||
else
|
||||
SelectedNode.Parent.SortRecursive(sortDirection);
|
||||
_connectionTreeModel.SuspendingCollectionChangedEvents = wasSuspendingEvents;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user