Drag and drop now working

This commit is contained in:
David Sparer
2016-09-08 10:50:47 -06:00
parent 092171982b
commit 5f8d274b94
2 changed files with 35 additions and 1 deletions

View File

@@ -112,6 +112,8 @@ namespace mRemoteNG.UI.Window
this.olvConnections.Cursor = System.Windows.Forms.Cursors.Default;
this.olvConnections.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
this.olvConnections.HideSelection = false;
this.olvConnections.IsSimpleDragSource = true;
this.olvConnections.IsSimpleDropSink = true;
this.olvConnections.LabelEdit = true;
this.olvConnections.Location = new System.Drawing.Point(0, 0);
this.olvConnections.MultiSelect = false;

View File

@@ -98,9 +98,13 @@ namespace mRemoteNG.UI.Window
olvConnections.CellClick += tvConnections_NodeMouseSingleClick;
olvConnections.CellClick += tvConnections_NodeMouseDoubleClick;
olvConnections.CellToolTipShowing += tvConnections_CellToolTipShowing;
olvConnections.ModelCanDrop += OlvConnections_OnModelCanDrop;
olvConnections.ModelDropped += OlvConnections_OnModelDropped;
}
private void PopulateTreeView()
{
olvConnections.Roots = ConnectionTreeModel.RootNodes;
@@ -432,6 +436,34 @@ namespace mRemoteNG.UI.Window
#endregion
#region Drag and Drop
private void OlvConnections_OnModelCanDrop(object sender, ModelDropEventArgs e)
{
var draggedObject = e.SourceModels[0] as ConnectionInfo;
if (!NodeIsDraggable(draggedObject)) return;
var dropTarget = e.TargetModel as ContainerInfo;
if (dropTarget != null)
e.Effect = DragDropEffects.Move;
else
{
e.Effect = DragDropEffects.None;
}
}
private bool NodeIsDraggable(ConnectionInfo node)
{
if (node == null || node is RootNodeInfo || node is PuttySessionInfo) return false;
return true;
}
private void OlvConnections_OnModelDropped(object sender, ModelDropEventArgs e)
{
var draggedObject = (IHasParent)e.SourceModels[0];
var dropTarget = e.TargetModel as ContainerInfo;
if (dropTarget != null)
draggedObject.SetParent(dropTarget);
e.RefreshObjects();
}
//TODO Fix for TreeListView
private static void tvConnections_DragDrop(object sender, DragEventArgs e)
{