bookmark-manager-r4/FindForm.cs

257 lines
10 KiB
C#
Raw Normal View History

2024-07-17 00:56:17 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
2021-09-12 14:25:37 +00:00
using System.Windows.Forms;
using bzit.bomg.Models;
2024-07-17 00:56:17 +00:00
using RyzStudio.Windows.Forms;
using RyzStudio.Windows.ThemedForms;
using RyzStudio.Windows.ThemedForms.ButtonTextBox;
2021-09-12 14:25:37 +00:00
namespace FizzyLauncher
{
2024-07-17 00:56:17 +00:00
public class FindForm : Form
2021-09-12 14:25:37 +00:00
{
private System.Windows.Forms.Label label1;
2024-07-17 00:56:17 +00:00
private ThButton button2;
2021-09-12 14:25:37 +00:00
private RyzStudio.Windows.Forms.THorizontalSeparator tHorizontalSeparator1;
2024-07-17 00:56:17 +00:00
private ThButton button1;
private ThClearableTextBox textBox1;
2021-09-12 14:25:37 +00:00
private BookmarkTreeView treeView1 = null;
private int findPosition = -1;
2021-09-12 14:25:37 +00:00
2021-09-14 19:36:04 +00:00
public FindForm(BookmarkTreeView treeView)
2021-09-12 14:25:37 +00:00
{
InitializeComponent();
this.MinimizeBox = false;
this.MaximizeBox = false;
this.ShowIcon = false;
this.ShowInTaskbar = true;
2021-09-12 14:25:37 +00:00
treeView1 = treeView;
textBox1.PreviewKeyDown += textBox1_PreviewKeyDown;
2021-09-12 14:25:37 +00:00
}
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
2024-07-17 00:56:17 +00:00
this.button2 = new RyzStudio.Windows.ThemedForms.ThButton();
2021-09-12 14:25:37 +00:00
this.tHorizontalSeparator1 = new RyzStudio.Windows.Forms.THorizontalSeparator();
2024-07-17 00:56:17 +00:00
this.textBox1 = new ThClearableTextBox();
this.button1 = new RyzStudio.Windows.ThemedForms.ThButton();
2021-09-12 14:25:37 +00:00
this.SuspendLayout();
2022-01-27 15:28:33 +00:00
//
2021-09-12 14:25:37 +00:00
// label1
2022-01-27 15:28:33 +00:00
//
2021-09-12 14:25:37 +00:00
this.label1.AutoSize = true;
this.label1.BackColor = System.Drawing.Color.Transparent;
this.label1.ForeColor = System.Drawing.SystemColors.ControlText;
this.label1.Location = new System.Drawing.Point(10, 21);
this.label1.Margin = new System.Windows.Forms.Padding(0);
this.label1.Name = "label1";
this.label1.Padding = new System.Windows.Forms.Padding(0, 9, 0, 10);
this.label1.Size = new System.Drawing.Size(30, 34);
this.label1.TabIndex = 153;
this.label1.Text = "Find";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
2022-01-27 15:28:33 +00:00
//
2021-09-12 14:25:37 +00:00
// button2
2022-01-27 15:28:33 +00:00
//
this.button2.ActiveImage = null;
2021-09-12 14:25:37 +00:00
this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.button2.BackColor = System.Drawing.Color.Transparent;
this.button2.HoverImage = null;
this.button2.IdleImage = null;
2021-09-12 14:25:37 +00:00
this.button2.LabelText = "&Next";
this.button2.Location = new System.Drawing.Point(321, 99);
this.button2.Margin = new System.Windows.Forms.Padding(10, 0, 0, 10);
2021-09-12 14:25:37 +00:00
this.button2.Name = "button2";
this.button2.Padding = new System.Windows.Forms.Padding(4, 4, 3, 3);
this.button2.Size = new System.Drawing.Size(128, 32);
this.button2.TabIndex = 2;
2021-09-12 14:25:37 +00:00
this.button2.MouseClick += new System.Windows.Forms.MouseEventHandler(this.button2_MouseClick);
2022-01-27 15:28:33 +00:00
//
2021-09-12 14:25:37 +00:00
// tHorizontalSeparator1
2022-01-27 15:28:33 +00:00
//
this.tHorizontalSeparator1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
2021-09-12 14:25:37 +00:00
| System.Windows.Forms.AnchorStyles.Right)));
this.tHorizontalSeparator1.AutoScrollMargin = new System.Drawing.Size(0, 0);
this.tHorizontalSeparator1.AutoScrollMinSize = new System.Drawing.Size(0, 0);
this.tHorizontalSeparator1.BackColor = System.Drawing.Color.Transparent;
this.tHorizontalSeparator1.Location = new System.Drawing.Point(10, 67);
this.tHorizontalSeparator1.Margin = new System.Windows.Forms.Padding(5, 0, 5, 10);
2021-09-12 14:25:37 +00:00
this.tHorizontalSeparator1.MaximumSize = new System.Drawing.Size(4920, 2);
this.tHorizontalSeparator1.MinimumSize = new System.Drawing.Size(0, 22);
this.tHorizontalSeparator1.Name = "tHorizontalSeparator1";
this.tHorizontalSeparator1.Padding = new System.Windows.Forms.Padding(0, 10, 0, 10);
this.tHorizontalSeparator1.Size = new System.Drawing.Size(444, 22);
this.tHorizontalSeparator1.TabIndex = 188;
this.tHorizontalSeparator1.TabStop = false;
2022-01-27 15:28:33 +00:00
//
2021-09-12 14:25:37 +00:00
// textBox1
2022-01-27 15:28:33 +00:00
//
this.textBox1.AcceptButton = this.button2;
2022-01-27 15:28:33 +00:00
this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
2021-09-12 14:25:37 +00:00
| System.Windows.Forms.AnchorStyles.Right)));
this.textBox1.BackColor = System.Drawing.Color.Transparent;
this.textBox1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.textBox1.Location = new System.Drawing.Point(121, 20);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(328, 35);
this.textBox1.TabIndex = 0;
2021-09-14 19:36:04 +00:00
this.textBox1.UseSystemPasswordChar = false;
2022-01-27 15:28:33 +00:00
//
2021-09-12 14:25:37 +00:00
// button1
2022-01-27 15:28:33 +00:00
//
this.button1.ActiveImage = null;
2021-09-12 14:25:37 +00:00
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.button1.BackColor = System.Drawing.Color.Transparent;
this.button1.HoverImage = null;
this.button1.IdleImage = null;
2021-09-12 14:25:37 +00:00
this.button1.LabelText = "&First";
this.button1.Location = new System.Drawing.Point(185, 99);
this.button1.Margin = new System.Windows.Forms.Padding(10, 0, 0, 10);
2021-09-12 14:25:37 +00:00
this.button1.Name = "button1";
this.button1.Padding = new System.Windows.Forms.Padding(4, 4, 3, 3);
this.button1.Size = new System.Drawing.Size(128, 32);
this.button1.TabIndex = 1;
2021-09-12 14:25:37 +00:00
this.button1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.button1_MouseClick);
2022-01-27 15:28:33 +00:00
//
2021-09-12 14:25:37 +00:00
// FindForm
2022-01-27 15:28:33 +00:00
//
2021-09-12 14:25:37 +00:00
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(464, 151);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.tHorizontalSeparator1);
this.Controls.Add(this.button2);
this.Controls.Add(this.label1);
this.MinimumSize = new System.Drawing.Size(480, 190);
this.Name = "FindForm";
this.Text = "Find";
this.ResumeLayout(false);
this.PerformLayout();
}
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
textBox1.Focus();
2021-09-12 14:25:37 +00:00
}
private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
if (findPosition < 0)
2021-09-12 14:25:37 +00:00
{
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;
2021-09-12 14:25:37 +00:00
}
}
/// <summary>
/// Find first.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2021-09-12 14:25:37 +00:00
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<BookmarkModel>();
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();
}
}
2021-09-12 14:25:37 +00:00
}
/// <summary>
/// Find next.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2021-09-12 14:25:37 +00:00
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<BookmarkModel>();
2021-09-12 14:25:37 +00:00
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;
//}
2021-09-12 14:25:37 +00:00
findPosition++;
2021-09-12 14:25:37 +00:00
if (findPosition >= node.Count)
{
findPosition = 0;
}
treeView1.SelectedNode = node[findPosition];
treeView1.SelectedNode.EnsureVisible();
}
}
2021-09-12 14:25:37 +00:00
}
}
}