Search bar

This commit is contained in:
Assistant 2020-05-16 05:31:38 -06:00
parent 51f99aebbf
commit 39843e706c
4 changed files with 94 additions and 0 deletions

View file

@ -71,6 +71,7 @@
<sys:String x:Key="Mods:UninstallBox:Body2">Mods:UninstallBox:Body2</sys:String>
<sys:String x:Key="Mods:FailedExtract">{0} {1} {2} {3} Mods:FailedExtract</sys:String>
<sys:String x:Key="Mods:FailedExtractMaxReached">{0} {1} Mods:FailedExtractMaxReached</sys:String>
<sys:String x:Key="Mods:SearchLabel">Mods:SearchLabel</sys:String>
<!-- About Page -->
<sys:String x:Key="About:Title">About:Title</sys:String>

View file

@ -102,6 +102,7 @@
<sys:String x:Key="Mods:UninstallBox:Body2">This could break your other mods</sys:String>
<sys:String x:Key="Mods:FailedExtract">Failed to extract {0}, trying again in {1} seconds. ({2}/{3})</sys:String>
<sys:String x:Key="Mods:FailedExtractMaxReached">Failed to extract {0} after max attempts ({1}), skipping. This mod might not work properly so proceed at your own risk</sys:String>
<sys:String x:Key="Mods:SearchLabel">Search...</sys:String>
<!-- About Page -->
<sys:String x:Key="About:Title">About</sys:String>

View file

@ -12,15 +12,51 @@
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock
Name="SearchText"
Padding="5,0,0,0"
Height="0"
Grid.Row="0"
Text="{DynamicResource Mods:SearchLabel}"
Panel.ZIndex="1"
Foreground="{DynamicResource TextColor}"
Background="{DynamicResource BottomStatusBarBackground}" />
<TextBox
Name="SearchBar"
Margin="0,-1,0,0"
Padding="3,1,0,0"
Height="0"
Grid.Row="0"
Panel.ZIndex="2"
Background="#00000000"
Foreground="{DynamicResource TextColor}"
TextChanged="SearchBar_TextChanged"
BorderThickness="0" />
<ListView
Name="ModsListView"
Grid.Column="1"
Grid.Row="1"
SelectionChanged="ModsListView_SelectionChanged"
SelectionMode="Single">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Width="30">
<GridViewColumn.Header>
<Button
Name="SearchButton"
Background="#00000000"
BorderThickness="0"
Click="SearchButton_Click"
Padding="9,-1,9,0"
Margin="-5"
Content="🔍"
FontSize="11" />
</GridViewColumn.Header>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox

View file

@ -12,6 +12,8 @@ using System.Windows.Forms;
using System.Windows.Navigation;
using static ModAssistant.Http;
using ModAssistant.Libs;
using System.Windows.Media.Animation;
using TextBox = System.Windows.Controls.TextBox;
namespace ModAssistant.Pages
{
@ -717,5 +719,59 @@ namespace ModAssistant.Pages
System.Windows.Clipboard.SetText(((TextBlock)sender).Text);
Utils.SendNotify("Copied text to clipboard");
}
private void SearchButton_Click(object sender, RoutedEventArgs e)
{
if (SearchBar.Height == 0)
{
SearchBar.Focus();
Animate(SearchBar, 0, 16, new TimeSpan(0, 0, 0, 0, 300));
Animate(SearchText, 0, 16, new TimeSpan(0, 0, 0, 0, 300));
ModsListView.Items.Filter = new Predicate<object>(SearchFilter);
}
else
{
Animate(SearchBar, 16, 0, new TimeSpan(0, 0, 0, 0, 300));
Animate(SearchText, 16, 0, new TimeSpan(0, 0, 0, 0, 300));
ModsListView.Items.Filter = null;
}
}
private void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
{
ModsListView.Items.Filter = new Predicate<object>(SearchFilter);
if (SearchBar.Text.Length > 0)
{
SearchText.Text = null;
}
else
{
SearchText.Text = "Search...";
}
}
private bool SearchFilter(object mod)
{
ModListItem item = mod as ModListItem;
if (item.ModName.ToLower().Contains(SearchBar.Text.ToLower())) return true;
if (item.ModDescription.ToLower().Contains(SearchBar.Text.ToLower())) return true;
if (item.ModName.ToLower().Replace(" ", string.Empty).Contains(SearchBar.Text.ToLower().Replace(" ", string.Empty))) return true;
if (item.ModDescription.ToLower().Replace(" ", string.Empty).Contains(SearchBar.Text.ToLower().Replace(" ", string.Empty))) return true;
return false;
}
private void Animate(TextBlock target, double oldHeight, double newHeight, TimeSpan duration)
{
target.Height = oldHeight;
DoubleAnimation animation = new DoubleAnimation(newHeight, duration);
target.BeginAnimation(TextBlock.HeightProperty, animation);
}
private void Animate(TextBox target, double oldHeight, double newHeight, TimeSpan duration)
{
target.Height = oldHeight;
DoubleAnimation animation = new DoubleAnimation(newHeight, duration);
target.BeginAnimation(TextBox.HeightProperty, animation);
}
}
}