285 lines
10 KiB
C#
285 lines
10 KiB
C#
|
using Newtonsoft.Json.Linq;
|
|||
|
using ryCommon;
|
|||
|
using ScintillaNET;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel;
|
|||
|
using System.Data;
|
|||
|
using System.Drawing;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Text.RegularExpressions;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows.Forms;
|
|||
|
|
|||
|
namespace SuperDesign.Controls.Highlight.FindReplace
|
|||
|
{
|
|||
|
public partial class FindConfig : UserControl
|
|||
|
{
|
|||
|
public FindConfig()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
pnlStandardOptions.BringToFront();
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 搜索模式,0表示标准,1表示扩展,2表示正则
|
|||
|
/// </summary>
|
|||
|
[Description("搜索模式,0表示标准,1表示扩展,2表示正则")]
|
|||
|
public int SearchMode
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (rdoFileStandardR.Checked) { return 0; }
|
|||
|
if (rdoFileExtendedR.Checked) { return 1; }
|
|||
|
if (rdoFileRegexR.Checked) { return 2; }
|
|||
|
return -1;
|
|||
|
}
|
|||
|
set
|
|||
|
{
|
|||
|
if (value == 0) { rdoFileStandardR.Checked = true; }
|
|||
|
else if (value ==1) { rdoFileExtendedR.Checked = true; }
|
|||
|
else if (value == 2) { rdoFileRegexR.Checked = true; }
|
|||
|
else { rdoFileStandardR.Checked = true; }
|
|||
|
}
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 匹配大小写
|
|||
|
/// </summary>
|
|||
|
[Description("匹配大小写")]
|
|||
|
public bool MatchCase
|
|||
|
{
|
|||
|
get { return chkFileMatchCaseR.Checked; }
|
|||
|
set { chkFileMatchCaseR.Checked = value; }
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 全词匹配
|
|||
|
/// </summary>
|
|||
|
[Description("全词匹配")]
|
|||
|
public bool FileWholeWord
|
|||
|
{
|
|||
|
get { return chkFileWholeWordR.Checked; }
|
|||
|
set { chkFileWholeWordR.Checked = value; }
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 单词开头匹配
|
|||
|
/// </summary>
|
|||
|
[Description("单词开头匹配")]
|
|||
|
public bool FileWordStart
|
|||
|
{
|
|||
|
get { return chkFileWordStartR.Checked; }
|
|||
|
set { chkFileWordStartR.Checked = value; }
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 【正则】已编译
|
|||
|
/// </summary>
|
|||
|
[Description("【正则】已编译")]
|
|||
|
public bool RegexCompiled
|
|||
|
{
|
|||
|
get { return chkFileCompiledR.Checked; }
|
|||
|
set { chkFileCompiledR.Checked = value; }
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 【正则】显式捕获
|
|||
|
/// </summary>
|
|||
|
[Description("【正则】显式捕获")]
|
|||
|
public bool RegexExplicitCapture
|
|||
|
{
|
|||
|
get { return chkFileExplicitCaptureR.Checked; }
|
|||
|
set { chkFileExplicitCaptureR.Checked = value; }
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 【正则】多行模式
|
|||
|
/// </summary>
|
|||
|
[Description("【正则】多行模式")]
|
|||
|
public bool RegexMultiline
|
|||
|
{
|
|||
|
get { return chkFileMultilineR.Checked; }
|
|||
|
set { chkFileMultilineR.Checked = value; }
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 【正则】忽略语言区域差异
|
|||
|
/// </summary>
|
|||
|
[Description("【正则】忽略语言区域差异")]
|
|||
|
public bool RegexFileCultureInvariant
|
|||
|
{
|
|||
|
get { return chkFileCultureInvariantR.Checked; }
|
|||
|
set { chkFileCultureInvariantR.Checked = value; }
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 【正则】忽略大小写
|
|||
|
/// </summary>
|
|||
|
[Description("【正则】忽略大小写")]
|
|||
|
public bool RegexIgnoreCase
|
|||
|
{
|
|||
|
get { return chkFileIgnoreCaseR.Checked; }
|
|||
|
set { chkFileIgnoreCaseR.Checked = value; }
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 【正则】从右到左
|
|||
|
/// </summary>
|
|||
|
[Description("【正则】从右到左")]
|
|||
|
public bool RegexRightToLeft
|
|||
|
{
|
|||
|
get { return chkFileRightToLeftR.Checked; }
|
|||
|
set { chkFileRightToLeftR.Checked = value; }
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 【正则】ECMA脚本
|
|||
|
/// </summary>
|
|||
|
[Description("【正则】ECMA脚本")]
|
|||
|
public bool RegexEcmaScript
|
|||
|
{
|
|||
|
get { return chkFileEcmaScriptR.Checked; }
|
|||
|
set { chkFileEcmaScriptR.Checked = value; }
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 【正则】忽略空白符
|
|||
|
/// </summary>
|
|||
|
[Description("【正则】忽略空白符")]
|
|||
|
public bool RegexIgnorePatternWhitespace
|
|||
|
{
|
|||
|
get { return chkFileIgnorePatternWhitespaceR.Checked; }
|
|||
|
set { chkFileIgnorePatternWhitespaceR.Checked = value; }
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 【正则】单行模式
|
|||
|
/// </summary>
|
|||
|
[Description("【正则】单行模式")]
|
|||
|
public bool RegexFileSingleline
|
|||
|
{
|
|||
|
get { return chkFileSinglelineR.Checked; }
|
|||
|
set { chkFileSinglelineR.Checked = value; }
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 获取正则选项
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public RegexOptions GetRegexOptions()
|
|||
|
{
|
|||
|
RegexOptions ro = RegexOptions.None;
|
|||
|
if (chkFileCompiledR.Checked)
|
|||
|
ro |= RegexOptions.Compiled;
|
|||
|
|
|||
|
if (chkFileCultureInvariantR.Checked)
|
|||
|
ro |= RegexOptions.CultureInvariant;
|
|||
|
|
|||
|
if (chkFileEcmaScriptR.Checked)
|
|||
|
ro |= RegexOptions.ECMAScript;
|
|||
|
|
|||
|
if (chkFileExplicitCaptureR.Checked)
|
|||
|
ro |= RegexOptions.ExplicitCapture;
|
|||
|
|
|||
|
if (chkFileIgnoreCaseR.Checked)
|
|||
|
ro |= RegexOptions.IgnoreCase;
|
|||
|
|
|||
|
if (chkFileIgnorePatternWhitespaceR.Checked)
|
|||
|
ro |= RegexOptions.IgnorePatternWhitespace;
|
|||
|
|
|||
|
if (chkFileMultilineR.Checked)
|
|||
|
ro |= RegexOptions.Multiline;
|
|||
|
|
|||
|
if (chkFileRightToLeftR.Checked)
|
|||
|
ro |= RegexOptions.RightToLeft;
|
|||
|
|
|||
|
if (chkFileSinglelineR.Checked)
|
|||
|
ro |= RegexOptions.Singleline;
|
|||
|
return ro;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 设置正则选项
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public void SetRegexOptions(RegexOptions ro)
|
|||
|
{
|
|||
|
chkFileCompiledR.Checked = (ro & RegexOptions.Compiled) == RegexOptions.Compiled;
|
|||
|
chkFileCultureInvariantR.Checked = (ro & RegexOptions.CultureInvariant) == RegexOptions.CultureInvariant;
|
|||
|
chkFileEcmaScriptR.Checked = (ro & RegexOptions.ECMAScript) == RegexOptions.ECMAScript;
|
|||
|
chkFileExplicitCaptureR.Checked = (ro & RegexOptions.ExplicitCapture) == RegexOptions.ExplicitCapture;
|
|||
|
chkFileIgnoreCaseR.Checked = (ro & RegexOptions.IgnoreCase) == RegexOptions.IgnoreCase;
|
|||
|
chkFileIgnorePatternWhitespaceR.Checked = (ro & RegexOptions.IgnorePatternWhitespace) == RegexOptions.IgnorePatternWhitespace;
|
|||
|
chkFileMultilineR.Checked = (ro & RegexOptions.Multiline) == RegexOptions.Multiline;
|
|||
|
chkFileRightToLeftR.Checked = (ro & RegexOptions.RightToLeft) == RegexOptions.RightToLeft;
|
|||
|
chkFileSinglelineR.Checked = (ro & RegexOptions.Singleline) == RegexOptions.Singleline;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 获取普通搜索选项
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public SearchFlags GetSearchFlags()
|
|||
|
{
|
|||
|
SearchFlags sf = SearchFlags.None;
|
|||
|
if (chkFileMatchCaseR.Checked)
|
|||
|
sf |= SearchFlags.MatchCase;
|
|||
|
|
|||
|
if (chkFileWholeWordR.Checked)
|
|||
|
sf |= SearchFlags.WholeWord;
|
|||
|
|
|||
|
if (chkFileWordStartR.Checked)
|
|||
|
sf |= SearchFlags.WordStart;
|
|||
|
return sf;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 设置普通搜索选项
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public void SetSearchFlags(SearchFlags sf)
|
|||
|
{
|
|||
|
chkFileMatchCaseR.Checked = (sf & SearchFlags.MatchCase) == SearchFlags.MatchCase;
|
|||
|
chkFileWholeWordR.Checked = (sf & SearchFlags.WholeWord) == SearchFlags.WholeWord;
|
|||
|
chkFileWordStartR.Checked = (sf & SearchFlags.WordStart) == SearchFlags.WordStart;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 从另一个控件复制配置
|
|||
|
/// </summary>
|
|||
|
/// <param name="fc"></param>
|
|||
|
public void LoadConfig(FindConfig fc)
|
|||
|
{
|
|||
|
SearchMode = fc.SearchMode;
|
|||
|
fc.SetSearchFlags(fc.GetSearchFlags());
|
|||
|
fc.SetRegexOptions(fc.GetRegexOptions());
|
|||
|
}
|
|||
|
private void RdoFileExtendedR_CheckedChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (rdoFileExtendedR.Checked)
|
|||
|
pnlStandardOptions.BringToFront();
|
|||
|
|
|||
|
//cmdExtCharAndRegExFindR.Enabled = !rdoStandardR.Checked;
|
|||
|
//cmdExtCharAndRegExReplace.Enabled = !rdoStandardR.Checked;
|
|||
|
}
|
|||
|
|
|||
|
private void RdoFileStandardR_CheckedChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (rdoFileStandardR.Checked)
|
|||
|
pnlStandardOptions.BringToFront();
|
|||
|
}
|
|||
|
|
|||
|
private void RdoFileRegexR_CheckedChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (rdoFileRegexR.Checked)
|
|||
|
pnlRegexpOptions.BringToFront();
|
|||
|
}
|
|||
|
|
|||
|
private void chkFileEcmaScriptR_CheckedChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (((CheckBox)sender).Checked)
|
|||
|
{
|
|||
|
chkFileExplicitCaptureR.Checked = false;
|
|||
|
chkFileExplicitCaptureR.Enabled = false;
|
|||
|
chkFileIgnorePatternWhitespaceR.Checked = false;
|
|||
|
chkFileIgnorePatternWhitespaceR.Enabled = false;
|
|||
|
chkFileRightToLeftR.Checked = false;
|
|||
|
chkFileRightToLeftR.Enabled = false;
|
|||
|
chkFileSinglelineR.Checked = false;
|
|||
|
chkFileSinglelineR.Enabled = false;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
chkFileExplicitCaptureR.Enabled = true;
|
|||
|
chkFileIgnorePatternWhitespaceR.Enabled = true;
|
|||
|
chkFileRightToLeftR.Enabled = true;
|
|||
|
chkFileSinglelineR.Enabled = true;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|