mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-10 07:04:36 +00:00
Add tree node parent/child moving for pane hierarchy.
This commit is contained in:
parent
6eabbda19b
commit
a62f1b8a07
2 changed files with 78 additions and 0 deletions
|
@ -33,6 +33,7 @@
|
|||
//
|
||||
// treeView1
|
||||
//
|
||||
this.treeView1.AllowDrop = true;
|
||||
this.treeView1.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||||
this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.treeView1.Location = new System.Drawing.Point(0, 0);
|
||||
|
@ -41,9 +42,12 @@
|
|||
this.treeView1.TabIndex = 0;
|
||||
this.treeView1.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterCheck);
|
||||
this.treeView1.BeforeExpand += new System.Windows.Forms.TreeViewCancelEventHandler(this.treeView1_BeforeExpand);
|
||||
this.treeView1.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.treeView1_ItemDrag);
|
||||
this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
|
||||
this.treeView1.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeView1_NodeMouseClick);
|
||||
this.treeView1.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.treeView1_NodeMouseDoubleClick);
|
||||
this.treeView1.DragDrop += new System.Windows.Forms.DragEventHandler(this.treeView1_DragDrop);
|
||||
this.treeView1.DragEnter += new System.Windows.Forms.DragEventHandler(this.treeView1_DragEnter);
|
||||
this.treeView1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.treeView1_KeyDown);
|
||||
this.treeView1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.treeView1_MouseClick);
|
||||
//
|
||||
|
|
|
@ -364,5 +364,79 @@ namespace LayoutBXLYT
|
|||
ParentEditor.ShowPaneEditor(e.Node.Tag as BasePane);
|
||||
}
|
||||
}
|
||||
|
||||
private void treeView1_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (e.Data.GetDataPresent(typeof(PaneTreeWrapper)))
|
||||
{
|
||||
Point targetPoint = treeView1.PointToClient(new Point(e.X, e.Y));
|
||||
|
||||
TreeNode targetNode = treeView1.GetNodeAt(targetPoint);
|
||||
TreeNode draggedNode = (PaneTreeWrapper)e.Data.GetData(typeof(PaneTreeWrapper));
|
||||
|
||||
Console.WriteLine("draggedPane " + draggedNode.Text);
|
||||
Console.WriteLine("draggedPane is pane? " + (draggedNode.Tag is BasePane));
|
||||
|
||||
var draggedPane = draggedNode.Tag as BasePane;
|
||||
if (draggedPane == null || draggedPane.IsRoot)
|
||||
return;
|
||||
|
||||
TreeNode parentNode = targetNode;
|
||||
|
||||
if (targetNode != null && targetNode.Parent != null)
|
||||
{
|
||||
bool canDrop = true;
|
||||
while (canDrop && (parentNode != null))
|
||||
{
|
||||
canDrop = !Object.ReferenceEquals(draggedNode, parentNode);
|
||||
parentNode = parentNode.Parent;
|
||||
}
|
||||
|
||||
if (!canDrop) return;
|
||||
|
||||
bool isTargetParent = targetNode.Equals(draggedNode.Parent);
|
||||
|
||||
//Remove it's previous parent
|
||||
draggedPane.Parent.Childern.Remove(draggedPane);
|
||||
draggedNode.Remove();
|
||||
|
||||
//Adjust the parent to the parent's parent
|
||||
Console.WriteLine("isTargetParent " + isTargetParent);
|
||||
if (isTargetParent)
|
||||
{
|
||||
var parentPane = targetNode.Tag as BasePane;
|
||||
if (parentPane.IsRoot) return;
|
||||
|
||||
var upperParentNode = targetNode.Parent;
|
||||
var upperParentPane = upperParentNode.Tag as BasePane;
|
||||
|
||||
draggedPane.Parent = upperParentPane;
|
||||
upperParentPane.Childern.Add(draggedPane);
|
||||
|
||||
upperParentNode.Nodes.Add(draggedNode);
|
||||
upperParentNode.Expand();
|
||||
}
|
||||
else //Set the target node as the parent
|
||||
{
|
||||
var parentPane = targetNode.Tag as BasePane;
|
||||
draggedPane.Parent = parentPane;
|
||||
parentPane.Childern.Add(draggedPane);
|
||||
|
||||
targetNode.Nodes.Add(draggedNode);
|
||||
targetNode.Expand();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void treeView1_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
e.Effect = DragDropEffects.Move;
|
||||
}
|
||||
|
||||
private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
|
||||
{
|
||||
DoDragDrop(e.Item, DragDropEffects.Move);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue