Skip to content

Commit

Permalink
Filters: Added panel to easily switch between filters to edit and del…
Browse files Browse the repository at this point in the history
…ete multiple.
  • Loading branch information
Zoltanar committed Nov 25, 2023
1 parent 0e48309 commit bde373b
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 126 deletions.
184 changes: 108 additions & 76 deletions Happy Reader/View/FiltersPane.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,96 +7,128 @@
mc:Ignorable="d"
d:DesignHeight="500" d:DesignWidth="400" d:DataContext="{d:DesignInstance viewModel:FiltersViewModel}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<GroupBox Grid.Row="0" Header="Custom Filter" Margin="5,10,5,5">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Grid.Row="1" Content="Name" HorizontalAlignment="Left" Padding="0" Margin="0,5" VerticalContentAlignment="Center" Height="21"/>
<TextBox Grid.Row="1" Margin="37,5,82,5" Text="{Binding CustomFilter.Name}" VerticalContentAlignment="Center" Height="21" />
<Button Grid.Row="1" Content="Save" HorizontalAlignment="Right" Margin="0,5,48,5" Command="{Binding SaveCustomFilterCommand}" VerticalContentAlignment="Center" Height="21"/>
<Button Grid.Row="1" Content="Delete" HorizontalAlignment="Right" Margin="0,5,5,5" Click="DeleteCustomFilter" VerticalContentAlignment="Center" Height="21"/>
<TextBlock Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<DataGrid ItemsSource="{Binding Filters}" IsReadOnly="True"
CanUserAddRows="False" CanUserDeleteRows="True"
AutoGenerateColumns="False" CommandManager.PreviewCanExecute="PreviewDeleteFilter" SelectedCellsChanged="RowSelected">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
</DataGrid.Columns>
<DataGrid.Resources>
<Style TargetType="DataGridRow">
<EventSetter Event="MouseDoubleClick" Handler="Row_DoubleClick"/>
</Style>
</DataGrid.Resources>
</DataGrid>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<GroupBox Grid.Row="0" Header="Custom Filter" Margin="5,10,5,5">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Grid.Row="1" Content="Name" HorizontalAlignment="Left" Padding="0" Margin="0,5" VerticalContentAlignment="Center" Height="21"/>
<TextBox Grid.Row="1" Margin="37,5,82,5" Text="{Binding CustomFilterCopy.Name}" VerticalContentAlignment="Center" Height="21" />
<Button Grid.Row="1" Content="Save" HorizontalAlignment="Right" Margin="0,5,48,5" Command="{Binding SaveCustomFilterCommand}" VerticalContentAlignment="Center" Height="21"/>
<Button Grid.Row="1" Content="Delete" HorizontalAlignment="Right" Margin="0,5,5,5" Click="DeleteCustomFilter" VerticalContentAlignment="Center" Height="21"/>
<TextBlock Grid.Row="2">
<Run>AND Group</Run>
<LineBreak/>
<Run>(All of these are required)</Run>
</TextBlock>
<ListBox ItemsSource="{Binding CustomFilter.AndFilters}" Grid.Row="3" KeyUp="FilterKeyUp" MinHeight="23"/>
<TextBlock Grid.Row="4">
<Run>OR Group</Run>
<LineBreak/>
<Run>(One of these is required)</Run>
</TextBlock>
<ListBox ItemsSource="{Binding CustomFilter.OrFilters}" Grid.Row="5" KeyUp="FilterKeyUp" MinHeight="23"/>
<Button Content="Save OR Group" Grid.Row="6" Click="SaveOrGroup" Margin="5"/>
<Button Content="Apply Filter" Grid.Row="7" Click="ApplyFilterClick" Margin="5"/>
</Grid>
</GroupBox>
<GroupBox Grid.Row="1" Header="Add Filter" Margin="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="118*"/>
<ColumnDefinition Width="125*"/>
</Grid.ColumnDefinitions>
<!-- ReSharper disable once Xaml.BindingWithContextNotResolved -->
<ComboBox ItemsSource="{Binding FilterTypes}" SelectedIndex="{Binding SelectedFilterIndex, Mode=TwoWay}" SelectedValue="{Binding NewFilter.Type}"
SelectedValuePath="Tag" VerticalAlignment="Top" Grid.ColumnSpan="3"
SelectionChanged="FilterTypeChanged">
<ComboBox.ItemContainerStyle>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
<CheckBox Grid.Column="0" Content="OR Group" VerticalAlignment="Top" Margin="5,27,5,0" IsChecked="{Binding NewFilterOrGroup}" Grid.ColumnSpan="2" />
<CheckBox Grid.Column="1" Content="Exclude" VerticalAlignment="Top" Margin="5,27,5,0" IsChecked="{Binding NewFilter.Exclude}" />
<Grid x:Name="FilterValuesGrid" Grid.ColumnSpan="2" Grid.Column="0" Margin="0,47,0,25" MaxHeight="200"/>
<Button Grid.Column="0" Content="Add To Custom Filter" VerticalAlignment="Bottom" Margin="5,0" Command="{Binding AddToCustomFilterCommand}"/>
<Button Grid.Column="1" Content="Add To Permanent Filter" VerticalAlignment="Bottom" Margin="5,0" Command="{Binding AddToPermanentFilterCommand}"/>
</Grid>
</GroupBox>
<GroupBox Grid.Row="2" Header="Permanent Filter" Margin="5,5,5,10" x:Name="PermanentFilterGroupBox">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="AND Group (All of these are required)"/>
<ListBox Grid.Row="1" KeyUp="FilterKeyUp" ItemsSource="{Binding PermanentFilter.AndFilters}" MinHeight="23">
</TextBlock>
<ListBox ItemsSource="{Binding CustomFilterCopy.AndFilters}" Grid.Row="3" KeyUp="FilterKeyUp" MinHeight="23">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Top" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<Label Grid.Row="2" Content="OR Group (One of these is required)"/>
<ListBox Grid.Row="3" KeyUp="FilterKeyUp" ItemsSource="{Binding PermanentFilter.OrFilters}" MinHeight="23">
</ListBox>
<TextBlock Grid.Row="4">
<Run>OR Group</Run>
<LineBreak/>
<Run>(One of these is required)</Run>
</TextBlock>
<ListBox ItemsSource="{Binding CustomFilterCopy.OrFilters}" Grid.Row="5" KeyUp="FilterKeyUp" MinHeight="23">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Top" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<Button Content="Save OR Group" Grid.Row="4" Click="SaveOrGroup" Margin="5"/>
</Grid>
</GroupBox>
</ListBox>
<Button Content="Save OR Group" Grid.Row="6" Click="SaveOrGroup" Margin="5"/>
<Button Content="Apply Filter" Grid.Row="7" Click="ApplyFilterClick" Margin="5"/>
</Grid>
</GroupBox>
<GroupBox Grid.Row="1" Header="Add Filter" Margin="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="118*"/>
<ColumnDefinition Width="125*"/>
</Grid.ColumnDefinitions>
<!-- ReSharper disable once Xaml.BindingWithContextNotResolved -->
<ComboBox ItemsSource="{Binding FilterTypes}" SelectedIndex="{Binding SelectedFilterIndex, Mode=TwoWay}" SelectedValue="{Binding NewFilter.Type}"
SelectedValuePath="Tag" VerticalAlignment="Top" Grid.ColumnSpan="3"
SelectionChanged="FilterTypeChanged">
<ComboBox.ItemContainerStyle>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
<CheckBox Grid.Column="0" Content="OR Group" VerticalAlignment="Top" Margin="5,27,5,0" IsChecked="{Binding NewFilterOrGroup}" Grid.ColumnSpan="2" />
<CheckBox Grid.Column="1" Content="Exclude" VerticalAlignment="Top" Margin="5,27,5,0" IsChecked="{Binding NewFilter.Exclude}" />
<Grid x:Name="FilterValuesGrid" Grid.ColumnSpan="2" Grid.Column="0" Margin="0,47,0,25" MaxHeight="200"/>
<Button Grid.Column="0" Content="Add To Custom Filter" VerticalAlignment="Bottom" Margin="5,0" Command="{Binding AddToCustomFilterCommand}"/>
<Button Grid.Column="1" Content="Add To Permanent Filter" VerticalAlignment="Bottom" Margin="5,0" Command="{Binding AddToPermanentFilterCommand}"/>
</Grid>
</GroupBox>
<GroupBox Grid.Row="2" Header="Permanent Filter" Margin="5,5,5,10" x:Name="PermanentFilterGroupBox">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="AND Group (All of these are required)"/>
<ListBox Grid.Row="1" KeyUp="FilterKeyUp" ItemsSource="{Binding PermanentFilter.AndFilters}" MinHeight="23">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Top" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<Label Grid.Row="2" Content="OR Group (One of these is required)"/>
<ListBox Grid.Row="3" KeyUp="FilterKeyUp" ItemsSource="{Binding PermanentFilter.OrFilters}" MinHeight="23">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Top" />
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<Button Content="Save OR Group" Grid.Row="4" Click="SaveOrGroup" Margin="5"/>
</Grid>
</GroupBox>
</Grid>
</Grid>
</UserControl>
25 changes: 25 additions & 0 deletions Happy Reader/View/FiltersPane.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,30 @@ private async void ApplyFilterClick(object sender, RoutedEventArgs e)
{
await ViewModel.ApplyCurrentFilter();
}

