------ #### SuperDesign V3.0.2412.2001 - *.[新增]新增程序更新日志设置和自动发布功能。 - *.[修复]修复Post数据格式不正确时双击文本框会导致软件闪退的BUG。
166 lines
7.0 KiB
C#
166 lines
7.0 KiB
C#
namespace ScintillaNET_FindReplaceDialog.FindAllResults
|
|
{
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using ScintillaNET;
|
|
|
|
public partial class FindAllResultsPanel : UserControl
|
|
{
|
|
#region Fields
|
|
|
|
private readonly Dictionary<int, FindResult> _findAllResults=new Dictionary<int, FindResult>();
|
|
|
|
#endregion Fields
|
|
|
|
#region Constructors
|
|
|
|
/// <summary>
|
|
/// Creates a new instance of FindAllResultsPanel
|
|
/// </summary>
|
|
public FindAllResultsPanel()
|
|
{
|
|
InitializeComponent();
|
|
|
|
FindResultsScintilla.Styles[Style.Default].Font = "Consolas";
|
|
FindResultsScintilla.Styles[Style.Default].Size = 10;
|
|
|
|
FindResultsScintilla.ClearAll();
|
|
}
|
|
public delegate void ResultEventHandler(object sender, FindResult r);
|
|
/// <summary>
|
|
/// 点击结果时发生
|
|
/// </summary>
|
|
[Description("点击结果时发生")]
|
|
public event ResultEventHandler OnResultClick;
|
|
#endregion Constructors
|
|
|
|
#region Properties
|
|
#endregion Properties
|
|
|
|
#region Methods
|
|
|
|
/// <summary>
|
|
/// Updates the find all results panel
|
|
/// </summary>
|
|
/// <param name="FindReplace">The FindReplace instance used to generate the find results.</param>
|
|
/// <param name="FindAllResults"></param>
|
|
public void UpdateFindAllResults(Dictionary<string,List<ScintillaNET_FindReplaceDialog.CharacterRange>> FindAllResults)
|
|
{
|
|
_findAllResults.Clear();
|
|
FindResultsScintilla.ReadOnly = false;
|
|
FindResultsScintilla.ClearAll();
|
|
Indicator _indicator_title = FindResultsScintilla.Indicators[15];
|
|
_indicator_title.ForeColor = Color.LightGreen;
|
|
_indicator_title.Alpha = 100;
|
|
_indicator_title.Style = IndicatorStyle.RoundBox;
|
|
_indicator_title.Under = true;
|
|
|
|
Indicator _indicator = FindResultsScintilla.Indicators[16];
|
|
_indicator.ForeColor = Color.Red;
|
|
_indicator.Alpha = 100;
|
|
_indicator.Style = IndicatorStyle.RoundBox;
|
|
_indicator.Under = true;
|
|
var line = 0;
|
|
//Write lines
|
|
foreach (var item in FindAllResults)
|
|
{
|
|
FindResultsScintilla.AppendText(item.Key+" (匹配"+ item.Value.Count+ "次)\r\n");
|
|
_findAllResults.Add(line, new FindResult());
|
|
FindResultsScintilla.Lines[line].ToggleFold();
|
|
line++;
|
|
foreach (var item_file in item.Value)
|
|
{
|
|
string resultsLinePrefix = string.Format("行 {0}: ", item_file.LineNum + 1);
|
|
FindResultsScintilla.AppendText(string.Format("{0}{1}",
|
|
resultsLinePrefix, item_file.RangeText.Replace("\n"," "))+"\r\n");
|
|
_findAllResults.Add(line,new FindResult() { Path = item.Key, Result = item_file });
|
|
line++;
|
|
}
|
|
//Highlight
|
|
foreach (var item_file in _findAllResults)
|
|
{
|
|
var item_range = item_file.Value.Result;
|
|
int lastLineStartPos = FindResultsScintilla.Lines[item_file.Key].Position;
|
|
if (item_range == null) {
|
|
FindResultsScintilla.IndicatorCurrent = _indicator_title.Index;
|
|
FindResultsScintilla.IndicatorFillRange(lastLineStartPos, FindResultsScintilla.Lines[item_file.Key].Length);
|
|
continue;
|
|
}
|
|
string resultsLinePrefix = string.Format("行 {0}: ", item_range.LineNum+1);
|
|
//int LinePos = item_range.LinePos;
|
|
//int startPosInLine = item_range.CpMin - LinePos;
|
|
FindResultsScintilla.IndicatorCurrent = _indicator.Index;
|
|
FindResultsScintilla.IndicatorFillRange(lastLineStartPos + resultsLinePrefix.Length+1, item_file.Value.Result.CpMax - item_file.Value.Result.CpMin);
|
|
}
|
|
}
|
|
FindResultsScintilla.ReadOnly = true;
|
|
}
|
|
|
|
private void FindResultsScintilla_KeyUp(object sender, KeyEventArgs e)
|
|
{
|
|
int pos = FindResultsScintilla.CurrentPosition;
|
|
int selectedLine = FindResultsScintilla.LineFromPosition(pos);
|
|
|
|
if (_findAllResults.ContainsKey(selectedLine))
|
|
{
|
|
ScintillaNET_FindReplaceDialog.CharacterRange CharRange = _findAllResults[selectedLine].Result;
|
|
if (CharRange == null) { return; }
|
|
if (CharRange.CpMax== CharRange.CpMin) { return; }
|
|
OnResultClick?.Invoke(this, _findAllResults[selectedLine]);
|
|
//Scintilla.SetSelection(CharRange.cpMin, CharRange.cpMax);
|
|
//Scintilla.ScrollCaret();
|
|
}
|
|
}
|
|
|
|
private void FindResultsScintilla_MouseClick(object sender, MouseEventArgs e)
|
|
{
|
|
int pos = FindResultsScintilla.CharPositionFromPointClose((e.Location).X, (e.Location).Y);
|
|
if (pos == -1)
|
|
return;
|
|
|
|
int selectedLine = FindResultsScintilla.LineFromPosition(pos);
|
|
if (_findAllResults.ContainsKey(selectedLine))
|
|
{
|
|
ScintillaNET_FindReplaceDialog.CharacterRange CharRange = _findAllResults[selectedLine].Result;
|
|
if (CharRange == null) { return; }
|
|
if (CharRange.CpMax == CharRange.CpMin) { return; }
|
|
OnResultClick?.Invoke(this, _findAllResults[selectedLine]);
|
|
//Scintilla.SetSelection(CharRange.cpMin, CharRange.cpMax);
|
|
//Scintilla.ScrollCaret();
|
|
}
|
|
}
|
|
|
|
private void FindResultsScintilla_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
{
|
|
var aa = FindResultsScintilla.CurrentPosition;
|
|
int selectedLine = FindResultsScintilla.LineFromPosition(aa);
|
|
//int pos = FindResultsScintilla.CharPositionFromPointClose((e.Location).X, (e.Location).Y);
|
|
if (selectedLine == -1)
|
|
return;
|
|
//int selectedLine = FindResultsScintilla.LineFromPosition(pos);
|
|
if (_findAllResults.ContainsKey(selectedLine))
|
|
{
|
|
ScintillaNET_FindReplaceDialog.CharacterRange CharRange = _findAllResults[selectedLine].Result;
|
|
if (CharRange == null) { return; }
|
|
if (CharRange.CpMax == CharRange.CpMin) { return; }
|
|
OnResultClick?.Invoke(this, _findAllResults[selectedLine]);
|
|
//Scintilla.SetSelection(CharRange.cpMin, CharRange.cpMax);
|
|
//Scintilla.ScrollCaret();
|
|
//Scintilla.Focus();
|
|
}
|
|
}
|
|
|
|
#endregion Methods
|
|
}
|
|
public class FindResult
|
|
{
|
|
public string Path { get; set; } = "";
|
|
public ScintillaNET_FindReplaceDialog.CharacterRange Result { get; set; }
|
|
}
|
|
} |