2019-04-18 20:04:58 +00:00
|
|
|
|
using bzit.bomg.Models;
|
|
|
|
|
using System;
|
2019-04-16 20:57:31 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace RyzStudio.Windows.Forms
|
|
|
|
|
{
|
2019-04-18 20:04:58 +00:00
|
|
|
|
public class BookmarkTreeViewSNode
|
2019-04-16 20:57:31 +00:00
|
|
|
|
{
|
2019-04-18 20:04:58 +00:00
|
|
|
|
protected BookmarkTreeView Treeview = null;
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2019-04-18 20:04:58 +00:00
|
|
|
|
public BookmarkTreeViewSNode(BookmarkTreeView treeview)
|
2019-04-16 20:57:31 +00:00
|
|
|
|
{
|
|
|
|
|
Treeview = treeview;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-18 20:04:58 +00:00
|
|
|
|
protected TreeNode SelectedNode
|
|
|
|
|
{
|
|
|
|
|
get => this.Treeview.SelectedNode;
|
|
|
|
|
set => this.Treeview.SelectedNode = value;
|
|
|
|
|
}
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2019-04-20 16:05:55 +00:00
|
|
|
|
public TreeNode AddFolder() => this.Treeview.AddFolder(this.SelectedNode);
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
2019-04-20 16:05:55 +00:00
|
|
|
|
public TreeNode AddFolder(string name) => this.Treeview.AddFolder(this.SelectedNode, name);
|
2019-04-16 20:57:31 +00:00
|
|
|
|
|
|
|
|
|
public TreeNode AddItem(string name, object tag)
|
|
|
|
|
{
|
|
|
|
|
if (this.SelectedNode == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.SelectedNode.Tag != null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-18 20:04:58 +00:00
|
|
|
|
TreeNode tn = new TreeNode(name, (int)BookmarkTreeView.IconSet.Default, (int)BookmarkTreeView.IconSet.Default);
|
2019-04-16 20:57:31 +00:00
|
|
|
|
tn.Tag = tag;
|
|
|
|
|
|
|
|
|
|
this.SelectedNode.Nodes.Add(tn);
|
|
|
|
|
|
|
|
|
|
return tn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Delete()
|
|
|
|
|
{
|
|
|
|
|
if (this.SelectedNode == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.Treeview.Nodes.Count <= 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.SelectedNode.Equals(this.Treeview.Nodes[0]))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.SelectedNode.Remove();
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-18 20:04:58 +00:00
|
|
|
|
public void Edit()
|
|
|
|
|
{
|
|
|
|
|
if (this.SelectedNode == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.SelectedNode.IsEditing)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (this.GetNodeType())
|
|
|
|
|
{
|
|
|
|
|
case BookmarkTreeView.NodeType.Root:
|
|
|
|
|
case BookmarkTreeView.NodeType.Folder:
|
|
|
|
|
this.SelectedNode.BeginEdit();
|
|
|
|
|
break;
|
|
|
|
|
case BookmarkTreeView.NodeType.Page:
|
|
|
|
|
this.SelectedNode.BeginEdit();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//this.HasChanged = true;
|
|
|
|
|
|
|
|
|
|
//if (this.SelectedNode == null)
|
|
|
|
|
//{
|
|
|
|
|
// return;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//if (!this.SelectedNode.IsEditing)
|
|
|
|
|
//{
|
|
|
|
|
// allowBeginEdit = true;
|
|
|
|
|
// this.SelectedNode.BeginEdit();
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BookmarkTreeView.NodeType GetNodeType() => this.Treeview.GetNodeType(this.SelectedNode);
|
|
|
|
|
|
2019-04-20 16:05:55 +00:00
|
|
|
|
public BookmarkItemViewModel GetViewModel() => this.Treeview.GetViewModel(this.SelectedNode);
|
|
|
|
|
|
2019-04-16 20:57:31 +00:00
|
|
|
|
public void MoveDown()
|
|
|
|
|
{
|
|
|
|
|
if (this.SelectedNode == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TreeNode tn = this.SelectedNode;
|
|
|
|
|
if (tn.Parent == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TreeNode tn1 = tn.Parent;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MoveUp()
|
|
|
|
|
{
|
|
|
|
|
if (this.SelectedNode == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TreeNode tn = this.SelectedNode;
|
|
|
|
|
if (tn.Parent == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tn.Index <= 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int n = tn.Index - 1;
|
|
|
|
|
|
|
|
|
|
TreeNode tn1 = tn.Parent;
|
|
|
|
|
tn1.Nodes.Remove(tn);
|
|
|
|
|
tn1.Nodes.Insert(n, tn);
|
|
|
|
|
|
|
|
|
|
this.SelectedNode = tn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Sort()
|
|
|
|
|
{
|
|
|
|
|
if (this.SelectedNode == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string[] tnv = new string[0];
|
|
|
|
|
TreeNode[] tna = new TreeNode[0];
|
|
|
|
|
|
|
|
|
|
foreach (TreeNode tn2 in this.SelectedNode.Nodes)
|
|
|
|
|
{
|
|
|
|
|
Array.Resize(ref tna, (tna.Length + 1));
|
|
|
|
|
tna[(tna.Length - 1)] = tn2;
|
|
|
|
|
|
|
|
|
|
Array.Resize(ref tnv, (tnv.Length + 1));
|
|
|
|
|
tnv[(tnv.Length - 1)] = tn2.Text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Array.Sort(tnv, tna);
|
|
|
|
|
|
|
|
|
|
this.SelectedNode.Nodes.Clear();
|
|
|
|
|
|
|
|
|
|
foreach (TreeNode tn2 in tna)
|
|
|
|
|
{
|
|
|
|
|
this.SelectedNode.Nodes.Add(tn2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|