Browse Source

Added search by name

Krzysztof Krysiński 3 years ago
parent
commit
66dbff9ea8

+ 7 - 2
PixiEditor/Models/DataHolders/Palettes/FilteringSettings.cs

@@ -10,16 +10,21 @@ namespace PixiEditor.Models.DataHolders.Palettes
         public int ColorsCount { get; set; }
         public string[] Tags { get; set; }
 
-        public FilteringSettings(ColorsNumberMode colorsNumberMode, int colorsCount, string[] tags)
+        public string Name { get; set; }
+
+        public FilteringSettings(ColorsNumberMode colorsNumberMode, int colorsCount, string[] tags, string name)
         {
             ColorsNumberMode = colorsNumberMode;
             ColorsCount = colorsCount;
             Tags = tags;
+            Name = name;
         }
 
         public bool Filter(Palette palette)
         {
-            bool result = true;
+            // Lexical comparison
+            bool result = palette.Title.Contains(Name, StringComparison.OrdinalIgnoreCase);
+            if (string.IsNullOrWhiteSpace(Name)) result = true;
 
             switch (ColorsNumberMode)
             {

+ 5 - 1
PixiEditor/Views/Dialogs/PalettesBrowser.xaml

@@ -67,9 +67,13 @@
                         </Image.Style>
                     </Image>
                 </ToggleButton>
+                <Label Margin="10 0 0 0" Content="Name:" Style="{StaticResource BaseLabel}" VerticalAlignment="Center" FontSize="16"/>
+                <usercontrols:InputBox OnSubmit="NameInput_OnSubmit" FontSize="16" VerticalAlignment="Center"
+                                       Style="{StaticResource DarkTextBoxStyle}" Width="125" />
+
                 <Label Margin="10 0 0 0" Content="Tags:" Style="{StaticResource BaseLabel}" VerticalAlignment="Center" FontSize="16"/>
                 <usercontrols:InputBox OnSubmit="TagsInput_OnSubmit" FontSize="16" VerticalAlignment="Center" 
-                                       Style="{StaticResource DarkTextBoxStyle}" Width="250" />
+                                       Style="{StaticResource DarkTextBoxStyle}" Width="125" />
                 <Label Margin="10 0 0 0" Content="Colors:" Style="{StaticResource BaseLabel}" VerticalAlignment="Center" FontSize="16"/>
                 <ComboBox Name="colorsComboBox" FontSize="16" VerticalAlignment="Center" SelectionChanged="ColorsComboBox_SelectionChanged">
                     <ComboBoxItem IsSelected="True">Any</ComboBoxItem>

+ 19 - 9
PixiEditor/Views/Dialogs/PalettesBrowser.xaml.cs

@@ -91,17 +91,23 @@ namespace PixiEditor.Views.Dialogs
             get { return (WpfObservableRangeCollection<Palette>)GetValue(SortedResultsProperty); }
             set { SetValue(SortedResultsProperty, value); }
         }
+
+        public static readonly DependencyProperty NameFilterProperty = DependencyProperty.Register(
+            "NameFilter", typeof(string), typeof(PalettesBrowser), new PropertyMetadata(default(string)));
+
+        public string NameFilter
+        {
+            get { return (string)GetValue(NameFilterProperty); }
+            set { SetValue(NameFilterProperty, value); }
+        }
+
         public string SortingType { get; set; } = "Default";
         public ColorsNumberMode ColorsNumberMode { get; set; } = ColorsNumberMode.Any;
         public string[] Tags { get; set; } = Array.Empty<string>();
 
         private FilteringSettings _filteringSettings;
 
-        public FilteringSettings Filtering
-        {
-            get => _filteringSettings ??= new FilteringSettings(ColorsNumberMode, ColorsNumber, Tags);
-            set => _filteringSettings = value;
-        }
+        public FilteringSettings Filtering => _filteringSettings ??= new FilteringSettings(ColorsNumberMode, ColorsNumber, Tags, NameFilter);
 
         private char[] _separators = new char[] { ' ', ',' };
 
@@ -139,10 +145,7 @@ namespace PixiEditor.Views.Dialogs
         public async Task UpdatePaletteList()
         {
             IsFetching = true;
-            if(PaletteList?.Palettes != null)
-            {
-                PaletteList.Palettes.Clear();
-            }
+            PaletteList?.Palettes?.Clear();
 
             for (int i = 0; i < PaletteListDataSources.Count; i++)
             {
@@ -210,6 +213,13 @@ namespace PixiEditor.Views.Dialogs
             scrollViewer.ScrollToHome();
         }
 
+        private async void NameInput_OnSubmit(object sender, InputBoxEventArgs e)
+        {
+            NameFilter = e.Input;
+            Filtering.Name = NameFilter;
+            await UpdatePaletteList();
+            scrollViewer.ScrollToHome();
+        }
 
         private async void ColorsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {