123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- using PDF_Office.CustomControl;
- using PDF_Office.Model.BOTA;
- using PDF_Office.ViewModels.BOTA;
- 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_Office.Views.BOTA
- {
- /// <summary>
- /// SearchContent.xaml 的交互逻辑
- /// </summary>
- public partial class SearchContent : UserControl
- {
- public SearchContent()
- {
- InitializeComponent();
- }
- 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;
- }
- }
- }
- }
|