private void PreviewDeleteFilter(object sender, CanExecuteRoutedEventArgs e)
{
var grid = (DataGrid)sender;
if (e.Command != DataGrid.DeleteCommand) return;
if(grid.SelectedItems.Count == 0) return;
var message = "Are you sure you wish to delete ";
if (grid.SelectedItems.Count > 1) message += $"{grid.SelectedItems.Count} filters?";
else message += $"filter '{((CustomFilter)grid.SelectedItems[0]).Name}' ?";
if (MessageBox.Show(message,StaticHelpers.ClientName, MessageBoxButton.YesNo) != MessageBoxResult.Yes) e.Handled = true;
}

private void Row_DoubleClick(object sender, MouseButtonEventArgs e)
{
var row = (DataGridRow)sender;
if (row is not { DataContext: CustomFilter filter }) return;
ViewModel.SelectFilter(filter);
}

private void RowSelected(object sender, SelectedCellsChangedEventArgs e)
{
if (e.AddedCells.Count != 1) return;
var filter = (CustomFilter)e.AddedCells[0].Item;
ViewModel.CustomFilter = filter;
}
}
}
5 changes: 3 additions & 2 deletions Happy Reader/View/Tabs/DatabaseTab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
<view:FiltersPane x:Name="FiltersPane" Grid.Column="1" Visibility="Collapsed" MinWidth="250" MaxWidth="400" DataContext="{Binding FiltersViewModel}"/>
<view:FiltersPane x:Name="FiltersPane" Grid.Column="1" Visibility="Collapsed" MinWidth="250" MaxWidth="600" DataContext="{Binding FiltersViewModel}"/>
</Grid>
<Label Content="Search:" HorizontalAlignment="Left" VerticalContentAlignment="Center" Grid.Row="1" Margin="0"/>
<TextBox Margin="65,0,321,0" TextWrapping="Wrap" VerticalContentAlignment="Center" PreviewKeyUp="SearchByText" Height="30" VerticalAlignment="Stretch" Grid.Row="1"/>
Expand All @@ -67,7 +67,8 @@
<controls:AutoCompleteBox Height="30" Grid.Row="2" FilterMode="Custom" ItemsSource="{Binding ProducerList}" ValueMemberPath="Name" ItemFilter="ProducerBoxFilter" KeyUp="SelectProducerOnKey" MouseUp="ProducerItemClicked" Margin="65,0,321,0"/>
<Button Content="Suggested" Click="ShowSuggested" Height="30" Grid.Row="1" HorizontalAlignment="Right" Width="76" Margin="0,0,44,0"/>
<Button Content="Filters" Click="ShowFilters" Height="30" Grid.Row="2" HorizontalAlignment="Right" Width="39"/>
<ComboBox ItemsSource="{Binding FiltersViewModel.Filters}" SelectedItem="{Binding SelectedFilter}" Height="30" Grid.Row="2" VerticalAlignment="Stretch" Margin="0,0,44,0" HorizontalAlignment="Right" Width="272" MaxDropDownHeight="720">
<ComboBox ItemsSource="{Binding FiltersViewModel.Filters}" SelectedIndex="{Binding SelectedFilterIndex, Mode=TwoWay}"
Height="30" Grid.Row="2" VerticalAlignment="Stretch" Margin="0,0,44,0" HorizontalAlignment="Right" Width="272" MaxDropDownHeight="720">
<ComboBox.ItemContainerStyle>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="HorizontalContentAlignment" Value="Left"/>
Expand Down
4 changes: 2 additions & 2 deletions Happy Reader/View/Tabs/DatabaseTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public partial class DatabaseTab : UserControl

