Skip to content

Commit

Permalink
Merge pull request #203 from Denrage/202
Browse files Browse the repository at this point in the history
  • Loading branch information
Sejsel authored Oct 8, 2023
2 parents c01b217 + 4543af1 commit ff405e1
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 4 deletions.
50 changes: 48 additions & 2 deletions ArcdpsLogManager/Sections/GuildList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Eto.Drawing;
using Eto.Forms;
Expand All @@ -25,6 +26,8 @@ public class GuildList : DynamicLayout

private ObservableCollection<GuildData> guildData;
private SelectableFilterCollection<GuildData> filtered;
private Task debounceFilterTask;
private CancellationTokenSource debounceFilterCancellationTokenSource;

private readonly GridViewSorter<GuildData> sorter;
private readonly GridView<GuildData> guildGridView;
Expand Down Expand Up @@ -76,8 +79,51 @@ public GuildList(LogCache logCache, ApiData apiData, LogDataProcessor logProcess
playerFilterBox.TextBinding.Bind(this, x => x.GuildFilter);
playerFilterBox.TextChanged += (sender, args) =>
{
guildGridView.UnselectAll();
Refresh();
if (this.debounceFilterCancellationTokenSource != null)
{
this.debounceFilterCancellationTokenSource.Cancel();
try
{
this.debounceFilterTask.Wait();
}
catch (AggregateException ex)
{
if (ex.InnerException is TaskCanceledException)
{
// NOP
}
else
{
throw;
}
}
this.debounceFilterTask.Dispose();
this.debounceFilterCancellationTokenSource.Dispose();
this.debounceFilterTask = null;
this.debounceFilterCancellationTokenSource = null;
}
this.debounceFilterCancellationTokenSource = new CancellationTokenSource();
this.debounceFilterTask = Task.Run(async () =>
{
await Task.Delay(200, this.debounceFilterCancellationTokenSource.Token);
this.debounceFilterCancellationTokenSource.Token.ThrowIfCancellationRequested();
await Application.Instance.InvokeAsync(() =>
{
guildGridView.UnselectAll();
Refresh();
});
_ = Task.Run(() =>
{
this.debounceFilterCancellationTokenSource.Cancel();
this.debounceFilterTask.Wait();
this.debounceFilterTask.Dispose();
this.debounceFilterCancellationTokenSource.Dispose();
this.debounceFilterTask = null;
this.debounceFilterCancellationTokenSource = null;
});
});
};

BeginVertical(spacing: new Size(5, 5), padding: new Padding(5));
Expand Down
51 changes: 49 additions & 2 deletions ArcdpsLogManager/Sections/PlayerList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Eto.Drawing;
using Eto.Forms;
Expand All @@ -25,6 +26,8 @@ public class PlayerList : DynamicLayout

private ObservableCollection<PlayerData> playerData;
private SelectableFilterCollection<PlayerData> filtered;
private Task debounceFilterTask;
private CancellationTokenSource debounceFilterCancellationTokenSource;

private readonly GridView<PlayerData> playerGridView;
private readonly GridViewSorter<PlayerData> sorter;
Expand Down Expand Up @@ -82,8 +85,52 @@ public PlayerList(LogCache logCache, ApiData apiData, LogDataProcessor logProces
var playerFilterBox = new TextBox();
playerFilterBox.TextBinding.Bind(this, x => x.PlayerFilter);
playerFilterBox.TextChanged += (sender, args) => {
playerGridView.UnselectAll();
Refresh();
if (this.debounceFilterCancellationTokenSource != null)
{
this.debounceFilterCancellationTokenSource.Cancel();
try
{
this.debounceFilterTask.Wait();
}
catch (AggregateException ex)
{
if (ex.InnerException is TaskCanceledException)
{
// NOP
}
else
{
throw;
}
}
this.debounceFilterTask.Dispose();
this.debounceFilterCancellationTokenSource.Dispose();
this.debounceFilterTask = null;
this.debounceFilterCancellationTokenSource = null;
}
this.debounceFilterCancellationTokenSource = new CancellationTokenSource();
this.debounceFilterTask = Task.Run(async () =>
{
await Task.Delay(200, this.debounceFilterCancellationTokenSource.Token);
this.debounceFilterCancellationTokenSource.Token.ThrowIfCancellationRequested();
await Application.Instance.InvokeAsync(() =>
{
playerGridView.UnselectAll();
Refresh();
});
_ = Task.Run(() =>
{
this.debounceFilterCancellationTokenSource.Cancel();
this.debounceFilterTask.Wait();
this.debounceFilterTask.Dispose();
this.debounceFilterCancellationTokenSource.Dispose();
this.debounceFilterTask = null;
this.debounceFilterCancellationTokenSource = null;
});
});
};

BeginVertical(spacing: new Size(5, 5), padding: new Padding(5));
Expand Down

0 comments on commit ff405e1

Please sign in to comment.