suspend tree model events during sort, since this can produce a lot of changes

This commit is contained in:
David Sparer
2018-06-25 15:15:46 -05:00
parent 284755f298
commit 3bdcf655fd
3 changed files with 16 additions and 1 deletions

View File

@@ -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");
}
}
}

View File

@@ -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);
}
}

View File

@@ -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>