Improved search text functionality

This commit is contained in:
Alexander 2019-08-22 20:05:18 +03:00
parent 54334b53f8
commit 96be69dd77
2 changed files with 142 additions and 72 deletions

View file

@ -84,9 +84,10 @@ public void InitializeComponent()
this.OpenFile = new System.Windows.Forms.OpenFileDialog();
this.SaveFile = new System.Windows.Forms.SaveFileDialog();
this.SearchTextBox = new System.Windows.Forms.TextBox();
this.chkMatchCase = new System.Windows.Forms.CheckBox();
this.chkMatchWholeWord = new System.Windows.Forms.CheckBox();
this.MatchCaseCheckBox = new System.Windows.Forms.CheckBox();
this.WholeWordCheckBox = new System.Windows.Forms.CheckBox();
this.SearchPanel = new System.Windows.Forms.Panel();
this.FindNextButton = new System.Windows.Forms.Button();
this.CloseSearchPanel = new System.Windows.Forms.PictureBox();
this.ToolbarPanel = new System.Windows.Forms.Panel();
this.CloseToolbar = new System.Windows.Forms.PictureBox();
@ -582,55 +583,56 @@ public void InitializeComponent()
this.SearchTextBox.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(35)))));
this.SearchTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.SearchTextBox.ForeColor = System.Drawing.Color.White;
this.SearchTextBox.Location = new System.Drawing.Point(196, 6);
this.SearchTextBox.Location = new System.Drawing.Point(191, 5);
this.SearchTextBox.Name = "SearchTextBox";
this.SearchTextBox.Size = new System.Drawing.Size(279, 14);
this.SearchTextBox.Size = new System.Drawing.Size(236, 14);
this.SearchTextBox.TabIndex = 9;
this.SearchTextBox.TabStop = false;
this.SearchTextBox.TextChanged += new System.EventHandler(this.SearchTextBox_TextChanged);
this.SearchTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.SearchTextBox_KeyDown);
//
// chkMatchCase
// MatchCaseCheckBox
//
this.chkMatchCase.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
this.MatchCaseCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.chkMatchCase.AutoSize = true;
this.chkMatchCase.ForeColor = System.Drawing.Color.Gainsboro;
this.chkMatchCase.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.chkMatchCase.Location = new System.Drawing.Point(95, 5);
this.chkMatchCase.Name = "chkMatchCase";
this.chkMatchCase.Size = new System.Drawing.Size(95, 17);
this.chkMatchCase.TabIndex = 11;
this.chkMatchCase.Text = "Case sensitive";
this.chkMatchCase.UseVisualStyleBackColor = false;
this.chkMatchCase.CheckedChanged += new System.EventHandler(this.ChkMatchCase_CheckedChanged);
this.MatchCaseCheckBox.AutoSize = true;
this.MatchCaseCheckBox.ForeColor = System.Drawing.Color.Gainsboro;
this.MatchCaseCheckBox.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.MatchCaseCheckBox.Location = new System.Drawing.Point(95, 5);
this.MatchCaseCheckBox.Name = "MatchCaseCheckBox";
this.MatchCaseCheckBox.Size = new System.Drawing.Size(95, 17);
this.MatchCaseCheckBox.TabIndex = 11;
this.MatchCaseCheckBox.Text = "Case sensitive";
this.MatchCaseCheckBox.UseVisualStyleBackColor = false;
this.MatchCaseCheckBox.CheckedChanged += new System.EventHandler(this.MatchCaseCheckBox_CheckedChanged);
//
// chkMatchWholeWord
// WholeWordCheckBox
//
this.chkMatchWholeWord.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
this.WholeWordCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.chkMatchWholeWord.AutoSize = true;
this.chkMatchWholeWord.BackColor = System.Drawing.Color.Transparent;
this.chkMatchWholeWord.ForeColor = System.Drawing.Color.Gainsboro;
this.chkMatchWholeWord.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.chkMatchWholeWord.Location = new System.Drawing.Point(6, 5);
this.chkMatchWholeWord.Name = "chkMatchWholeWord";
this.chkMatchWholeWord.Size = new System.Drawing.Size(83, 17);
this.chkMatchWholeWord.TabIndex = 12;
this.chkMatchWholeWord.Text = "Whole word";
this.chkMatchWholeWord.UseVisualStyleBackColor = false;
this.chkMatchWholeWord.CheckedChanged += new System.EventHandler(this.ChkMatchWholeWord_CheckedChanged);
this.WholeWordCheckBox.AutoSize = true;
this.WholeWordCheckBox.BackColor = System.Drawing.Color.Transparent;
this.WholeWordCheckBox.ForeColor = System.Drawing.Color.Gainsboro;
this.WholeWordCheckBox.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.WholeWordCheckBox.Location = new System.Drawing.Point(6, 5);
this.WholeWordCheckBox.Name = "WholeWordCheckBox";
this.WholeWordCheckBox.Size = new System.Drawing.Size(83, 17);
this.WholeWordCheckBox.TabIndex = 12;
this.WholeWordCheckBox.Text = "Whole word";
this.WholeWordCheckBox.UseVisualStyleBackColor = false;
this.WholeWordCheckBox.CheckedChanged += new System.EventHandler(this.WholeWordCheckBox_CheckedChanged);
//
// SearchPanel
//
this.SearchPanel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(35)))));
this.SearchPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.SearchPanel.Controls.Add(this.CloseSearchPanel);
this.SearchPanel.Controls.Add(this.SearchTextBox);
this.SearchPanel.Controls.Add(this.chkMatchCase);
this.SearchPanel.Controls.Add(this.chkMatchWholeWord);
this.SearchPanel.Controls.Add(this.MatchCaseCheckBox);
this.SearchPanel.Controls.Add(this.WholeWordCheckBox);
this.SearchPanel.Controls.Add(this.FindNextButton);
this.SearchPanel.Controls.Add(this.CloseSearchPanel);
this.SearchPanel.Dock = System.Windows.Forms.DockStyle.Bottom;
this.SearchPanel.Font = new System.Drawing.Font("Tahoma", 8.25F);
this.SearchPanel.Location = new System.Drawing.Point(0, 291);
@ -639,15 +641,36 @@ public void InitializeComponent()
this.SearchPanel.TabIndex = 13;
this.SearchPanel.Visible = false;
//
// FindNextButton
//
this.FindNextButton.Cursor = System.Windows.Forms.Cursors.Hand;
this.FindNextButton.Dock = System.Windows.Forms.DockStyle.Right;
this.FindNextButton.FlatAppearance.BorderColor = System.Drawing.Color.DimGray;
this.FindNextButton.FlatAppearance.MouseDownBackColor = System.Drawing.Color.DimGray;
this.FindNextButton.FlatAppearance.MouseOverBackColor = System.Drawing.Color.DimGray;
this.FindNextButton.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.FindNextButton.ForeColor = System.Drawing.SystemColors.AppWorkspace;
this.FindNextButton.Location = new System.Drawing.Point(433, 0);
this.FindNextButton.Name = "FindNextButton";
this.FindNextButton.Size = new System.Drawing.Size(64, 25);
this.FindNextButton.TabIndex = 15;
this.FindNextButton.TabStop = false;
this.FindNextButton.Text = "Find Next";
this.FindNextButton.UseMnemonic = false;
this.FindNextButton.UseVisualStyleBackColor = true;
this.FindNextButton.Click += new System.EventHandler(this.FindNextButton_Click);
//
// CloseSearchPanel
//
this.CloseSearchPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.CloseSearchPanel.BackColor = System.Drawing.Color.Transparent;
this.CloseSearchPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.CloseSearchPanel.Cursor = System.Windows.Forms.Cursors.Hand;
this.CloseSearchPanel.Dock = System.Windows.Forms.DockStyle.Right;
this.CloseSearchPanel.Image = ((System.Drawing.Image)(resources.GetObject("CloseSearchPanel.Image")));
this.CloseSearchPanel.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.CloseSearchPanel.Location = new System.Drawing.Point(495, 6);
this.CloseSearchPanel.Location = new System.Drawing.Point(497, 0);
this.CloseSearchPanel.Name = "CloseSearchPanel";
this.CloseSearchPanel.Size = new System.Drawing.Size(14, 14);
this.CloseSearchPanel.Size = new System.Drawing.Size(14, 25);
this.CloseSearchPanel.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.CloseSearchPanel.TabIndex = 14;
this.CloseSearchPanel.TabStop = false;
@ -844,11 +867,11 @@ public void InitializeComponent()
this.CustomRTB.Dock = System.Windows.Forms.DockStyle.Fill;
this.CustomRTB.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
this.CustomRTB.ForeColor = System.Drawing.SystemColors.WindowText;
this.CustomRTB.Location = new System.Drawing.Point(18, 47);
this.CustomRTB.Location = new System.Drawing.Point(17, 47);
this.CustomRTB.Name = "CustomRTB";
this.CustomRTB.Size = new System.Drawing.Size(495, 244);
this.CustomRTB.Size = new System.Drawing.Size(496, 244);
this.CustomRTB.TabIndex = 10;
this.CustomRTB.Text = "";
this.CustomRTB.Text = "TEST TEST TEST TEST TEST TEST ";
this.CustomRTB.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.СustomRTB_LinkClicked);
this.CustomRTB.SelectionChanged += new System.EventHandler(this.CustomRTB_SelectionChanged);
this.CustomRTB.Click += new System.EventHandler(this.CustomRTB_Click);
@ -894,7 +917,7 @@ public void InitializeComponent()
this.LineNumbers_For_RichTextBox.Show_GridLines = true;
this.LineNumbers_For_RichTextBox.Show_LineNrs = true;
this.LineNumbers_For_RichTextBox.Show_MarginLines = false;
this.LineNumbers_For_RichTextBox.Size = new System.Drawing.Size(18, 244);
this.LineNumbers_For_RichTextBox.Size = new System.Drawing.Size(17, 244);
this.LineNumbers_For_RichTextBox.TabIndex = 15;
//
// MainForm
@ -988,8 +1011,8 @@ public void InitializeComponent()
private System.Windows.Forms.ToolStripMenuItem CheckForUpdatesToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem DocumentationToolStripMenuItem;
private System.Windows.Forms.TextBox SearchTextBox;
private System.Windows.Forms.CheckBox chkMatchCase;
private System.Windows.Forms.CheckBox chkMatchWholeWord;
private System.Windows.Forms.CheckBox MatchCaseCheckBox;
private System.Windows.Forms.CheckBox WholeWordCheckBox;
private System.Windows.Forms.Panel SearchPanel;
private System.Windows.Forms.ToolStripMenuItem SettingsToolStripMenuItem;
public CustomRichTextBox CustomRTB;
@ -1017,5 +1040,6 @@ public void InitializeComponent()
private System.Windows.Forms.ToolStripMenuItem MainVariablesToolStripMenuItem;
private LineNumbers.LineNumbers_For_RichTextBox LineNumbers_For_RichTextBox;
private System.Windows.Forms.ToolStripMenuItem insertToolStripMenuItem;
private System.Windows.Forms.Button FindNextButton;
}
}

