feat(wpf): order danmaku merge files by their path

This commit is contained in:
genteure 2023-07-20 19:22:52 +08:00
parent 0c30c49ebb
commit 071087bea1
2 changed files with 23 additions and 11 deletions

View File

@ -6,16 +6,26 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:l="https://github.com/XAMLMarkupExtensions/WPFLocalizationExtension"
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
l:LocalizeDictionary.DesignCulture=""
l:ResxLocalizationProvider.DefaultAssembly="BililiveRecorder.WPF"
l:ResxLocalizationProvider.DefaultDictionary="Strings"
mc:Ignorable="d" DataContext="{x:Null}"
d:DesignHeight="450" d:DesignWidth="800"
Title="ToolboxDanmakuMergerPage">
<Grid>
<Grid.Resources>
<ui:Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/ModernWpf;component/DensityStyles/Compact.xaml" />
</Grid.Resources>
</ResourceDictionary.MergedDictionaries>
<CollectionViewSource x:Key="cvs">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="Path" Direction="Ascending"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</ResourceDictionary>
</ui:Page.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
@ -28,7 +38,7 @@
<Button Margin="0,0,5,0" Content="{l:Loc Toolbox_Merge_Button_AddFile}" Click="AddFile_Click"/>
<Button Content="{l:Loc Toolbox_Merge_Button_Merge}" Click="Merge_Click"/>
</StackPanel>
<ListView Grid.Row="3" Margin="5" x:Name="listView" AllowDrop="True" Drop="DragDrop">
<ListView Grid.Row="3" Margin="5" x:Name="listView" ItemsSource="{Binding Source={StaticResource cvs}}" AllowDrop="True" Drop="DragDrop">
<ListView.View>
<GridView AllowsColumnReorder="False">
<GridViewColumn>
@ -41,7 +51,8 @@
</GridViewColumn>
<GridViewColumn Header="偏移量(秒)" Width="120">
<GridViewColumn.CellTemplate>
<DataTemplate><!--
<DataTemplate>
<!--
<ui:NumberBox Minimum="0" SmallChange="1" LargeChange="10" Text="{Binding Offset,UpdateSourceTrigger=PropertyChanged}"
SpinButtonPlacementMode="Inline" ValidationMode="InvalidInputOverwritten"/>
-->

View File

@ -6,6 +6,7 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Threading;
using BililiveRecorder.ToolBox;
using BililiveRecorder.ToolBox.Tool.DanmakuMerger;
@ -32,7 +33,9 @@ namespace BililiveRecorder.WPF.Pages
public ToolboxDanmakuMergerPage()
{
this.InitializeComponent();
this.listView.ItemsSource = this.Files;
var cvs = (CollectionViewSource)this.FindResource("cvs");
cvs.Source = this.Files;
}
private void RemoveFile_Click(object sender, RoutedEventArgs e)
@ -86,7 +89,8 @@ namespace BililiveRecorder.WPF.Pages
private async Task AddFilesAsync(string[] paths)
{
var req = new DanmakuStartTimeRequest { Inputs = paths };
// filter duplicate file paths
var req = new DanmakuStartTimeRequest { Inputs = paths.Where(x => !this.Files.Any(f => f.Path == x)).ToArray() };
var handler = new DanmakuStartTimeHandler();
var resp = await handler.Handle(req, default, default).ConfigureAwait(true);
@ -111,9 +115,6 @@ namespace BililiveRecorder.WPF.Pages
{
item.Offset = (int)(item.StartTime - minTime).TotalSeconds;
}
this.listView.DataContext = null;
this.listView.DataContext = this.Files;
}
#pragma warning disable VSTHRD100 // Avoid async void methods
@ -188,7 +189,7 @@ namespace BililiveRecorder.WPF.Pages
logger.Debug("弹幕合并结果 {@Response}", resp);
if (resp.Status != ResponseStatus.Cancelled && resp.Status != ResponseStatus.OK)
if (resp.Status is not ResponseStatus.Cancelled and not ResponseStatus.OK)
{
logger.Warning(resp.Exception, "弹幕合并时发生错误 (@Status)", resp.Status);
await Task.Run(() => ShowErrorMessageBox(resp)).ConfigureAwait(true);