Skip to content

Commit

Permalink
Change ListView to DataGrid, add filter textbox
Browse files Browse the repository at this point in the history
  • Loading branch information
segabl committed May 6, 2021
1 parent b5a3706 commit aa5ea2e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 56 deletions.
54 changes: 17 additions & 37 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI"
xmlns:adonisControls="clr-namespace:AdonisUI.Controls;assembly=AdonisUI"
xmlns:adonisExtensions="clr-namespace:AdonisUI.Extensions;assembly=AdonisUI"
Closed="OnWindowClosed"
Title="PD2 Soundbank Editor"
Height="360"
Expand Down Expand Up @@ -55,43 +56,21 @@
</MenuItem>
</Menu>

<ListView Name="listView" Grid.Column="0" Grid.Row="1" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" SelectionChanged="OnListViewSelectionChanged" SizeChanged="OnListViewSizeChanged">
<ListView.Resources>
<Style TargetType="{x:Type GridViewColumnHeader}" BasedOn="{StaticResource {x:Type GridViewColumnHeader}}">
<Setter Property="HorizontalContentAlignment" Value="Left" />
</Style>
<Style TargetType="{x:Type ListView}" BasedOn="{StaticResource {x:Type ListView}}">
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="ListViewItem" BasedOn="{StaticResource {x:Type ListViewItem}}">
<Setter Property="VerticalContentAlignment" Value="Center"/>
</Style>
</Setter.Value>
</Setter>
</Style>
</ListView.Resources>
<ListView.View>
<GridView>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Content="" Click="OnPlayButtonClick" Width="20" Height="20" Padding="0,0,0,0"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="ID" DisplayMemberBinding="{Binding Id}" />
<GridViewColumn Header="Size" DisplayMemberBinding="{Binding Size, StringFormat={}{0:0.0} KB}" />
<GridViewColumn Header="Note" DisplayMemberBinding="{Binding Note}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Width="96" Height="20" Padding="0,0,0,0" Margin="0, 0, 0, 0" Background="{x:Null}" BorderThickness="0" Text="{Binding Note}"></TextBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Replacement" DisplayMemberBinding="{Binding ReplacementFile}" />
</GridView>
</ListView.View>
</ListView>
<DataGrid Name="dataGrid" AutoGenerateColumns="False" Grid.Column="0" Grid.Row="1" SelectionChanged="OnDataGridSelectionChanged" HorizontalScrollBarVisibility="Disabled">
<DataGrid.Columns>
<DataGridTemplateColumn SortMemberPath="Offset" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="" Click="OnPlayButtonClick" Width="20" Height="20" Padding="0,0,0,0"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="ID" Binding="{Binding Id}" IsReadOnly="True"/>
<DataGridTextColumn Header="Size" Binding="{Binding Size, StringFormat={}{0:0.0} KB}" IsReadOnly="True"/>
<DataGridTextColumn Width="*" Header="Note" Binding="{Binding Note}" IsReadOnly="False"/>
<DataGridTextColumn Width="*" Header="Replacement" Binding="{Binding ReplacementFile}" IsReadOnly="True"/>
</DataGrid.Columns>
</DataGrid>

