5
5
using System . Windows . Data ;
6
6
using System . Windows . Input ;
7
7
using Happy_Apps_Core ;
8
+ using Happy_Apps_Core . Database ;
8
9
using Happy_Reader . ViewModel ;
9
10
10
11
namespace Happy_Reader . View
@@ -15,7 +16,7 @@ public partial class FiltersPane : UserControl
15
16
// ReSharper disable once NotAccessedField.Local
16
17
private FiltersViewModel ViewModel => ( FiltersViewModel ) DataContext ;
17
18
private AutoCompleteBox _traitOrTagControl ;
18
-
19
+
19
20
public FiltersPane ( )
20
21
{
21
22
InitializeComponent ( ) ;
@@ -55,12 +56,12 @@ private void FilterTypeChanged(object sender, SelectionChangedEventArgs e)
55
56
if ( type == null ) return ;
56
57
FrameworkElement control ;
57
58
DependencyProperty bindingProperty = null ;
58
- var valueBinding = new Binding ( $ "{ nameof ( ViewModel . NewFilter ) } .{ nameof ( IFilter . Value ) } ") { Mode = BindingMode . OneWayToSource } ;
59
+ var valueBinding = new Binding ( $ "{ nameof ( ViewModel . NewFilter ) } .{ nameof ( IFilter . Value ) } ") { Mode = BindingMode . OneWayToSource } ;
59
60
if ( type . IsEnum )
60
61
{
61
62
control = new ComboBox
62
63
{
63
- ItemsSource = StaticMethods . GetEnumValues ( type ) ,
64
+ ItemsSource = StaticMethods . GetEnumValues ( type ) ,
64
65
SelectedIndex = 0 ,
65
66
SelectedValuePath = nameof ( Tag )
66
67
} ;
@@ -108,19 +109,25 @@ private void FilterTypeChanged(object sender, SelectionChangedEventArgs e)
108
109
control = _traitOrTagControl ;
109
110
bindingProperty = AutoCompleteBox . SelectedItemProperty ;
110
111
}
112
+ else if ( type == typeof ( ListedProducer ) )
113
+ {
114
+ _traitOrTagControl = new AutoCompleteBox ( ) { ItemFilter = ProducerBoxFilter , ItemsSource = StaticHelpers . LocalDatabase . Producers } ;
115
+ control = _traitOrTagControl ;
116
+ bindingProperty = AutoCompleteBox . SelectedItemProperty ;
117
+ }
111
118
else control = new TextBlock ( new System . Windows . Documents . Run ( type . ToString ( ) ) ) ;
112
119
}
113
- if ( bindingProperty != null ) control . SetBinding ( bindingProperty , valueBinding ) ;
120
+ if ( bindingProperty != null ) control . SetBinding ( bindingProperty , valueBinding ) ;
114
121
FilterValuesGrid . Children . Add ( control ) ;
115
122
}
116
-
123
+
117
124
private void RootControl_SelectionChanged ( object sender , SelectionChangedEventArgs e )
118
125
{
119
126
if ( e . AddedItems . Count == 0 ) return ;
120
127
var selectedTraitRoot = ( DumpFiles . RootTrait ) ( ( ComboBoxItem ) e . AddedItems [ 0 ] ) . Tag ;
121
128
_traitOrTagControl . ItemsSource = DumpFiles . GetTraitsForRoot ( selectedTraitRoot ) ;
122
129
}
123
-
130
+
124
131
private bool TraitOrTagBoxFilter ( string input , object item )
125
132
{
126
133
//Short input is not filtered to prevent excessive loading times
@@ -129,6 +136,14 @@ private bool TraitOrTagBoxFilter(string input, object item)
129
136
return trait . Name . ToLowerInvariant ( ) . Contains ( input . ToLowerInvariant ( ) ) ;
130
137
}
131
138
139
+ private bool ProducerBoxFilter ( string input , object item )
140
+ {
141
+ //Short input is not filtered to prevent excessive loading times
142
+ if ( input . Length <= 2 ) return false ;
143
+ var producer = ( ListedProducer ) item ;
144
+ return producer . Name . ToLowerInvariant ( ) . Contains ( input . ToLowerInvariant ( ) ) ;
145
+ }
146
+
132
147
private void NumberValidationTextBox ( object sender , TextCompositionEventArgs e )
133
148
{
134
149
var regex = new System . Text . RegularExpressions . Regex ( "[^0-9]+" ) ;
0 commit comments