116 lines
3.5 KiB
C#
116 lines
3.5 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.ComponentModel;
|
|||
|
|
using System.Globalization;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Runtime.CompilerServices;
|
|||
|
|
using System.Windows;
|
|||
|
|
using System.Windows.Controls;
|
|||
|
|
using System.Windows.Data;
|
|||
|
|
using System.Windows.Input;
|
|||
|
|
|
|||
|
|
using BeWo.Annotations;
|
|||
|
|
|
|||
|
|
using BS.Shared.Core;
|
|||
|
|
using BS.Shared.DataContracts;
|
|||
|
|
using BS.Shared.Extensions;
|
|||
|
|
|
|||
|
|
namespace BeWo.View.Search
|
|||
|
|
{
|
|||
|
|
public partial class TextModuleTreeSearchView : INotifyPropertyChanged
|
|||
|
|
{
|
|||
|
|
private BindingList<TextModuleDC> _List;
|
|||
|
|
private readonly List<TextModuleDC> _AllTextModules = new List<TextModuleDC>();
|
|||
|
|
|
|||
|
|
public BindingList<TextModuleDC> List
|
|||
|
|
{
|
|||
|
|
get => _List ?? new BindingList<TextModuleDC>();
|
|||
|
|
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
_List = value;
|
|||
|
|
OnPropertyChanged(nameof(List));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public TextModuleTreeSearchView()
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
DataContext = this;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void InitSearchView(List<TextModuleDC> pAllTextModules)
|
|||
|
|
{
|
|||
|
|
_AllTextModules.Clear();
|
|||
|
|
_AllTextModules.AddRange(pAllTextModules);
|
|||
|
|
List = new BindingList<TextModuleDC>(_AllTextModules);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public long ServiceCategoryOid { get; set; }
|
|||
|
|
|
|||
|
|
public TextModuleDC SelectedItem { get; set; }
|
|||
|
|
|
|||
|
|
public event EventHandler<EventArgs<TextModuleDC>> ItemSelected;
|
|||
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|||
|
|
|
|||
|
|
[NotifyPropertyChangedInvocator]
|
|||
|
|
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
|||
|
|
{
|
|||
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void TreeListControl_OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
|
|||
|
|
{
|
|||
|
|
var hitInfo = TreeListView.CalcHitInfo(e.OriginalSource as DependencyObject);
|
|||
|
|
if(hitInfo.InRowCell)
|
|||
|
|
{
|
|||
|
|
SelectedItem = (TextModuleDC)TreeListControl.SelectedItem;
|
|||
|
|
|
|||
|
|
if(SelectedItem != null && !SelectedItem.IsParent)
|
|||
|
|
{
|
|||
|
|
ItemSelected?.Invoke(this, new EventArgs<TextModuleDC>(SelectedItem));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
e.Handled = false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void UpdateFilteredList()
|
|||
|
|
{
|
|||
|
|
if(string.IsNullOrEmpty(TextBoxSearch.Text))
|
|||
|
|
{
|
|||
|
|
List = new BindingList<TextModuleDC>(_AllTextModules);
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var lFilter = TextBoxSearch.Text.ToLower().Split(" ");
|
|||
|
|
|
|||
|
|
var directHits = _AllTextModules.Where(w => w.Text != null && lFilter.Any(w.Text.ToLower().Contains) || lFilter.Any(w.Name.ToLower().Contains)).ToList();
|
|||
|
|
|
|||
|
|
directHits.AddRangeIfElementsNotIn(Utils.GetParentTextModules(directHits));
|
|||
|
|
|
|||
|
|
List = new BindingList<TextModuleDC>(directHits);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void TextBoxSearch_OnTextChanged(object sender, TextChangedEventArgs e)
|
|||
|
|
{
|
|||
|
|
UpdateFilteredList();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public class TextModuleFontWeightConverter : IValueConverter
|
|||
|
|
{
|
|||
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|||
|
|
{
|
|||
|
|
var isParent = value != null && (bool) value;
|
|||
|
|
|
|||
|
|
return isParent ? FontWeights.Bold : FontWeights.Normal;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|||
|
|
{
|
|||
|
|
throw new NotImplementedException();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|