using PDF_Master.CustomControl; using PDF_Master.EventAggregators; using PDF_Master.Model.BOTA; using PDF_Master.ViewModels.BOTA; using Prism.Events; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace PDF_Master.Views.BOTA { /// /// SearchContent.xaml 的交互逻辑 /// public partial class SearchContent : UserControl { private bool Updata = false; private string unicode = ""; public SearchContent() { InitializeComponent(); unicode = App.mainWindowViewModel.SelectedItem.Unicode; } public SearchContent(IEventAggregator eventAggregator) : this() { //Windows: BOTA列表,移除点击阅读页取消选中逻辑 //eventAggregator.GetEvent().Subscribe(CleanSelectAll, e => e.Unicode == unicode); } private void CleanSelectAll(CleanSelectAllArgs obj) { SearchResultList.SelectedIndex = -1; (DataContext as SearchContentViewModel).CleaSelect(); if (Updata) { if (string.IsNullOrEmpty(SearchText.Text)) { return; } (DataContext as SearchContentViewModel).SearchText(SearchText.Text); HistorySearchText.Remove(SearchText.Text); if (HistorySearchText.Count >= MaxHistoryCount) { HistorySearchText.RemoveAt(HistorySearchText.Count - 1); } HistorySearchText.Insert(0, SearchText.Text); } } private List HistorySearchText = new List(); private const int MaxHistoryCount = 10; private void TextBox_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { TextBox text = e.Source as TextBox; if (text == null) { return; } if (string.IsNullOrEmpty(text.Text)) { return; } (DataContext as SearchContentViewModel).SearchText(text.Text); HistorySearchText.Remove(text.Text); if (HistorySearchText.Count >= MaxHistoryCount) { HistorySearchText.RemoveAt(HistorySearchText.Count - 1); } HistorySearchText.Insert(0, text.Text); } } /// /// 控制收起与展开 /// private void BtnExptend_Click(object sender, RoutedEventArgs e) { var btn = sender as PathButton; if (btn == null) return; btn.IsChecked = !btn.IsChecked; var item = (sender as FrameworkElement).DataContext as CollectionViewGroup; if (item != null) { foreach (object item2 in item.Items) { SearchItem searchItem = item2 as SearchItem; if (searchItem.TextProperty.ItemVisibility == Visibility.Visible) { searchItem.TextProperty.ItemVisibility = Visibility.Collapsed; } else { searchItem.TextProperty.ItemVisibility = Visibility.Visible; } } } } private void Create_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = sender as MenuItem; if (menuItem == null) { return; } foreach (object item in SearchResultList.SelectedItems) { (DataContext as SearchContentViewModel).CreateAnnotate(item, menuItem.Tag.ToString()); } } private void TextBoxEx_Initialized(object sender, EventArgs e) { var btn = sender as TextBoxEx; if (btn != null) { btn.ContextMenu = null; } } private void PathButton_Click(object sender, RoutedEventArgs e) { ContextSearchText.PlacementTarget = SearchText; ContextSearchText.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom; ContextSearchText.IsOpen = true; UpDataItem(); } private void UpDataItem() { foreach (var item in ContextSearchText.Items) { if (item is MenuItem) { (item as MenuItem).Click -= SearchContent_Click; } } ContextSearchText.Items.Clear(); ContextSearchText.Items.Add(IgnoreItem); if (HistorySearchText.Count > 0) { ContextSearchText.Items.Add(IgnoreSeparator); } foreach (var item in HistorySearchText) { MenuItem Searchitem = new MenuItem(); Searchitem.Height = 32; Searchitem.Header = item; Searchitem.Padding = new Thickness(0, 7, 0, 7); Searchitem.Click += SearchContent_Click; ContextSearchText.Items.Add(Searchitem); } if (HistorySearchText.Count > 0) { ContextSearchText.Items.Add(ClearSeparator); ContextSearchText.Items.Add(ClearItem); } } private void SearchContent_Click(object sender, RoutedEventArgs e) { MenuItem item = sender as MenuItem; if (item != null) { SearchText.Text = item.Header.ToString(); (DataContext as SearchContentViewModel).SearchText(SearchText.Text); } } private void ClearItem_Click(object sender, RoutedEventArgs e) { HistorySearchText.Clear(); UpDataItem(); } private void UserControl_Loaded(object sender, RoutedEventArgs e) { SearchText.Focus(); } private void UserControl_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Escape) { //Windows:BOTA列表,移除Esc取消选中逻辑 //SearchResultList.SelectedIndex = -1; //e.Handled = true; } } private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e) { SearchContent searchContent = sender as SearchContent; if (searchContent != null && searchContent.ActualWidth > 209 && searchContent.ActualWidth < 216) { SearchText.Focus(); } } private void SearchResultList_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { var pos = e.GetPosition(SearchResultList); var result = VisualTreeHelper.HitTest(SearchResultList, pos); if (result != null) { //获取当前鼠标指针下的容器 var listBoxItem = Helper.CommonHelper.FindVisualParent(result.VisualHit); if (listBoxItem == null) { if (SearchResultList.SelectedItem != null) { SearchResultList.SelectedIndex = -1; } } } } } private void SearchText_LostFocus(object sender, RoutedEventArgs e) { Updata = false; } private void SearchText_GotFocus(object sender, RoutedEventArgs e) { Updata = true; } } }