2018-03-18 19:57:56 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Mesen.GUI.Controls;
|
|
|
|
|
|
|
|
|
|
namespace Mesen.GUI.Debugger.Controls
|
|
|
|
|
{
|
|
|
|
|
public partial class ctrlFindOccurrences : UserControl
|
|
|
|
|
{
|
|
|
|
|
public event EventHandler OnSearchResultsClosed;
|
|
|
|
|
|
|
|
|
|
public ctrlFindOccurrences()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
this.lstSearchResult.Font = new System.Drawing.Font(BaseControl.MonospaceFontFamily, 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ICodeViewer Viewer { get; set; }
|
|
|
|
|
|
2019-01-06 11:10:54 -05:00
|
|
|
|
public void FindAllOccurrences(string text, List<FindAllOccurrenceResult> results)
|
2018-03-18 19:57:56 -04:00
|
|
|
|
{
|
2019-01-06 11:10:54 -05:00
|
|
|
|
this.lstSearchResult.BeginUpdate();
|
2018-03-18 19:57:56 -04:00
|
|
|
|
this.lstSearchResult.Items.Clear();
|
2019-01-06 11:10:54 -05:00
|
|
|
|
foreach(FindAllOccurrenceResult searchResult in results) {
|
|
|
|
|
var item = this.lstSearchResult.Items.Add(searchResult.Location);
|
|
|
|
|
item.Tag = searchResult.Destination;
|
|
|
|
|
item.SubItems.Add(searchResult.MatchedLine);
|
2018-03-18 19:57:56 -04:00
|
|
|
|
item.SubItems.Add("");
|
|
|
|
|
}
|
2019-01-06 11:10:54 -05:00
|
|
|
|
this.lstSearchResult.EndUpdate();
|
|
|
|
|
|
2018-03-18 19:57:56 -04:00
|
|
|
|
this.lblSearchResult.Text = $"Search results for: {text} ({this.lstSearchResult.Items.Count} results)";
|
|
|
|
|
this.lstSearchResult.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
|
|
|
|
|
this.lstSearchResult.Columns[0].Width += 20;
|
|
|
|
|
this.lstSearchResult.Columns[1].Width = Math.Max(this.lstSearchResult.Columns[1].Width, this.lstSearchResult.Width - this.lstSearchResult.Columns[0].Width - 24);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void lstSearchResult_SizeChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.lstSearchResult.SizeChanged -= lstSearchResult_SizeChanged;
|
|
|
|
|
this.lstSearchResult.Columns[1].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
|
|
|
|
|
this.lstSearchResult.Columns[1].Width = Math.Max(this.lstSearchResult.Columns[1].Width, this.lstSearchResult.Width - this.lstSearchResult.Columns[0].Width - 24);
|
|
|
|
|
this.lstSearchResult.SizeChanged += lstSearchResult_SizeChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void picCloseOccurrenceList_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
OnSearchResultsClosed?.Invoke(null, EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void lstSearchResult_DoubleClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(lstSearchResult.SelectedItems.Count > 0) {
|
2019-01-06 11:10:54 -05:00
|
|
|
|
GoToDestination dest = lstSearchResult.SelectedItems[0].Tag as GoToDestination;
|
|
|
|
|
Viewer.CodeViewerActions.GoToDestination(dest);
|
2018-03-18 19:57:56 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-06 11:10:54 -05:00
|
|
|
|
|
|
|
|
|
public class FindAllOccurrenceResult
|
|
|
|
|
{
|
|
|
|
|
public string Location;
|
|
|
|
|
public string MatchedLine;
|
|
|
|
|
public GoToDestination Destination;
|
|
|
|
|
}
|
2018-03-18 19:57:56 -04:00
|
|
|
|
}
|