|
@@ -3,6 +3,8 @@ using Compdfkit_Tools.PDFControlUI;
|
|
using ComPDFKitViewer.PdfViewer;
|
|
using ComPDFKitViewer.PdfViewer;
|
|
using System;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
|
+using System.Linq;
|
|
|
|
+using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media;
|
|
@@ -21,10 +23,12 @@ namespace Compdfkit_Tools.PDFControl
|
|
private PDFTextSearch textSearch;
|
|
private PDFTextSearch textSearch;
|
|
|
|
|
|
private string keyWord;
|
|
private string keyWord;
|
|
|
|
+
|
|
|
|
+ private bool isClearResult = false;
|
|
|
|
+
|
|
|
|
|
|
private SolidColorBrush highLightBrush = new SolidColorBrush(Color.FromArgb(0x99, 0xFF, 0xF7, 0x00));
|
|
private SolidColorBrush highLightBrush = new SolidColorBrush(Color.FromArgb(0x99, 0xFF, 0xF7, 0x00));
|
|
-
|
|
|
|
- private int ResultCount = 0;
|
|
|
|
|
|
+
|
|
public CPDFSearchControl()
|
|
public CPDFSearchControl()
|
|
{
|
|
{
|
|
InitializeComponent();
|
|
InitializeComponent();
|
|
@@ -43,15 +47,75 @@ namespace Compdfkit_Tools.PDFControl
|
|
private void PDFSearch_Loaded(object sender, RoutedEventArgs e)
|
|
private void PDFSearch_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
{
|
|
textSearch = new PDFTextSearch();
|
|
textSearch = new PDFTextSearch();
|
|
|
|
+
|
|
|
|
+ SearchInput.SearchEvent -= SearchInput_SearchEvent;
|
|
|
|
+ SearchInput.ClearEvent -= SearchInput_ClearEvent;
|
|
|
|
+ textSearch.SearchCompletedHandler -= TextSearch_SearchCompletedHandler;
|
|
|
|
+ SearchResult.SelectionChanged -= SearchResult_SelectionChanged;
|
|
|
|
+ textSearch.SearchPercentHandler -= TextSearch_SearchPercentHandler;
|
|
|
|
+ textSearch.SearchCancelHandler -= TextSearch_SearchCancelHandler;
|
|
|
|
+
|
|
SearchInput.SearchEvent += SearchInput_SearchEvent;
|
|
SearchInput.SearchEvent += SearchInput_SearchEvent;
|
|
SearchInput.ClearEvent += SearchInput_ClearEvent;
|
|
SearchInput.ClearEvent += SearchInput_ClearEvent;
|
|
textSearch.SearchCompletedHandler += TextSearch_SearchCompletedHandler;
|
|
textSearch.SearchCompletedHandler += TextSearch_SearchCompletedHandler;
|
|
SearchResult.SelectionChanged += SearchResult_SelectionChanged;
|
|
SearchResult.SelectionChanged += SearchResult_SelectionChanged;
|
|
|
|
+ textSearch.SearchPercentHandler += TextSearch_SearchPercentHandler;
|
|
|
|
+ textSearch.SearchCancelHandler += TextSearch_SearchCancelHandler;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void TextSearch_SearchPercentHandler(object sender, TextSearchResult e)
|
|
|
|
+ {
|
|
|
|
+ Dispatcher.Invoke(() =>
|
|
|
|
+ {
|
|
|
|
+ if(!e.Items.ContainsKey(e.CurrentPage))
|
|
|
|
+ {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ ProgressBar.ProgressValue = e.CurrentPage + 1;
|
|
|
|
+ foreach (var item in e.Items[e.CurrentPage])
|
|
|
|
+ {
|
|
|
|
+ if (item == null)
|
|
|
|
+ {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var result = new BindSearchResult()
|
|
|
|
+ {
|
|
|
|
+ PageIndex = item.PageIndex,
|
|
|
|
+ TextContent = item.TextContent,
|
|
|
|
+ TextRect = item.TextRect,
|
|
|
|
+ SearchWord = keyWord,
|
|
|
|
+ HighLightColor = Color.FromArgb(0x99, 0xFF, 0xF7, 0x00),
|
|
|
|
+ PageRotate = item.PageRotate
|
|
|
|
+ };
|
|
|
|
+ SearchResult.AddSearchResult(result);
|
|
|
|
+ ResultNum.Text = SearchResult.ResultListControl.Items.Count.ToString();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
private void SearchInput_ClearEvent(object sender, EventArgs e)
|
|
private void SearchInput_ClearEvent(object sender, EventArgs e)
|
|
{
|
|
{
|
|
- ClearSearchResult();
|
|
|
|
|
|
+ if (textSearch.CanDoSearch)
|
|
|
|
+ {
|
|
|
|
+ Dispatcher.Invoke(ClearSearchResult);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ isClearResult = true;
|
|
|
|
+ textSearch.CancleSearch();
|
|
|
|
+ }
|
|
|
|
+ ProgressBorder.Visibility = Visibility.Hidden;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void TextSearch_SearchCancelHandler(object sender, TextSearchResult e)
|
|
|
|
+ {
|
|
|
|
+ if (isClearResult)
|
|
|
|
+ {
|
|
|
|
+ Dispatcher.Invoke(ClearSearchResult);
|
|
|
|
+ isClearResult = false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private void SearchInput_FindPreviousEvent(object sender, EventArgs e)
|
|
private void SearchInput_FindPreviousEvent(object sender, EventArgs e)
|
|
@@ -76,45 +140,22 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
|
|
|
private void SearchResult_SelectionChanged(object sender, int e)
|
|
private void SearchResult_SelectionChanged(object sender, int e)
|
|
{
|
|
{
|
|
|
|
+ if (e < 0)
|
|
|
|
+ {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
currentHighLightIndex = e;
|
|
currentHighLightIndex = e;
|
|
BindSearchResult result = SearchResult.GetSelectItem();
|
|
BindSearchResult result = SearchResult.GetSelectItem();
|
|
HighLightSelectResult(result);
|
|
HighLightSelectResult(result);
|
|
- ResultText.Text = LanguageHelper.BotaManager.GetString("Text_Result")+ (e+1) + "/" + ResultCount;
|
|
|
|
|
|
+ ResultNum.Text = "";
|
|
|
|
+ ResultText.Text = LanguageHelper.BotaManager.GetString("Text_Result")+ (e+1) + "/" + SearchResult.ResultListControl.Items.Count;
|
|
}
|
|
}
|
|
|
|
|
|
private void TextSearch_SearchCompletedHandler(object sender, TextSearchResult e)
|
|
private void TextSearch_SearchCompletedHandler(object sender, TextSearchResult e)
|
|
{
|
|
{
|
|
Dispatcher.Invoke(() =>
|
|
Dispatcher.Invoke(() =>
|
|
{
|
|
{
|
|
- List<BindSearchResult> resultList = new List<BindSearchResult>();
|
|
|
|
-
|
|
|
|
- foreach (int pageIndex in e.Items.Keys)
|
|
|
|
- {
|
|
|
|
- List<TextSearchItem> textSearchItems = e.Items[pageIndex];
|
|
|
|
- foreach (TextSearchItem item in textSearchItems)
|
|
|
|
- {
|
|
|
|
- resultList.Add(new BindSearchResult()
|
|
|
|
- {
|
|
|
|
- PageIndex = item.PageIndex,
|
|
|
|
- TextContent = item.TextContent,
|
|
|
|
- TextRect = item.TextRect,
|
|
|
|
- SearchWord = keyWord,
|
|
|
|
- HighLightColor = Color.FromArgb(0x99, 0xFF, 0xF7, 0x00),
|
|
|
|
- PageRotate = item.PageRotate
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- SearchResult.SetSearchResult(resultList);
|
|
|
|
- ResultCount=resultList.Count;
|
|
|
|
-
|
|
|
|
- if (resultList==null || resultList.Count==0)
|
|
|
|
- {
|
|
|
|
- ResultText.Text= string.Empty;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- ResultText.Text = ResultCount + " " + LanguageHelper.BotaManager.GetString("Tip_Result");
|
|
|
|
- }
|
|
|
|
|
|
+ ProgressBorder.Visibility = Visibility.Hidden;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -132,9 +173,15 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
|
|
|
if (textSearch != null && textSearch.CanDoSearch)
|
|
if (textSearch != null && textSearch.CanDoSearch)
|
|
{
|
|
{
|
|
|
|
+ ResultNum.Text = "0";
|
|
|
|
+ ResultText.Text = LanguageHelper.BotaManager.GetString("Tip_Result");
|
|
|
|
+ ProgressBar.ProgressMaxValue = pdfView.Document.PageCount;
|
|
|
|
+ ProgressBorder.Visibility = Visibility.Visible;
|
|
|
|
+
|
|
keyWord = e;
|
|
keyWord = e;
|
|
textSearch.TextSearchDocument = pdfView.Document;
|
|
textSearch.TextSearchDocument = pdfView.Document;
|
|
- textSearch.SearchText(e, C_Search_Options.Search_Case_Insensitive);
|
|
|
|
|
|
+ SearchResult.ClearSearchResult();
|
|
|
|
+ textSearch.SearchText(keyWord,C_Search_Options.Search_Case_Insensitive);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -159,9 +206,15 @@ namespace Compdfkit_Tools.PDFControl
|
|
|
|
|
|
private void ClearSearchResult()
|
|
private void ClearSearchResult()
|
|
{
|
|
{
|
|
- SearchResult?.SetSearchResult(null);
|
|
|
|
|
|
+ SearchResult?.ClearSearchResult();
|
|
|
|
+ ResultNum.Text = string.Empty;
|
|
ResultText.Text = string.Empty;
|
|
ResultText.Text = string.Empty;
|
|
SearchInput.SearchKeyWord=string.Empty;
|
|
SearchInput.SearchKeyWord=string.Empty;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private void SearchCancel_Click(object sender, RoutedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ textSearch.CancleSearch();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|