View file

@ -24,6 +24,7 @@ public partial class MainForm : Form
bool shiftPresed;
bool noExit = false;
string argsPath = "";
int findPos = 0;
public MainForm()
{
@ -637,14 +638,10 @@ private void MainWindow_Activated(object sender, EventArgs e)
if (!ps.ShowToolbar && ToolbarPanel.Visible)
{
ToolbarPanel.Visible = false;
CustomRTB.Height += 23;
CustomRTB.Location = new Point(0, 24);
}
if (ps.ShowToolbar && !ToolbarPanel.Visible)
{
ToolbarPanel.Visible = true;
CustomRTB.Height -= 23;
CustomRTB.Location = new Point(0, 47);
}
MenuIcons();
@ -753,9 +750,6 @@ private void MainWindow_Load(object sender, EventArgs e)
if (!ps.ShowToolbar)
{
ToolbarPanel.Visible = false;
CustomRTB.Height += 23;
CustomRTB.Location = new Point(0, 24);
}
else
{
@ -843,6 +837,16 @@ private void CustomRTB_KeyDown(object sender, KeyEventArgs e)
{
shiftPresed = true;
}
if (e.KeyCode == Keys.Escape)
{
SearchTextBox.Text = "";
SearchPanel.Visible = false;
CustomRTB.Focus();
CustomRTB.DeselectAll();
e.Handled = e.SuppressKeyPress = true;
findPos = 0;
}
}
private void СustomRTB_LinkClicked(object sender, LinkClickedEventArgs e)
@ -908,7 +912,10 @@ private void CustomRTB_KeyUp(object sender, KeyEventArgs e)
shiftPresed = false;
}
}
private void CustomRTB_TextChanged(object sender, EventArgs e)
{
LineNumbers_For_RichTextBox.Refresh();
}
/*CustomRTB Events*/
@ -1193,16 +1200,14 @@ private void FindToolStripMenuItem_Click(object sender, EventArgs e)
{
SearchTextBox.Text = "";
SearchPanel.Visible = false;
CustomRTB.Height += 27;
CustomRTB.Focus();
CustomRTB.DeselectAll();
CustomRTB.SelectionStart = caretPos;
//CustomRTB.SelectionStart = caretPos;
}
else
{
SearchPanel.Visible = true;
SearchTextBox.Focus();
CustomRTB.Height -= 27;
}
}
@ -1459,8 +1464,6 @@ private void LockToolbarButton_Click(object sender, EventArgs e)
private void CloseToolbar_Click(object sender, EventArgs e)
{
ToolbarPanel.Visible = false;
CustomRTB.Height += 23;
CustomRTB.Location = new Point(0, 24);
ps.ShowToolbar = false;
ps.Save();
}
@ -1478,9 +1481,10 @@ private void CloseToolbar_MouseLeave(object sender, EventArgs e)
/*Search Panel*/
private void SearchTextBox_TextChanged(object sender, EventArgs e)
{
bool isexist = CustomRTB.Highlight(SearchTextBox.Text, ps.HighlightsColor, chkMatchCase.Checked, chkMatchWholeWord.Checked);
findPos = 0;
}
private void SearchTextBox_KeyDown(object sender, KeyEventArgs e)
@ -1489,11 +1493,10 @@ private void SearchTextBox_KeyDown(object sender, KeyEventArgs e)
{
SearchTextBox.Text = "";
SearchPanel.Visible = false;
CustomRTB.Height += 27;
CustomRTB.Focus();
CustomRTB.DeselectAll();
CustomRTB.SelectionStart = caretPos;
e.Handled = e.SuppressKeyPress = true;
findPos = 0;
}
}
@ -1504,22 +1507,73 @@ private void CloseSearchPanel_Click(object sender, EventArgs e)
private void CloseSearchPanel_MouseHover(object sender, EventArgs e)
{
CloseSearchPanel.Image = Properties.Resources.close_b;
CloseSearchPanel.BackColor = Color.DimGray;
}
private void CloseSearchPanel_MouseLeave(object sender, EventArgs e)
{
CloseSearchPanel.Image = Properties.Resources.close_g;
CloseSearchPanel.BackColor = Color.Transparent;
}
private void ChkMatchCase_CheckedChanged(object sender, EventArgs e)
private void MatchCaseCheckBox_CheckedChanged(object sender, EventArgs e)
{
bool isexist = CustomRTB.Highlight(SearchTextBox.Text, ps.HighlightsColor, chkMatchCase.Checked, chkMatchWholeWord.Checked);
findPos = 0;
CustomRTB.DeselectAll();
}
private void ChkMatchWholeWord_CheckedChanged(object sender, EventArgs e)
private void WholeWordCheckBox_CheckedChanged(object sender, EventArgs e)
{
bool isexist = CustomRTB.Highlight(SearchTextBox.Text, ps.HighlightsColor, chkMatchCase.Checked, chkMatchWholeWord.Checked);
findPos = 0;
CustomRTB.DeselectAll();
}
private void FindMyText(string text, RichTextBoxFinds findOptions)
{
if (text.Length > 0)
{
try
{
findPos = CustomRTB.Find(SearchTextBox.Text, findPos, findOptions);
if (findPos == -1)
{
findPos = 0;
return;
}
CustomRTB.Focus();
CustomRTB.Select(findPos, SearchTextBox.Text.Length);
findPos += SearchTextBox.Text.Length + 1;
}
catch
{
findPos = 0;
}
}
}
private void FindNextButton_Click(object sender, EventArgs e)
{
if ((!WholeWordCheckBox.Checked) & (!MatchCaseCheckBox.Checked))
{
FindMyText(SearchTextBox.Text, RichTextBoxFinds.None);
return;
}
if (WholeWordCheckBox.Checked & MatchCaseCheckBox.Checked)
{
FindMyText(SearchTextBox.Text, RichTextBoxFinds.MatchCase | RichTextBoxFinds.WholeWord);
return;
}
if (MatchCaseCheckBox.Checked)
{
FindMyText(SearchTextBox.Text, RichTextBoxFinds.MatchCase);
return;
}
if (WholeWordCheckBox.Checked)
{
FindMyText(SearchTextBox.Text, RichTextBoxFinds.WholeWord);
return;
}
}
/*Search Panel*/
@ -1540,16 +1594,8 @@ private void MainVariablesToolStripMenuItem_Click(object sender, EventArgs e)
Debug.WriteLine("okPressed: " + PublicVar.okPressed);
Debug.WriteLine("CustomRTB.Modified: " + CustomRTB.Modified);
Debug.WriteLine("EditorMenuStrip: " + EditorMenuStrip.Enabled);
#endif
}
private void CustomRTB_TextChanged(object sender, EventArgs e)
{
LineNumbers_For_RichTextBox.Refresh();
}
}
/*Debug Menu*/
}
}