2017-07-30 11:59:34 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace RyzStudio.Windows.Forms
|
|
|
|
|
{
|
|
|
|
|
public class MovableTreeView : System.Windows.Forms.TreeView
|
|
|
|
|
{
|
2019-04-16 20:57:31 +00:00
|
|
|
|
public enum IconSet
|
|
|
|
|
{
|
|
|
|
|
Root = 0,
|
|
|
|
|
Folder1,
|
|
|
|
|
Folder2,
|
|
|
|
|
Default
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MovableTreeViewSelectedNode SNode { get; set; }
|
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
public delegate void NodeCountUpdated(ulong v);
|
|
|
|
|
|
|
|
|
|
public EventHandler OnChanged = null;
|
|
|
|
|
public NodeCountUpdated OnNodeCountUpdate = null;
|
|
|
|
|
|
|
|
|
|
protected const char pathSeparator = '|';
|
2019-04-16 20:57:31 +00:00
|
|
|
|
//protected const int folderImageIndex = 1;
|
|
|
|
|
//protected const int folderSelectedImageIndex = 2;
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
protected TreeNode draggingNode = null;
|
2017-07-30 11:59:34 +00:00
|
|
|
|
protected bool allowBeginEdit = false;
|
|
|
|
|
//// public int[] folderImageIndex = { 1, 2 };
|
|
|
|
|
protected ulong nodeCount = 0;
|
|
|
|
|
protected bool hasChanged = false;
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
public MovableTreeView()
|
|
|
|
|
{
|
2019-04-16 20:57:31 +00:00
|
|
|
|
this.SNode = new MovableTreeViewSelectedNode(this);
|
2017-07-30 11:59:34 +00:00
|
|
|
|
}
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
#region public properties
|
|
|
|
|
|
|
|
|
|
/* [Category("Data")]
|
|
|
|
|
public char CustomPathSeparator
|
|
|
|
|
{
|
|
|
|
|
get { return customPathSeparator; }
|
|
|
|
|
set { customPathSeparator = value; }
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
[Browsable(false)]
|
|
|
|
|
public TreeNode[] NodeList
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
TreeNode[] rv = new TreeNode[0];
|
|
|
|
|
if (this.Nodes.Count <= 0)
|
|
|
|
|
{
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
foreach (TreeNode tn in this.Nodes)
|
|
|
|
|
{
|
|
|
|
|
traverseNodeList(ref rv, tn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
//[Browsable(false)]
|
|
|
|
|
//public string[] NodeNameList
|
|
|
|
|
//{
|
|
|
|
|
// get
|
|
|
|
|
// {
|
|
|
|
|
// string[] rv = new string[0];
|
|
|
|
|
// if (this.Nodes.Count <= 0)
|
|
|
|
|
// {
|
|
|
|
|
// return rv;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// foreach (TreeNode tn in this.Nodes)
|
|
|
|
|
// {
|
|
|
|
|
// traverseNodeNameList(ref rv, tn);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// return rv;
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
[Browsable(false)]
|
|
|
|
|
public ulong NodeCount
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return nodeCount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Browsable(false)]
|
|
|
|
|
public ulong NodeCountCalc
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
ulong rv = 0;
|
|
|
|
|
if (this.Nodes.Count <= 0)
|
|
|
|
|
{
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
foreach (TreeNode tn in this.Nodes)
|
|
|
|
|
{
|
|
|
|
|
traverseNodeCount(ref rv, tn);
|
|
|
|
|
}
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Browsable(false)]
|
|
|
|
|
public bool HasChanged
|
|
|
|
|
{
|
|
|
|
|
get { return hasChanged; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
hasChanged = value;
|
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
OnChanged?.Invoke(null, null);
|
2017-07-30 11:59:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
#region public methods
|
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
//public TreeNode AddFolder()
|
|
|
|
|
//{
|
|
|
|
|
// return this.AddFolder("New Folder " + (new Random()).Next(10001, 99999).ToString());
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//public TreeNode AddFolder(string name)
|
|
|
|
|
//{
|
|
|
|
|
// if (this.SelectedNode == null)
|
|
|
|
|
// {
|
|
|
|
|
// return null;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if (this.SelectedNode.Tag != null)
|
|
|
|
|
// {
|
|
|
|
|
// return null;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// this.HasChanged = true;
|
|
|
|
|
|
|
|
|
|
// TreeNode tn = this.SelectedNode.Nodes.Add(PathEncode(name), name, folderImageIndex, folderSelectedImageIndex);
|
|
|
|
|
// this.SelectedNode = tn;
|
|
|
|
|
|
|
|
|
|
// OnAddFolderNode(tn);
|
|
|
|
|
|
|
|
|
|
// return tn;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//public TreeNode AddBookmarkPage()
|
|
|
|
|
//{
|
|
|
|
|
// return this.AddBookmarkPage("New Page " + (new Random()).Next(10001, 99999).ToString());
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//public TreeNode AddBookmarkPage(string name, int icon = 3)
|
|
|
|
|
//{
|
|
|
|
|
// if (this.SelectedNode == null)
|
|
|
|
|
// {
|
|
|
|
|
// return null;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if (this.SelectedNode.Tag != null)
|
|
|
|
|
// {
|
|
|
|
|
// return null;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// this.HasChanged = true;
|
|
|
|
|
|
|
|
|
|
// TreeNode tn = this.SelectedNode.Nodes.Add(PathEncode(name), name, icon, icon);
|
|
|
|
|
// tn.Tag = new object();
|
|
|
|
|
// tn.ToolTipText = name;
|
|
|
|
|
|
|
|
|
|
// nodeCount++;
|
|
|
|
|
// NodeCountUpdate(nodeCount);
|
|
|
|
|
|
|
|
|
|
// this.SelectedNode = tn;
|
|
|
|
|
|
|
|
|
|
// OnAddItemNode(tn);
|
|
|
|
|
// return tn;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//public TreeNode AddBookmarkPageFullPath(string name, int icon = 3)
|
|
|
|
|
//{
|
|
|
|
|
// if (this.Nodes.Count <= 0)
|
|
|
|
|
// {
|
|
|
|
|
// return null;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// this.HasChanged = true;
|
|
|
|
|
|
|
|
|
|
// TreeNode tn2;
|
|
|
|
|
// if (!name.Contains(pathSeparator.ToString()))
|
|
|
|
|
// {
|
|
|
|
|
// tn2 = this.Nodes[0].Nodes.Add(name, PathDecode(name), icon, icon);
|
|
|
|
|
// tn2.ToolTipText = name;
|
|
|
|
|
// nodeCount++;
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// tn2 = this.Nodes[0];
|
|
|
|
|
// string[] folders = name.Split(pathSeparator);
|
|
|
|
|
// for (int x = 0; x < (folders.Length - 1); x++)
|
|
|
|
|
// {
|
|
|
|
|
// string dr = folders[x].Trim();
|
|
|
|
|
// if (tn2.Nodes.ContainsKey(dr))
|
|
|
|
|
// {
|
|
|
|
|
// tn2 = tn2.Nodes[dr];
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// tn2 = tn2.Nodes.Add(dr, PathDecode(dr), folderImageIndex, folderSelectedImageIndex);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// string tm = folders[(folders.Length - 1)].Trim();
|
|
|
|
|
// tn2 = tn2.Nodes.Add(tm, PathDecode(tm), icon, icon);
|
|
|
|
|
// tn2.Tag = new object();
|
|
|
|
|
// tn2.ToolTipText = tm;
|
|
|
|
|
|
|
|
|
|
// nodeCount++;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// NodeCountUpdate(nodeCount);
|
|
|
|
|
|
|
|
|
|
// return tn2;
|
|
|
|
|
//}
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
public void EditNode()
|
2017-07-30 11:59:34 +00:00
|
|
|
|
{
|
2019-04-16 20:57:31 +00:00
|
|
|
|
this.HasChanged = true;
|
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
if (this.SelectedNode == null)
|
|
|
|
|
{
|
2019-04-16 20:57:31 +00:00
|
|
|
|
return;
|
2017-07-30 11:59:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
if (!this.SelectedNode.IsEditing)
|
2017-07-30 11:59:34 +00:00
|
|
|
|
{
|
2019-04-16 20:57:31 +00:00
|
|
|
|
allowBeginEdit = true;
|
|
|
|
|
this.SelectedNode.BeginEdit();
|
2017-07-30 11:59:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
//public void DeleteNode()
|
|
|
|
|
//{
|
|
|
|
|
// if (this.SelectedNode == null)
|
|
|
|
|
// {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
// if (this.Nodes.Count <= 0)
|
|
|
|
|
// {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
// if (this.SelectedNode.Equals(this.Nodes[0]))
|
|
|
|
|
// {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
// this.HasChanged = true;
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
// this.SelectedNode.Remove();
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
// if (this.SelectedNode.Tag == null)
|
|
|
|
|
// {
|
|
|
|
|
// nodeCount = this.NodeCountCalc;
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// nodeCount--;
|
|
|
|
|
// }
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
// NodeCountUpdate(nodeCount);
|
|
|
|
|
//}
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
//public void SortNode()
|
|
|
|
|
//{
|
|
|
|
|
// TreeNode tn = this.SelectedNode;
|
|
|
|
|
// string[] tnv = new string[0];
|
|
|
|
|
// TreeNode[] tna = new TreeNode[0];
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
// this.HasChanged = true;
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
// foreach (TreeNode tn2 in tn.Nodes)
|
|
|
|
|
// {
|
|
|
|
|
// Array.Resize(ref tna, (tna.Length + 1));
|
|
|
|
|
// tna[(tna.Length - 1)] = tn2;
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
// Array.Resize(ref tnv, (tnv.Length + 1));
|
|
|
|
|
// tnv[(tnv.Length - 1)] = tn2.Text;
|
|
|
|
|
// }
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
// Array.Sort(tnv, tna);
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
// tn.Nodes.Clear();
|
|
|
|
|
// foreach (TreeNode tn2 in tna)
|
|
|
|
|
// {
|
|
|
|
|
// tn.Nodes.Add(tn2);
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
//public void MoveNodeUp()
|
|
|
|
|
//{
|
|
|
|
|
// TreeNode tn = this.SelectedNode;
|
|
|
|
|
// if (tn.Parent == null)
|
|
|
|
|
// {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
// if (tn.Index == 0)
|
|
|
|
|
// {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
// this.HasChanged = true;
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
// int n = tn.Index - 1;
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
// TreeNode tn1 = tn.Parent;
|
|
|
|
|
// tn1.Nodes.Remove(tn);
|
|
|
|
|
// tn1.Nodes.Insert(n, tn);
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
// this.SelectedNode = tn;
|
|
|
|
|
//}
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
//public void MoveNodeDown()
|
|
|
|
|
//{
|
|
|
|
|
// TreeNode tn = this.SelectedNode;
|
|
|
|
|
// if (tn.Parent == null)
|
|
|
|
|
// {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
// TreeNode tn1 = tn.Parent;
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
// this.HasChanged = true;
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
// if (tn.Index >= (tn1.Nodes.Count - 1))
|
|
|
|
|
// {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// int n = tn.Index + 1;
|
|
|
|
|
|
|
|
|
|
// tn1.Nodes.Remove(tn);
|
|
|
|
|
// tn1.Nodes.Insert(n, tn);
|
|
|
|
|
|
|
|
|
|
// this.SelectedNode = tn;
|
|
|
|
|
//}
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
|
|
|
|
public string GetNodeFullPath(TreeNode node)
|
|
|
|
|
{
|
|
|
|
|
string rv = PathEncode(node.Text);
|
|
|
|
|
|
|
|
|
|
TreeNode tn = node;
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
tn = tn.Parent;
|
|
|
|
|
|
|
|
|
|
if (tn == null)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tn.Level == 0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
rv = PathEncode(tn.Text) + pathSeparator.ToString() + rv;
|
|
|
|
|
}
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool FindTextNode(TreeNode node, string term)
|
|
|
|
|
{
|
|
|
|
|
if (node == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.Nodes.Count <= 0)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
bool rt = false;
|
|
|
|
|
bool inclusive = false;
|
|
|
|
|
TreeNode tn = node;
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if (tn == null)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
if (inclusive)
|
|
|
|
|
{
|
|
|
|
|
if (tn.Text.ToLower().Contains(term.ToLower()))
|
|
|
|
|
{
|
|
|
|
|
this.SelectedNode = tn;
|
|
|
|
|
this.SelectedNode.EnsureVisible();
|
|
|
|
|
rt = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
if (tn.Nodes.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
tn = tn.Nodes[0];
|
|
|
|
|
inclusive = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (tn.NextNode != null)
|
|
|
|
|
{
|
|
|
|
|
tn = tn.NextNode;
|
|
|
|
|
inclusive = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
tn = tn.Parent;
|
|
|
|
|
if (tn == null)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tn.NextNode != null)
|
|
|
|
|
{
|
|
|
|
|
tn = tn.NextNode;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inclusive = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
return rt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
|
|
|
|
nodeCount = 0;
|
|
|
|
|
NodeCountUpdate(nodeCount);
|
|
|
|
|
this.Nodes.Clear();
|
|
|
|
|
|
|
|
|
|
this.HasChanged = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
#region integrated behaviour
|
|
|
|
|
|
|
|
|
|
protected override void OnItemDrag(ItemDragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnItemDrag(e);
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
draggingNode = (TreeNode)e.Item;
|
|
|
|
|
DoDragDrop(e.Item, DragDropEffects.Move);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDragDrop(DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnDragDrop(e);
|
|
|
|
|
|
|
|
|
|
if (draggingNode.Level <= 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TreeNode en = this.GetNodeAt(this.PointToClient(new Point(e.X, e.Y)));
|
|
|
|
|
if (en == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
if (isNodeChild(draggingNode, en))
|
2017-07-30 11:59:34 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TreeNode dn = draggingNode;
|
|
|
|
|
if (en.Tag == null)
|
|
|
|
|
{
|
|
|
|
|
dn.Parent.Nodes.Remove(dn);
|
|
|
|
|
en.Nodes.Insert(0, dn);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
en.Parent.Nodes.Remove(dn);
|
|
|
|
|
en.Parent.Nodes.Insert(en.Index + 1, dn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.HasChanged = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDragEnter(DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnDragEnter(e);
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
e.Effect = DragDropEffects.Move;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseDown(MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnMouseDown(e);
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
this.SelectedNode = this.GetNodeAt(e.Location);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDragOver(DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnDragOver(e);
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
this.SelectedNode = this.GetNodeAt(this.PointToClient(new Point(e.X, e.Y)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnBeforeLabelEdit(NodeLabelEditEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!allowBeginEdit)
|
|
|
|
|
{
|
|
|
|
|
e.CancelEdit = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.HasChanged = true;
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
base.OnBeforeLabelEdit(e);
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
if (e.Node == null)
|
|
|
|
|
{
|
|
|
|
|
e.CancelEdit = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (e.Node.Tag == null)
|
|
|
|
|
{
|
|
|
|
|
// do it
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
e.CancelEdit = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnAfterLabelEdit(NodeLabelEditEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnAfterLabelEdit(e);
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
if (e.Node.Tag == null)
|
|
|
|
|
{
|
|
|
|
|
if (e.Label == null)
|
|
|
|
|
{
|
|
|
|
|
e.CancelEdit = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (e.Label.Trim().Length <= 0)
|
|
|
|
|
{
|
|
|
|
|
e.CancelEdit = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
e.CancelEdit = true;
|
|
|
|
|
}
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
allowBeginEdit = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
TreeNode tn = this.SelectedNode;
|
|
|
|
|
if (tn == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
|
switch (e.KeyCode)
|
|
|
|
|
{
|
|
|
|
|
case Keys.Insert:
|
|
|
|
|
if (e.Modifiers == Keys.Shift)
|
|
|
|
|
{
|
2019-04-16 20:57:31 +00:00
|
|
|
|
this.SelectedNode = this.SNode.AddFolder();
|
2017-07-30 11:59:34 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-04-16 20:57:31 +00:00
|
|
|
|
//##AddBookmarkPage();
|
2017-07-30 11:59:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Delete:
|
|
|
|
|
if (!tn.IsEditing)
|
|
|
|
|
{
|
2019-04-16 20:57:31 +00:00
|
|
|
|
this.SNode.Delete();
|
2017-07-30 11:59:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case Keys.F2:
|
|
|
|
|
if (tn.Tag == null)
|
|
|
|
|
{
|
|
|
|
|
this.EditNode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Up:
|
|
|
|
|
if (e.Modifiers == Keys.Control)
|
|
|
|
|
{
|
2019-04-16 20:57:31 +00:00
|
|
|
|
this.SNode.MoveUp();
|
2017-07-30 11:59:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case Keys.Down:
|
|
|
|
|
if (e.Modifiers == Keys.Control)
|
|
|
|
|
{
|
2019-04-16 20:57:31 +00:00
|
|
|
|
this.SNode.MoveDown();
|
2017-07-30 11:59:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.OnPreviewKeyDown(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void NodeCountUpdate(ulong v)
|
|
|
|
|
{
|
|
|
|
|
this.OnNodeCountUpdate?.Invoke(v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
protected bool isNodeChild(TreeNode drag_node, TreeNode drop_node)
|
2017-07-30 11:59:34 +00:00
|
|
|
|
{
|
|
|
|
|
TreeNode tn = drop_node;
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if (tn.Parent == null)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tn.Equals(drag_node))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tn = tn.Parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void traverseNodeList(ref TreeNode[] results, TreeNode node)
|
|
|
|
|
{
|
|
|
|
|
foreach (TreeNode tn in node.Nodes)
|
|
|
|
|
{
|
|
|
|
|
if (tn.Tag == null)
|
|
|
|
|
{
|
|
|
|
|
traverseNodeList(ref results, tn);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Array.Resize(ref results, (results.Length + 1));
|
|
|
|
|
results[(results.Length - 1)] = tn;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
//protected void traverseNodeNameList(ref string[] results, TreeNode node)
|
|
|
|
|
//{
|
|
|
|
|
// foreach (TreeNode tn in node.Nodes)
|
|
|
|
|
// {
|
|
|
|
|
// if (tn.Tag == null)
|
|
|
|
|
// {
|
|
|
|
|
// traverseNodeNameList(ref results, tn);
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// Array.Resize(ref results, (results.Length + 1));
|
|
|
|
|
// results[(results.Length - 1)] = this.GetNodeFullPath(tn);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
|
|
|
|
protected void traverseNodeCount(ref ulong results, TreeNode node)
|
|
|
|
|
{
|
|
|
|
|
foreach (TreeNode tn in node.Nodes)
|
|
|
|
|
{
|
|
|
|
|
if (tn.Tag == null)
|
|
|
|
|
{
|
|
|
|
|
traverseNodeCount(ref results, tn);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
results++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void OnAddFolderNode(TreeNode node) { }
|
|
|
|
|
|
|
|
|
|
protected virtual void OnAddItemNode(TreeNode node) { }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////protected string PathEncode(string text) { return RyzStudio.String.EncodeTo64(text); }
|
|
|
|
|
//protected string PathDecode(string text) { return RyzStudio.String.DecodeFrom64(text); }
|
2019-04-16 20:57:31 +00:00
|
|
|
|
protected string PathEncode(string text) { return System.Web.HttpUtility.UrlEncode(text); }
|
2017-07-30 11:59:34 +00:00
|
|
|
|
protected string PathDecode(string text) { return System.Web.HttpUtility.UrlDecode(text); }
|
|
|
|
|
}
|
|
|
|
|
}
|