123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- 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
- {
- /// <summary>
- /// SearchContent.xaml 的交互逻辑
- /// </summary>
- public partial class SearchContent : UserControl
- {
- bool Updata = false;
- private string unicode = "";
- public SearchContent()
- {
- InitializeComponent();
- unicode = App.mainWindowViewModel.SelectedItem.Unicode;
- }
- public SearchContent(IEventAggregator eventAggregator) : this()
- {
- eventAggregator.GetEvent<CleanSelectAllEvent>().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);
- }
- }
- List<string> HistorySearchText = new List<string>();
- 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);
- }
- }
- /// <summary>
- /// 控制收起与展开
- /// </summary>
- 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)
- {
- 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<ListViewItem>(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;
- }
- }
- }
|