private void ListboxPreviewMouseUp(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton != MouseButtonState.Released) return;
if (e.LeftButton != MouseButtonState.Released || !_loaded) return;
AddPageIfAtEnd();
}

Expand All @@ -41,7 +41,7 @@ private void AddPageIfAtEnd()
var viewHeight = scrollViewer.ViewportHeight;
//if the (starting) position of the scrollbar plus the length of the scrollbar exceed or equal the total scroll height,
//then we are at the end and want to add a new page.
if (position + viewHeight >= maxHeight) ViewModel.AddPage();
if (maxHeight>0 && position + viewHeight >= maxHeight) ViewModel.AddPage();
}


Expand Down
2 changes: 1 addition & 1 deletion Happy Reader/View/VnMenuItem.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private void ShowByStaffArtScenario(object sender, RoutedEventArgs e)
filter.SaveOrGroup();
}
StaticMethods.MainWindow.SelectTab(typeof(VNTabViewModel));
StaticMethods.MainWindow.ViewModel.DatabaseViewModel.SelectedFilter = filter;
StaticMethods.MainWindow.ViewModel.DatabaseViewModel.ActiveFilter = filter;
}

private async void ChangeLabel(object sender, RoutedEventArgs e)
Expand Down
9 changes: 5 additions & 4 deletions Happy Reader/ViewModel/CharactersTabViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public override async Task Initialize()
MainViewModel.StatusText = "Loading Characters...";
OnPropertyChanged(nameof(ProducerList));
LocalDatabase.SetCharactersAttachedVisualNovels();
await RefreshTiles();
SelectedFilterIndex = 0;
//await RefreshTiles();
}

