From 431c830ea03da07c2f0042383cf2c2e4ac511357 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Fri, 22 Jun 2018 13:56:22 -0500 Subject: [PATCH] resize connection tree column width when calling expand all. related to #993 --- .../UI/Controls/ConnectionTreeTests.cs | 29 +++++++++++++++++-- .../Controls/ConnectionTree/ConnectionTree.cs | 12 +++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/mRemoteNGTests/UI/Controls/ConnectionTreeTests.cs b/mRemoteNGTests/UI/Controls/ConnectionTreeTests.cs index ababe7b00..b6227d985 100644 --- a/mRemoteNGTests/UI/Controls/ConnectionTreeTests.cs +++ b/mRemoteNGTests/UI/Controls/ConnectionTreeTests.cs @@ -1,4 +1,5 @@ -using System.Threading; +using System.Linq; +using System.Threading; using mRemoteNG.Connection; using mRemoteNG.Container; using mRemoteNG.Tree; @@ -8,7 +9,7 @@ using NUnit.Framework; namespace mRemoteNGTests.UI.Controls { - public class ConnectionTreeTests + public class ConnectionTreeTests { private ConnectionTreeSearchTextFilter _filter; private ConnectionTree _connectionTree; @@ -159,5 +160,29 @@ namespace mRemoteNGTests.UI.Controls Assert.That(connectionTreeModel.RootNodes, Has.One.Items); } + + [Test] + [Apartment(ApartmentState.STA)] + public void ExpandingAllItemsUpdatesColumnWidthAppropriately() + { + var connectionTreeModel = new ConnectionTreeModel(); + var root = new RootNodeInfo(RootNodeType.Connection); + connectionTreeModel.AddRootNode(root); + ContainerInfo parent = root; + foreach (var i in Enumerable.Repeat("", 8)) + { + var newContainer = new ContainerInfo {IsExpanded = false}; + parent.AddChild(newContainer); + parent = newContainer; + } + + _connectionTree.ConnectionTreeModel = connectionTreeModel; + + var widthBefore = _connectionTree.Columns[0].Width; + _connectionTree.ExpandAll(); + var widthAfter = _connectionTree.Columns[0].Width; + + Assert.That(widthAfter, Is.GreaterThan(widthBefore)); + } } } diff --git a/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs b/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs index 94b59d486..abbe7efb0 100644 --- a/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs +++ b/mRemoteV1/UI/Controls/ConnectionTree/ConnectionTree.cs @@ -15,7 +15,7 @@ using mRemoteNG.Tree.Root; namespace mRemoteNG.UI.Controls { - public partial class ConnectionTree : TreeListView, IConnectionTree + public partial class ConnectionTree : TreeListView, IConnectionTree { private readonly ConnectionTreeDragAndDropHandler _dragAndDropHandler = new ConnectionTreeDragAndDropHandler(); private readonly PuttySessionsManager _puttySessionsManager = PuttySessionsManager.Instance; @@ -318,6 +318,16 @@ namespace mRemoteNG.UI.Controls SelectedNode.Parent.SortRecursive(sortDirection); } + /// + /// Expands all tree objects and recalculates the + /// column widths. + /// + public override void ExpandAll() + { + base.ExpandAll(); + AutoResizeColumn(Columns[0]); + } + private void HandleCollectionChanged(object sender, NotifyCollectionChangedEventArgs args) { // disable filtering if necessary. prevents RefreshObjects from