This repository has been archived on 2022-09-30. You can view files and clone it, but cannot push or open issues or pull requests.
bookmark-manager/Windows/Forms/BookmarkTreeViewSNode.cs

213 lines
5.0 KiB
C#

using bzit.bomg.Models;
using System;
using System.Windows.Forms;
namespace RyzStudio.Windows.Forms
{
public class BookmarkTreeViewSNode
{
protected BookmarkTreeView Treeview = null;
public BookmarkTreeViewSNode(BookmarkTreeView treeview)
{
Treeview = treeview;
}
protected TreeNode SelectedNode
{
get => this.Treeview.SelectedNode;
set => this.Treeview.SelectedNode = value;
}
protected string encodeName(string name) => Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(name));
public TreeNode AddFolder()
{
//return this.AddFolder("New Folder " + (new Random()).Next(10001, 99999).ToString());
return this.AddFolder("New Folder (" + DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ")");
}
public TreeNode AddFolder(string name)
{
if (this.SelectedNode == null)
{
return null;
}
if (this.SelectedNode.Tag != null)
{
return null;
}
return this.SelectedNode.Nodes.Add(encodeName(name), name, (int)BookmarkTreeView.IconSet.Folder1, (int)BookmarkTreeView.IconSet.Folder2);
}
public TreeNode AddItem(string name, object tag)
{
if (this.SelectedNode == null)
{
return null;
}
if (this.SelectedNode.Tag != null)
{
return null;
}
TreeNode tn = new TreeNode(name, (int)BookmarkTreeView.IconSet.Default, (int)BookmarkTreeView.IconSet.Default);
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();
}
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);
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);
}
}
}
}