<Grid Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="8,0,0,0">
<Grid.RowDefinitions>
Expand All @@ -104,6 +83,7 @@
<Button Grid.Row="0" Name="extractAllButton" Content="Extract all" Click="OnExtractButtonClick" IsEnabled="False" Height="24"/>
<Button Grid.Row="1" Name="extractSelectedButton" Content="Extract selected" Click="OnExtractButtonClick" IsEnabled="False" Height="24"/>
<Button Grid.Row="2" Name="replaceSelectedButton" Content="Replace selected..." Click="OnReplaceButtonClick" IsEnabled="False" Height="24" Margin="0,8,0,0"/>
<TextBox Grid.Row="4" Name="filterTextBox" adonisExtensions:WatermarkExtension.Watermark="Filter" TextChanged="OnFilterTextBoxChanged" IsEnabled="False" Height="24"/>
</Grid>
</Grid>
<ProgressBar Name="progressBar" Margin="8,8,8,8" VerticalAlignment="Bottom" Height="16"/>
Expand Down
40 changes: 22 additions & 18 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
Expand Down Expand Up @@ -106,6 +107,7 @@ private void CommandSaveCanExecute(object sender, System.Windows.Input.CanExecut

private void CommandSaveExecuted(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) {
soundBank.Save(soundBank.FilePath);
Title = $"PD2 Soundbank Editor - {Path.GetFileName(soundBank.FilePath)}";
}
private void CommandSaveAsCanExecute(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e) {
e.CanExecute = soundBank != null && soundBank.StreamInfos.Count > 0;
Expand Down Expand Up @@ -145,7 +147,7 @@ private void OnAboutButtonClick(object sender, RoutedEventArgs e) {
}

private void OnExtractButtonClick(object sender, RoutedEventArgs e) {
DoGenericProcessing(true, ExtractStreams, OnExtractStreamsFinished, ((Button)sender) == extractAllButton ? soundBank.StreamInfos : listView.SelectedItems.Cast<StreamInfo>());
DoGenericProcessing(true, ExtractStreams, OnExtractStreamsFinished, ((Button)sender) == extractAllButton ? soundBank.StreamInfos : dataGrid.SelectedItems.Cast<StreamInfo>());
}

private void OnReplaceButtonClick(object sender, RoutedEventArgs e) {
Expand All @@ -164,7 +166,7 @@ private void OnReplaceButtonClick(object sender, RoutedEventArgs e) {
return;
}
var data = File.ReadAllBytes(fileName);
foreach (var info in listView.SelectedItems.Cast<StreamInfo>()) {
foreach (var info in dataGrid.SelectedItems.Cast<StreamInfo>()) {
info.Data = data;
info.ReplacementFile = fileNameNoExt + ".wav";
info.ConvertedFilePath = null;
Expand All @@ -173,6 +175,19 @@ private void OnReplaceButtonClick(object sender, RoutedEventArgs e) {
Title = $"PD2 Soundbank Editor - {Path.GetFileName(soundBank.FilePath)}*";
}

private void OnFilterTextBoxChanged(object sender, RoutedEventArgs e) {
var text = (sender as TextBox).Text;
if (text.Length > 0) {
var rx = new Regex(text, RegexOptions.Compiled);
var filtered = soundBank.StreamInfos.Where(info => rx.Match(info.Note).Success || rx.Match(info.Id.ToString()).Success);
dataGrid.ItemsSource = filtered;
dataGrid.DataContext = filtered;
} else {
dataGrid.ItemsSource = soundBank.StreamInfos;
dataGrid.DataContext = soundBank.StreamInfos;
}
}

private void OnPlayButtonClick(object sender, RoutedEventArgs e) {
if (!converterAvailable) {
return;
Expand Down Expand Up @@ -223,20 +238,9 @@ private void OnRecentFileClick(object sender, RoutedEventArgs e) {
}
}

private void OnListViewSelectionChanged(object sender, SelectionChangedEventArgs e) {
replaceSelectedButton.IsEnabled = converterAvailable && listView.SelectedItems.Count > 0;
extractSelectedButton.IsEnabled = converterAvailable && listView.SelectedItems.Count > 0;
}

private void OnListViewSizeChanged(object sender, SizeChangedEventArgs e) {
ListView listView = sender as ListView;
GridView gridView = listView.View as GridView;

gridView.Columns[0].Width = 40;
var workingWidth = Math.Max(0, listView.ActualWidth - SystemParameters.VerticalScrollBarWidth * 2 - gridView.Columns[0].Width - 16);
for (var i = 1; i < gridView.Columns.Count; i++) {
gridView.Columns[i].Width = workingWidth / (gridView.Columns.Count - 1);
}
private void OnDataGridSelectionChanged(object sender, SelectionChangedEventArgs e) {
replaceSelectedButton.IsEnabled = converterAvailable && dataGrid.SelectedItems.Count > 0;
extractSelectedButton.IsEnabled = converterAvailable && dataGrid.SelectedItems.Count > 0;
}

private void OnWindowClosed(object sender, EventArgs e) {
Expand Down Expand Up @@ -318,9 +322,9 @@ public void OnSoundBankLoaded(object sender, RunWorkerCompletedEventArgs e) {
Title = $"PD2 Soundbank Editor - {Path.GetFileName(soundBank.FilePath)}";

var containsEmedded = soundBank.StreamInfos.Count > 0;
listView.ItemsSource = soundBank.StreamInfos;
listView.DataContext = soundBank.StreamInfos;
OnFilterTextBoxChanged(filterTextBox, null);
extractAllButton.IsEnabled = converterAvailable && containsEmedded;
filterTextBox.IsEnabled = containsEmedded;
if (!containsEmedded) {
MessageBox.Show($"This soundbank does not contain any embedded streams.", "Information", MessageBoxButton.OK, MessageBoxImage.Warning);
}
Expand Down
2 changes: 1 addition & 1 deletion PD2SoundBankEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<UseWPF>true</UseWPF>
<StartupObject></StartupObject>
<AssemblyName>PD2SoundBankEditor</AssemblyName>
<Version>0.9.0</Version>
<Version>1.0.0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
Expand Down

0 comments on commit aa5ea2e

Please sign in to comment.