mirror of
https://github.com/mRemoteNG/mRemoteNG.git
synced 2026-02-17 22:11:48 +08:00
Sorting nodes now works (ascending/descending)
This commit is contained in:
@@ -2,7 +2,6 @@ using mRemoteNG.App.Info;
|
||||
using mRemoteNG.Config.Connections;
|
||||
using mRemoteNG.Connection;
|
||||
using mRemoteNG.Connection.Protocol;
|
||||
using mRemoteNG.Connection.Protocol.RDP;
|
||||
using mRemoteNG.Container;
|
||||
using mRemoteNG.Credential;
|
||||
using mRemoteNG.Messages;
|
||||
|
||||
33
mRemoteV1/Connection/ConnectionInfoComparer.cs
Normal file
33
mRemoteV1/Connection/ConnectionInfoComparer.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
|
||||
namespace mRemoteNG.Connection
|
||||
{
|
||||
public class ConnectionInfoComparer<TProperty> : IComparer<ConnectionInfo> where TProperty : IComparable<TProperty>
|
||||
{
|
||||
private readonly Func<ConnectionInfo, TProperty> _sortExpression;
|
||||
public ListSortDirection SortDirection { get; set; } = ListSortDirection.Ascending;
|
||||
|
||||
public ConnectionInfoComparer(Func<ConnectionInfo, TProperty> sortExpression)
|
||||
{
|
||||
_sortExpression = sortExpression;
|
||||
}
|
||||
|
||||
public int Compare(ConnectionInfo x, ConnectionInfo y)
|
||||
{
|
||||
return SortDirection == ListSortDirection.Ascending ? CompareAscending(x, y) : CompareDescending(x, y);
|
||||
}
|
||||
|
||||
private int CompareAscending(ConnectionInfo x, ConnectionInfo y)
|
||||
{
|
||||
return _sortExpression(x).CompareTo(_sortExpression(y));
|
||||
}
|
||||
|
||||
private int CompareDescending(ConnectionInfo x, ConnectionInfo y)
|
||||
{
|
||||
return _sortExpression(y).CompareTo(_sortExpression(x));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using mRemoteNG.Connection;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using mRemoteNG.Connection.Protocol;
|
||||
using mRemoteNG.Tools;
|
||||
using mRemoteNG.Tree;
|
||||
@@ -103,6 +107,34 @@ namespace mRemoteNG.Container
|
||||
SetChildPosition(child, originalIndex + 1);
|
||||
}
|
||||
|
||||
public void Sort(ListSortDirection sortDirection = ListSortDirection.Ascending)
|
||||
{
|
||||
SortOn(connectionInfo => connectionInfo.Name, sortDirection);
|
||||
}
|
||||
|
||||
public void SortOn<TProperty>(Func<ConnectionInfo, TProperty> propertyToCompare, ListSortDirection sortDirection = ListSortDirection.Ascending)
|
||||
where TProperty : IComparable<TProperty>
|
||||
{
|
||||
var connectionComparer = new ConnectionInfoComparer<TProperty>(propertyToCompare)
|
||||
{
|
||||
SortDirection = sortDirection
|
||||
};
|
||||
Children.Sort(connectionComparer);
|
||||
}
|
||||
|
||||
public void SortRecursive(ListSortDirection sortDirection = ListSortDirection.Ascending)
|
||||
{
|
||||
SortOnRecursive(connectionInfo => connectionInfo.Name, sortDirection);
|
||||
}
|
||||
|
||||
public void SortOnRecursive<TProperty>(Func<ConnectionInfo, TProperty> propertyToCompare, ListSortDirection sortDirection = ListSortDirection.Ascending)
|
||||
where TProperty : IComparable<TProperty>
|
||||
{
|
||||
foreach (var child in Children.OfType<ContainerInfo>())
|
||||
child.SortOnRecursive(propertyToCompare, sortDirection);
|
||||
SortOn(propertyToCompare, sortDirection);
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
var tempChildList = Children.ToArray();
|
||||
|
||||
@@ -188,7 +188,6 @@ namespace mRemoteNG.UI.Window
|
||||
this.mMenSortAscending.Image = global::mRemoteNG.Resources.Sort_AZ;
|
||||
this.mMenSortAscending.Name = "mMenSortAscending";
|
||||
this.mMenSortAscending.Size = new System.Drawing.Size(28, 20);
|
||||
this.mMenSortAscending.Click += new System.EventHandler(this.mMenSortAscending_Click);
|
||||
//
|
||||
// ConnectionTreeWindow
|
||||
//
|
||||
|
||||
@@ -3,6 +3,7 @@ using mRemoteNG.Connection;
|
||||
using mRemoteNG.Container;
|
||||
using mRemoteNG.Tree;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
@@ -18,9 +19,9 @@ namespace mRemoteNG.UI.Window
|
||||
public partial class ConnectionTreeWindow
|
||||
{
|
||||
private ConnectionTreeModel _connectionTreeModel;
|
||||
private ConnectionTreeDragAndDropHandler _dragAndDropHandler = new ConnectionTreeDragAndDropHandler();
|
||||
private readonly ConnectionTreeDragAndDropHandler _dragAndDropHandler = new ConnectionTreeDragAndDropHandler();
|
||||
private NodeSearcher _nodeSearcher;
|
||||
private ConnectionContextMenu _contextMenu = new ConnectionContextMenu();
|
||||
private readonly ConnectionContextMenu _contextMenu = new ConnectionContextMenu();
|
||||
|
||||
public ConnectionInfo SelectedNode => (ConnectionInfo) olvConnections.SelectedObject;
|
||||
|
||||
@@ -145,8 +146,8 @@ namespace mRemoteNG.UI.Window
|
||||
_contextMenu.ExportFileClicked += (sender, args) => Export.ExportToFile(Windows.treeForm.tvConnections.Nodes[0], Windows.treeForm.tvConnections.SelectedNode, Runtime.ConnectionTreeModel);
|
||||
_contextMenu.AddConnectionClicked += cMenTreeAddConnection_Click;
|
||||
_contextMenu.AddFolderClicked += cMenTreeAddFolder_Click;
|
||||
_contextMenu.SortAscendingClicked += cMenTreeToolsSortAscending_Click;
|
||||
_contextMenu.SortDescendingClicked += cMenTreeToolsSortDescending_Click;
|
||||
_contextMenu.SortAscendingClicked += (sender, args) => SortNodes(ListSortDirection.Ascending);
|
||||
_contextMenu.SortDescendingClicked += (sender, args) => SortNodes(ListSortDirection.Descending); ;
|
||||
_contextMenu.MoveUpClicked += cMenTreeMoveUp_Click;
|
||||
_contextMenu.MoveDownClicked += cMenTreeMoveDown_Click;
|
||||
_contextMenu.ExternalToolClicked += (sender, args) => StartExternalApp((ExternalTool)((ToolStripMenuItem)sender).Tag);
|
||||
@@ -160,7 +161,8 @@ namespace mRemoteNG.UI.Window
|
||||
olvConnections.CollapseAll();
|
||||
olvConnections.Expand(GetRootConnectionNode());
|
||||
};
|
||||
}
|
||||
mMenSortAscending.Click += (sender, args) => SortNodesRecursive(GetRootConnectionNode(), ListSortDirection.Ascending);
|
||||
}
|
||||
|
||||
private void PopulateTreeView()
|
||||
{
|
||||
@@ -404,32 +406,23 @@ namespace mRemoteNG.UI.Window
|
||||
Runtime.SaveConnectionsBG();
|
||||
}
|
||||
|
||||
//TODO Fix for TreeListView
|
||||
private void mMenSortAscending_Click(object sender, EventArgs e)
|
||||
{
|
||||
tvConnections.BeginUpdate();
|
||||
ConnectionTree.Sort(tvConnections.Nodes[0], SortOrder.Ascending);
|
||||
tvConnections.EndUpdate();
|
||||
private void SortNodes(ListSortDirection sortDirection)
|
||||
{
|
||||
var selectedNodeAsContainer = SelectedNode as ContainerInfo;
|
||||
if (selectedNodeAsContainer != null)
|
||||
selectedNodeAsContainer.Sort(sortDirection);
|
||||
else
|
||||
SelectedNode.Parent.Sort(sortDirection);
|
||||
olvConnections.RefreshObject(SelectedNode);
|
||||
Runtime.SaveConnectionsBG();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO Fix for TreeListView
|
||||
private void cMenTreeToolsSortAscending_Click(object sender, EventArgs e)
|
||||
{
|
||||
tvConnections.BeginUpdate();
|
||||
ConnectionTree.Sort(tvConnections.SelectedNode, SortOrder.Ascending);
|
||||
tvConnections.EndUpdate();
|
||||
private void SortNodesRecursive(ContainerInfo rootSortTarget, ListSortDirection sortDirection)
|
||||
{
|
||||
rootSortTarget.SortRecursive(sortDirection);
|
||||
olvConnections.RefreshObject(rootSortTarget);
|
||||
Runtime.SaveConnectionsBG();
|
||||
}
|
||||
|
||||
//TODO Fix for TreeListView
|
||||
private void cMenTreeToolsSortDescending_Click(object sender, EventArgs e)
|
||||
{
|
||||
tvConnections.BeginUpdate();
|
||||
ConnectionTree.Sort(tvConnections.SelectedNode, SortOrder.Descending);
|
||||
tvConnections.EndUpdate();
|
||||
Runtime.SaveConnectionsBG();
|
||||
}
|
||||
}
|
||||
|
||||
private void cMenTreeMoveUp_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
@@ -169,6 +169,7 @@
|
||||
<Compile Include="Config\Putty\Config.Putty.Provider.cs" />
|
||||
<Compile Include="Config\IDatabaseConnector.cs" />
|
||||
<Compile Include="Config\SqlDatabaseConnector.cs" />
|
||||
<Compile Include="Connection\ConnectionInfoComparer.cs" />
|
||||
<Compile Include="Connection\ConnectionInfoInheritance.cs" />
|
||||
<Compile Include="App\ProgramRoot.cs" />
|
||||
<Compile Include="Connection\ConnectionInitiator.cs" />
|
||||
|
||||
Reference in New Issue
Block a user