protected override Func<IDataItem<int>, double?> GetSuggestion { get; } = i => ((CharacterItem)i).TraitScore;
Expand All @@ -42,22 +43,22 @@ public void ShowForVisualNovel(CharacterVN visualNovel)
var vn = LocalDatabase.VisualNovels[visualNovel.VNId];
var cf = new CustomFilter($"VN: {TruncateString15(vn.Title)}");
cf.AndFilters.Add(new GeneralFilter(GeneralFilterType.VNID, vn.VNID));
SelectedFilter = cf;
ActiveFilter = cf;
}

public void ShowForSeiyuuWithAlias(int aliasId)
{
var staff = LocalDatabase.StaffAliases[aliasId];
var cf = new CustomFilter($"Seiyuu: {staff}");
cf.AndFilters.Add(new GeneralFilter(GeneralFilterType.Seiyuu, aliasId));
SelectedFilter = cf;
ActiveFilter = cf;
}

public void ShowWithTrait(DumpFiles.WrittenTrait trait)
{
var cf = new CustomFilter($"Trait: {trait}");
cf.AndFilters.Add(new GeneralFilter(GeneralFilterType.Traits, trait.ID));
SelectedFilter = cf;
ActiveFilter = cf;
}
}
}
Loading

0 comments on commit bde373b

Please sign in to comment.