From 3bdcf655fd5fefd6120abe9b030aa50795cca10d Mon Sep 17 00:00:00 2001 From: David Sparer Date: Mon, 25 Jun 2018 15:15:46 -0500 Subject: [PATCH] suspend tree model events during sort, since this can produce a lot of changes --- mRemoteV1/Config/Connections/SaveConnectionsOnEdit.cs | 4 ++++ mRemoteV1/Tree/ConnectionTreeModel.cs | 10 +++++++++- mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/mRemoteV1/Config/Connections/SaveConnectionsOnEdit.cs b/mRemoteV1/Config/Connections/SaveConnectionsOnEdit.cs index 91c76b983..6fa400563 100644 --- a/mRemoteV1/Config/Connections/SaveConnectionsOnEdit.cs +++ b/mRemoteV1/Config/Connections/SaveConnectionsOnEdit.cs @@ -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"); } } } diff --git a/mRemoteV1/Tree/ConnectionTreeModel.cs b/mRemoteV1/Tree/ConnectionTreeModel.cs index a4a16065e..a336aff4d 100644 --- a/mRemoteV1/Tree/ConnectionTreeModel.cs +++ b/mRemoteV1/Tree/ConnectionTreeModel.cs @@ -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 RootNodes { get; } = new List(); + 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); } } diff --git a/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs b/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs index e7ca75784..df8711c28 100644 --- a/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs +++ b/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs @@ -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; } ///