This commit is contained in:
Théo Marchal 2022-11-13 15:52:27 +01:00
parent 468ec8be07
commit f6eb00759a
2 changed files with 83 additions and 70 deletions

View File

@ -1,7 +1,7 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Windows;
using System;
using System.ComponentModel;
using System.Windows.Interop;
using System.Windows.Controls;

View File

@ -1,15 +1,16 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using System.Windows.Media;
using System.Linq;
using System.Windows.Input;
using System.Windows.Threading;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using MpcNET.Commands.Database;
using MpcNET.Tags;
using MpcNET.Types;
@ -149,65 +150,6 @@ namespace unison
return FilterOperator.Equal;
}
private async void UpdateFilter_Clicked(object sender, RoutedEventArgs e)
{
QueryFilterText.Visibility = Visibility.Visible;
await UpdateFilter();
QueryFilterText.Visibility = Visibility.Collapsed;
}
private async Task UpdateFilter()
{
Filters.Clear();
foreach (ContentPresenter superChild in FilterPanel.Children)
{
ITag tag = MpdTags.Title;
FilterOperator op = FilterOperator.None;
string value = "";
bool isDir = false;
StackPanel stackPanel = VisualTreeHelper.GetChild(superChild, 0) as StackPanel;
foreach (TextBox child in stackPanel.Children.OfType<TextBox>())
{
if (child.Name == "FilterValue")
value = child.Text;
}
foreach (ComboBox child in stackPanel.Children.OfType<ComboBox>())
{
if (child.Name == "FilterType")
{
if (child.SelectedItem.ToString() == "Directory")
isDir = true;
else
tag = FilterEquivalence_Type(child.SelectedItem.ToString());
}
if (child.Name == "FilterOperator")
op = FilterEquivalence_Operator(child.SelectedItem.ToString());
if (child.Name == "FilterList" && child.Visibility == Visibility.Visible)
value = child.SelectedItem.ToString();
}
if (value != "")
{
if (!isDir)
Filters.Add(new FilterTag(tag, value, op));
else
Filters.Add(new FilterBase(value, FilterOperator.None));
await Task.Run(async () =>
{
await _shuffle.GetSongsFromFilter(Filters, _mpd._cancelCommand.Token);
});
SongFilterPanel.Visibility = Visibility.Visible;
SongFilterNumber.Text = _shuffle.SongList.Count.ToString();
}
}
}
private void FilterType_Change(object sender, string Operator, List<string> Listing)
{
ComboBox comboBox = sender as ComboBox;
@ -271,6 +213,83 @@ namespace unison
SongFilterNumber.Text = "0";
}
private async void UpdateFilter_Clicked(object sender, RoutedEventArgs e)
{
QueryFilterText.Visibility = Visibility.Visible;
await UpdateFilter();
TimedText(QueryFilterText, 1);
}
private void TimedText(TextBlock textBlock, int time)
{
DispatcherTimer Timer = new DispatcherTimer();
Timer.Interval = TimeSpan.FromSeconds(time);
Timer.Tick += (sender, args) =>
{
Timer.Stop();
textBlock.Visibility = Visibility.Collapsed;
};
Timer.Start();
}
private async Task UpdateFilter()
{
Filters.Clear();
foreach (ContentPresenter superChild in FilterPanel.Children)
{
ITag tag = MpdTags.Title;
FilterOperator op = FilterOperator.None;
string value = "";
bool isDir = false;
StackPanel stackPanel = VisualTreeHelper.GetChild(superChild, 0) as StackPanel;
foreach (TextBox child in stackPanel.Children.OfType<TextBox>())
{
if (child.Name == "FilterValue")
value = child.Text;
}
foreach (ComboBox child in stackPanel.Children.OfType<ComboBox>())
{
if (child.Name == "FilterType")
{
if (child.SelectedItem.ToString() == "Directory")
isDir = true;
else
tag = FilterEquivalence_Type(child.SelectedItem.ToString());
}
if (child.Name == "FilterOperator")
op = FilterEquivalence_Operator(child.SelectedItem.ToString());
if (child.Name == "FilterList" && child.Visibility == Visibility.Visible)
value = child.SelectedItem.ToString();
}
if (value != "")
{
if (!isDir)
Filters.Add(new FilterTag(tag, value, op));
else
Filters.Add(new FilterBase(value, FilterOperator.None));
await Task.Run(async () =>
{
await _shuffle.GetSongsFromFilter(Filters, _mpd._cancelCommand.Token);
});
SongFilterPanel.Visibility = Visibility.Visible;
SongFilterNumber.Text = _shuffle.SongList.Count.ToString();
}
}
}
private void QueryFilterHandler(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
UpdateFilter_Clicked(null, null);
}
private void QueueValidationTextBox(object sender, TextCompositionEventArgs e)
{
Regex regex = new Regex("[^0-9]+");
@ -322,7 +341,7 @@ namespace unison
int Num = int.Parse(SongNumber.Text);
await AddToQueue_Internal(Num);
SearchStatus.Visibility = Visibility.Collapsed;
TimedText(SearchStatus, 2);
}
private async Task AddToQueue_Internal(int Num)
@ -343,12 +362,6 @@ namespace unison
}
}
private void QueryFilterHandler(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)
UpdateFilter_Clicked(null, null);
}
private void AddToQueueHandler(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return)