Auto-scroll process queue

This commit is contained in:
MBucari
2025-12-29 19:36:15 -07:00
parent 31087c0855
commit 29a5c943cb
5 changed files with 94 additions and 2 deletions

View File

@@ -38,9 +38,26 @@ internal partial class ProcessQueueControl : UserControl
logDGV.EnableHeadersVisualStyles = !Application.IsDarkModeEnabled;
ViewModel.PropertyChanged += ProcessQueue_PropertyChanged;
ViewModel.LogEntries.CollectionChanged += LogEntries_CollectionChanged;
ViewModel.ProcessStart += Book_ProcessStart;
ProcessQueue_PropertyChanged(this, new PropertyChangedEventArgs(null));
}
private void Book_ProcessStart(object? sender, ProcessBookViewModel e)
{
Invoke(() =>
{
if (ViewModel.Queue?.IndexOf(e) is int newtBookIndex && newtBookIndex > 0 && itemIsVisible(newtBookIndex - 1))
{
// Only scroll the new item into view if the previous item is visible.
// This allows users to scroll through the queue without being interrupted.
virtualFlowControl2.ScrollIntoView(newtBookIndex);
}
});
bool itemIsVisible(int newtBookIndex)
=> virtualFlowControl2.FirstRealizedIndex <= newtBookIndex && virtualFlowControl2.LastRealizedIndex >= newtBookIndex;
}
private void LogEntries_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (!IsDisposed && e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)