Added EditQuickFilters dialog
This commit is contained in:
parent
eff9c2b35d
commit
82d8d954ef
@ -0,0 +1,103 @@
|
||||
<Window xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="350"
|
||||
Width="800" Height="450"
|
||||
x:Class="LibationWinForms.AvaloniaUI.Views.Dialogs.EditQuickFilters"
|
||||
Title="Audible Accounts"
|
||||
Icon="/AvaloniaUI/Assets/libation.ico">
|
||||
<Grid RowDefinitions="*,Auto">
|
||||
|
||||
<Grid.Styles>
|
||||
<Style Selector="Button:focus">
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource SystemAccentColor}" />
|
||||
<Setter Property="BorderThickness" Value="2" />
|
||||
</Style>
|
||||
</Grid.Styles>
|
||||
|
||||
<DataGrid
|
||||
Grid.Row="0"
|
||||
CanUserReorderColumns="False"
|
||||
CanUserResizeColumns="False"
|
||||
CanUserSortColumns="False"
|
||||
AutoGenerateColumns="False"
|
||||
IsReadOnly="False"
|
||||
Items="{Binding Filters}"
|
||||
GridLinesVisibility="All">
|
||||
|
||||
<DataGrid.Columns>
|
||||
|
||||
<DataGridTemplateColumn Header="Delete">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
|
||||
<Button
|
||||
Width="55"
|
||||
Height="30"
|
||||
Content="X"
|
||||
IsEnabled="{Binding !IsDefault}"
|
||||
Click="DeleteButton_Clicked" />
|
||||
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTextColumn
|
||||
Width="*"
|
||||
IsReadOnly="False"
|
||||
Binding="{Binding FilterString, Mode=TwoWay}"
|
||||
Header="Filter"/>
|
||||
|
||||
|
||||
<DataGridTemplateColumn Header="Move
Up">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
|
||||
<Button
|
||||
Width="50"
|
||||
Height="30"
|
||||
Content="▲"
|
||||
IsEnabled="{Binding !IsDefault}"
|
||||
ToolTip.Tip="Export account authorization to audible-cli"
|
||||
Click="MoveUpButton_Clicked" />
|
||||
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
|
||||
|
||||
<DataGridTemplateColumn Header="Move
Down">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
|
||||
<Button
|
||||
Width="50"
|
||||
Height="30"
|
||||
Content="▼"
|
||||
IsEnabled="{Binding !IsDefault}"
|
||||
ToolTip.Tip="Export account authorization to audible-cli"
|
||||
Click="MoveDownButton_Clicked" />
|
||||
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<Grid
|
||||
Grid.Row="1"
|
||||
Margin="10"
|
||||
ColumnDefinitions="*,Auto" >
|
||||
|
||||
<Button
|
||||
Grid.Column="1"
|
||||
Height="30"
|
||||
Padding="30,3,30,3"
|
||||
Content="Save"
|
||||
Click="SaveButton_Clicked" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Window>
|
||||
@ -0,0 +1,107 @@
|
||||
using AudibleUtilities;
|
||||
using Avalonia.Controls;
|
||||
using LibationFileManager;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace LibationWinForms.AvaloniaUI.Views.Dialogs
|
||||
{
|
||||
public partial class EditQuickFilters : DialogWindow
|
||||
{
|
||||
public ObservableCollection<Filter> Filters { get; } = new();
|
||||
|
||||
public class Filter : ViewModels.ViewModelBase
|
||||
{
|
||||
private string _filterString;
|
||||
public string FilterString
|
||||
{
|
||||
get => _filterString;
|
||||
set
|
||||
{
|
||||
this.RaiseAndSetIfChanged(ref _filterString, value);
|
||||
IsDefault = string.IsNullOrEmpty(_filterString);
|
||||
this.RaisePropertyChanged(nameof(IsDefault));
|
||||
}
|
||||
}
|
||||
public bool IsDefault { get; private set; } = true;
|
||||
}
|
||||
public EditQuickFilters()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
// WARNING: accounts persister will write ANY EDIT to object immediately to file
|
||||
// here: copy strings and dispose of persister
|
||||
// only persist in 'save' step
|
||||
using var persister = AudibleApiStorage.GetAccountsSettingsPersister();
|
||||
var accounts = persister.AccountsSettings.Accounts;
|
||||
if (!accounts.Any())
|
||||
return;
|
||||
|
||||
ControlToFocusOnShow = this.FindControl<Button>(nameof(SaveButton_Clicked));
|
||||
|
||||
var allFilters = QuickFilters.Filters.Select(f => new Filter { FilterString = f }).ToList();
|
||||
allFilters.Add(new Filter());
|
||||
|
||||
foreach (var f in allFilters)
|
||||
f.PropertyChanged += Filter_PropertyChanged;
|
||||
|
||||
Filters = new(allFilters);
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
private void Filter_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (Filters.Any(f => f.IsDefault))
|
||||
return;
|
||||
Filters.Insert(Filters.Count, new Filter());
|
||||
}
|
||||
|
||||
protected override void SaveAndClose()
|
||||
{
|
||||
QuickFilters.ReplaceAll(Filters.Where(f => !f.IsDefault).Select(f => f.FilterString));
|
||||
base.SaveAndClose();
|
||||
}
|
||||
|
||||
public void DeleteButton_Clicked(object sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
if (e.Source is Button btn && btn.DataContext is Filter filter)
|
||||
{
|
||||
var index = Filters.IndexOf(filter);
|
||||
if (index < 0) return;
|
||||
|
||||
filter.PropertyChanged -= Filter_PropertyChanged;
|
||||
Filters.Remove(filter);
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveUpButton_Clicked(object sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
if (e.Source is Button btn && btn.DataContext is Filter filter)
|
||||
{
|
||||
var index = Filters.IndexOf(filter);
|
||||
if (index < 1) return;
|
||||
|
||||
Filters.Remove(filter);
|
||||
Filters.Insert(index - 1, filter);
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveDownButton_Clicked(object sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
if (e.Source is Button btn && btn.DataContext is Filter filter)
|
||||
{
|
||||
var index = Filters.IndexOf(filter);
|
||||
if (index >= Filters.Count - 2) return;
|
||||
|
||||
Filters.Remove(filter);
|
||||
Filters.Insert(index + 1, filter);
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveButton_Clicked(object sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
{
|
||||
SaveAndClose();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -59,7 +59,8 @@ namespace LibationWinForms.AvaloniaUI.Views
|
||||
public void addQuickFilterBtn_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
=> QuickFilters.Add(_viewModel.FilterString);
|
||||
|
||||
public void editQuickFiltersToolStripMenuItem_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e) => new EditQuickFilters().ShowDialog();
|
||||
public async void editQuickFiltersToolStripMenuItem_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
|
||||
=> await new Dialogs.EditQuickFilters().ShowDialog(this);
|
||||
|
||||
public async void ProductsDisplay_Initialized(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
@ -109,6 +109,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="AvaloniaUI\Views\Dialogs\EditQuickFilters.axaml.cs">
|
||||
<DependentUpon>EditQuickFilters.axaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="AvaloniaUI\Views\Dialogs\BookDetailsDialog.axaml.cs">
|
||||
<DependentUpon>BookDetailsDialog.axaml</DependentUpon>
|
||||
</Compile>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user