282 lines
9.9 KiB
C#
282 lines
9.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using BukkuBuddy.DTOs.SaveFile;
|
|
using RyzStudio.Windows.Forms;
|
|
using RyzStudio.Windows.ThemedForms;
|
|
using RyzStudio.Windows.ThemedForms.ButtonTextBox;
|
|
|
|
namespace BukkuBuddy.Forms
|
|
{
|
|
public class FindForm : Form
|
|
{
|
|
private Label label1;
|
|
private ThButton button2;
|
|
private THorizontalSeparator horizontalSeparator1;
|
|
private ThButton button1;
|
|
private ThClearableTextBox textBox1;
|
|
|
|
|
|
private BookmarkTreeView treeView1 = null;
|
|
private int findPosition = -1;
|
|
|
|
|
|
public FindForm(BookmarkTreeView treeView)
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.MinimizeBox = false;
|
|
this.MaximizeBox = false;
|
|
this.ShowIcon = false;
|
|
this.ShowInTaskbar = true;
|
|
|
|
treeView1 = treeView;
|
|
|
|
textBox1.PreviewKeyDown += textBox1_PreviewKeyDown;
|
|
}
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
label1 = new Label();
|
|
button2 = new ThButton();
|
|
horizontalSeparator1 = new THorizontalSeparator();
|
|
textBox1 = new ThClearableTextBox();
|
|
button1 = new ThButton();
|
|
SuspendLayout();
|
|
//
|
|
// label1
|
|
//
|
|
label1.AutoSize = true;
|
|
label1.BackColor = System.Drawing.Color.Transparent;
|
|
label1.ForeColor = System.Drawing.SystemColors.ControlText;
|
|
label1.Location = new System.Drawing.Point(10, 20);
|
|
label1.Margin = new Padding(0);
|
|
label1.Name = "label1";
|
|
label1.Padding = new Padding(0, 9, 0, 10);
|
|
label1.Size = new System.Drawing.Size(30, 34);
|
|
label1.TabIndex = 153;
|
|
label1.Text = "Find";
|
|
label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
|
//
|
|
// button2
|
|
//
|
|
button2.ActiveImage = null;
|
|
button2.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
|
button2.BackColor = System.Drawing.Color.Transparent;
|
|
button2.EnableMenuOnClick = false;
|
|
button2.EnableMovable = false;
|
|
button2.HoverImage = null;
|
|
button2.IdleImage = null;
|
|
//
|
|
//
|
|
//
|
|
button2.Label.BackColor = System.Drawing.Color.White;
|
|
button2.Label.Dock = DockStyle.Fill;
|
|
button2.Label.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold);
|
|
button2.Label.ForeColor = System.Drawing.Color.FromArgb(126, 54, 244);
|
|
button2.Label.Location = new System.Drawing.Point(4, 4);
|
|
button2.Label.Margin = new Padding(0);
|
|
button2.Label.Name = "label1";
|
|
button2.Label.Size = new System.Drawing.Size(121, 25);
|
|
button2.Label.TabIndex = 0;
|
|
button2.Label.Text = "&Next";
|
|
button2.Label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
|
button2.LabelText = "&Next";
|
|
button2.Location = new System.Drawing.Point(246, 94);
|
|
button2.Name = "button2";
|
|
button2.Size = new System.Drawing.Size(128, 32);
|
|
button2.TabIndex = 2;
|
|
button2.TabStop = false;
|
|
button2.MouseClick += button2_MouseClick;
|
|
button2.MouseDoubleClick += button2_MouseClick;
|
|
//
|
|
// horizontalSeparator1
|
|
//
|
|
horizontalSeparator1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
|
horizontalSeparator1.Location = new System.Drawing.Point(5, 73);
|
|
horizontalSeparator1.Name = "horizontalSeparator1";
|
|
horizontalSeparator1.Padding = new Padding(0, 10, 0, 10);
|
|
horizontalSeparator1.Size = new System.Drawing.Size(375, 10);
|
|
//
|
|
// textBox1
|
|
//
|
|
textBox1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
|
textBox1.BackColor = System.Drawing.Color.Transparent;
|
|
textBox1.ClearedValue = "";
|
|
textBox1.EnableMovable = false;
|
|
textBox1.Icon = "O";
|
|
textBox1.IconSize = 13F;
|
|
textBox1.Location = new System.Drawing.Point(95, 20);
|
|
textBox1.Name = "textBox1";
|
|
textBox1.Size = new System.Drawing.Size(280, 32);
|
|
textBox1.TabIndex = 0;
|
|
textBox1.TabStop = false;
|
|
textBox1.UseSystemPasswordChar = false;
|
|
//
|
|
// button1
|
|
//
|
|
button1.ActiveImage = null;
|
|
button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
|
button1.BackColor = System.Drawing.Color.Transparent;
|
|
button1.EnableMenuOnClick = false;
|
|
button1.EnableMovable = false;
|
|
button1.HoverImage = null;
|
|
button1.IdleImage = null;
|
|
//
|
|
//
|
|
//
|
|
button1.Label.BackColor = System.Drawing.Color.White;
|
|
button1.Label.Dock = DockStyle.Fill;
|
|
button1.Label.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold);
|
|
button1.Label.ForeColor = System.Drawing.Color.FromArgb(126, 54, 244);
|
|
button1.Label.Location = new System.Drawing.Point(4, 4);
|
|
button1.Label.Margin = new Padding(0);
|
|
button1.Label.Name = "label1";
|
|
button1.Label.Size = new System.Drawing.Size(121, 25);
|
|
button1.Label.TabIndex = 0;
|
|
button1.Label.Text = "&First";
|
|
button1.Label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
|
button1.LabelText = "&First";
|
|
button1.Location = new System.Drawing.Point(110, 94);
|
|
button1.Name = "button1";
|
|
button1.Size = new System.Drawing.Size(128, 32);
|
|
button1.TabIndex = 1;
|
|
button1.TabStop = false;
|
|
button1.MouseClick += button1_MouseClick;
|
|
button1.MouseDoubleClick += button1_MouseClick;
|
|
//
|
|
// FindForm
|
|
//
|
|
AutoScaleMode = AutoScaleMode.None;
|
|
ClientSize = new System.Drawing.Size(384, 141);
|
|
Controls.Add(button1);
|
|
Controls.Add(textBox1);
|
|
Controls.Add(horizontalSeparator1);
|
|
Controls.Add(button2);
|
|
Controls.Add(label1);
|
|
MinimumSize = new System.Drawing.Size(400, 168);
|
|
Name = "FindForm";
|
|
Text = "Find";
|
|
ResumeLayout(false);
|
|
PerformLayout();
|
|
|
|
}
|
|
|
|
protected override void OnShown(EventArgs e)
|
|
{
|
|
base.OnShown(e);
|
|
|
|
textBox1.Focus();
|
|
}
|
|
|
|
|
|
private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
|
|
{
|
|
switch (e.KeyCode)
|
|
{
|
|
case Keys.Enter:
|
|
if (findPosition < 0)
|
|
{
|
|
button1_MouseClick(sender, new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0));
|
|
}
|
|
else
|
|
{
|
|
button2_MouseClick(sender, new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0));
|
|
}
|
|
|
|
break;
|
|
case Keys.Escape:
|
|
this.Close();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Find first.
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void button1_MouseClick(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(textBox1.Text))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (treeView1.Nodes.Count <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
findPosition = -1;
|
|
|
|
var nodeList = treeView1.ToNodeList<App6Options.Item>();
|
|
|
|
var node = nodeList.Where(x => x.Value.Title.Contains(textBox1.Text?.Trim())).Select(x => x.Key).FirstOrDefault();
|
|
if (node != null)
|
|
{
|
|
findPosition = 0;
|
|
|
|
treeView1.SelectedNode = node;
|
|
treeView1.SelectedNode.EnsureVisible();
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Find next.
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void button2_MouseClick(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(textBox1.Text))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (treeView1.Nodes.Count <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (treeView1.SelectedNode == null)
|
|
{
|
|
treeView1.SelectedNode = treeView1.Nodes[0];
|
|
}
|
|
|
|
var nodeList = treeView1.ToNodeList<App6Options.Item>();
|
|
|
|
var node = nodeList.Where(x => x.Value.Title.Contains(textBox1.Text?.Trim())).Select(x => x.Key)?.ToList() ?? new List<TreeNode>();
|
|
if (node != null)
|
|
{
|
|
//var pos = nodeList.FindIndex(x => x.Key == treeView1.SelectedNode);
|
|
//if (pos < 0)
|
|
//{
|
|
// findPosition = -1;
|
|
//} else {
|
|
// findPosition = pos;
|
|
//}
|
|
|
|
findPosition++;
|
|
|
|
if (findPosition >= node.Count)
|
|
{
|
|
findPosition = 0;
|
|
}
|
|
|
|
treeView1.SelectedNode = node[findPosition];
|
|
treeView1.SelectedNode.EnsureVisible();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
} |