Skip to content

Commit

Permalink
Prevented rare crash when moving mouse over the preset tree
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomEngy committed Sep 3, 2024
1 parent 3ec5c91 commit a1d3335
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions VidCoder/Controls/PresetTreeViewContainer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,28 +186,34 @@ private void OnPresetTreeItemMouseDown(object sender, MouseButtonEventArgs e)

private void OnPresetTreeItemMouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Point currentPosition = e.GetPosition(this.presetTreeView);
var timeSinceLastResize = DateTimeOffset.UtcNow - this.windowManager.LastEncodingWindowReize;
var timeSinceLastMove = DateTimeOffset.UtcNow - this.windowManager.LastEncodingWindowMove;

// For some reason there is a hang on DoDragDrop if we are resizing or moving the encode settings window on top of another window.
// Suppress drag drop in this case.
if (timeSinceLastResize > TimeSpan.FromMilliseconds(500)
&& timeSinceLastMove > TimeSpan.FromMilliseconds(500)
&& DragDropUtilities.IsMovementBigEnough(this.lastPresetTreeViewMouseDown, currentPosition))
{
this.draggedPreset = this.presetTreeView.SelectedItem as PresetViewModel;

if (this.draggedPreset != null)
{
this.windowManager.SuspendDropOnWindows();
DragDrop.DoDragDrop((DependencyObject)sender, this.presetTreeView.SelectedItem, DragDropEffects.Move);
this.windowManager.ResumeDropOnWindows();
}
}
}
try
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Point currentPosition = e.GetPosition(this.presetTreeView);
var timeSinceLastResize = DateTimeOffset.UtcNow - this.windowManager.LastEncodingWindowReize;
var timeSinceLastMove = DateTimeOffset.UtcNow - this.windowManager.LastEncodingWindowMove;

// For some reason there is a hang on DoDragDrop if we are resizing or moving the encode settings window on top of another window.
// Suppress drag drop in this case.
if (timeSinceLastResize > TimeSpan.FromMilliseconds(500)
&& timeSinceLastMove > TimeSpan.FromMilliseconds(500)
&& DragDropUtilities.IsMovementBigEnough(this.lastPresetTreeViewMouseDown, currentPosition))
{
this.draggedPreset = this.presetTreeView.SelectedItem as PresetViewModel;

if (this.draggedPreset != null)
{
this.windowManager.SuspendDropOnWindows();
DragDrop.DoDragDrop((DependencyObject)sender, this.presetTreeView.SelectedItem, DragDropEffects.Move);
this.windowManager.ResumeDropOnWindows();
}
}
}
} catch (Exception exception)
{
StaticResolver.Resolve<IAppLogger>().LogError("Error processing mouse move on preset tree:" + Environment.NewLine + exception);
}
}

private void ShowFolderMoveAdorner(TreeViewItem item)
Expand Down

0 comments on commit a1d3335

Please sign in to comment.