resize connection tree column width when calling expand all. related to #993

This commit is contained in:
David Sparer
2018-06-22 13:56:22 -05:00
parent da047427a5
commit 431c830ea0
2 changed files with 38 additions and 3 deletions

View File

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

View File

@@ -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);
}
/// <summary>
/// Expands all tree objects and recalculates the
/// column widths.
/// </summary>
public override void ExpandAll()
{
base.ExpandAll();
AutoResizeColumn(Columns[0]);
}
private void HandleCollectionChanged(object sender, NotifyCollectionChangedEventArgs args)
{
// disable filtering if necessary. prevents RefreshObjects from