Убраны синхронные методы
This commit is contained in:
@@ -4,6 +4,8 @@ using Lattice.Core.DragDrop.Services;
|
||||
using Lattice.Core.Geometry;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Lattice.UI.DragDrop.Behaviors;
|
||||
|
||||
@@ -103,7 +105,7 @@ public abstract class DragSourceBehaviorBase<TElement> : IDragSource
|
||||
/// Обрабатывает начало взаимодействия (например, нажатие мыши).
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция в координатах элемента.</param>
|
||||
protected virtual void OnInteractionStarted(Point position)
|
||||
protected virtual async Task OnInteractionStarted(Point position)
|
||||
{
|
||||
if (_isDragging)
|
||||
return;
|
||||
@@ -115,7 +117,7 @@ public abstract class DragSourceBehaviorBase<TElement> : IDragSource
|
||||
/// Обрабатывает перемещение во время взаимодействия.
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция в координатах элемента.</param>
|
||||
protected virtual void OnInteractionMoved(Point position)
|
||||
protected virtual async Task OnInteractionMoved(Point position)
|
||||
{
|
||||
if (_isDragging)
|
||||
return;
|
||||
@@ -123,14 +125,14 @@ public abstract class DragSourceBehaviorBase<TElement> : IDragSource
|
||||
var distance = CalculateDistance(_dragStartPosition, position);
|
||||
if (distance > DragDropService.DragStartThreshold)
|
||||
{
|
||||
StartDragOperation();
|
||||
await StartDragOperation();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обрабатывает завершение взаимодействия.
|
||||
/// </summary>
|
||||
protected virtual void OnInteractionEnded()
|
||||
protected virtual async Task OnInteractionEnded()
|
||||
{
|
||||
// Сброс состояния, если перетаскивание не началось
|
||||
if (!_isDragging)
|
||||
@@ -142,11 +144,11 @@ public abstract class DragSourceBehaviorBase<TElement> : IDragSource
|
||||
/// <summary>
|
||||
/// Обрабатывает отмену взаимодействия.
|
||||
/// </summary>
|
||||
protected virtual void OnInteractionCancelled()
|
||||
protected virtual async Task OnInteractionCancelled()
|
||||
{
|
||||
if (_isDragging)
|
||||
{
|
||||
DragDropService.CancelDrag();
|
||||
await DragDropService.CancelDragAsync();
|
||||
}
|
||||
Reset();
|
||||
}
|
||||
@@ -154,7 +156,7 @@ public abstract class DragSourceBehaviorBase<TElement> : IDragSource
|
||||
/// <summary>
|
||||
/// Начинает операцию перетаскивания.
|
||||
/// </summary>
|
||||
protected virtual void StartDragOperation()
|
||||
protected virtual async Task StartDragOperation()
|
||||
{
|
||||
if (_isDragging || AssociatedElement == null)
|
||||
return;
|
||||
@@ -163,7 +165,7 @@ public abstract class DragSourceBehaviorBase<TElement> : IDragSource
|
||||
var screenPosition = ConvertToScreenCoordinates(_dragStartPosition);
|
||||
|
||||
// Начинаем перетаскивание
|
||||
_isDragging = DragDropService.StartDrag(this, screenPosition);
|
||||
_isDragging = await DragDropService.StartDragAsync(this, screenPosition);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -195,30 +197,25 @@ public abstract class DragSourceBehaviorBase<TElement> : IDragSource
|
||||
#region IDragSource Implementation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public abstract bool CanStartDrag(out DragInfo? dragInfo);
|
||||
public abstract Task<(bool CanStart, DragInfo? DragInfo)> CanStartDragAsync(CancellationToken ct = default);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual bool StartDrag(DragInfo dragInfo)
|
||||
public virtual async Task<bool> StartDragAsync(DragInfo dragInfo, CancellationToken ct = default)
|
||||
{
|
||||
// Базовая реализация всегда разрешает начало перетаскивания
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual void DragCompleted(DragInfo dragInfo, Core.DragDrop.Enums.DragDropEffects effects)
|
||||
public virtual async Task DragCompletedAsync(DragInfo dragInfo, Core.DragDrop.Enums.DragDropEffects effects, CancellationToken ct = default)
|
||||
{
|
||||
_isDragging = false;
|
||||
|
||||
// Оповещаем о завершении перетаскивания
|
||||
OnDragCompleted(dragInfo, effects);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual void DragCancelled(DragInfo dragInfo)
|
||||
public virtual async Task DragCancelledAsync(DragInfo dragInfo, CancellationToken ct = default)
|
||||
{
|
||||
_isDragging = false;
|
||||
|
||||
// Оповещаем об отмене перетаскивания
|
||||
OnDragCancelled(dragInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ using Lattice.Core.DragDrop.Services;
|
||||
using Lattice.Core.Geometry;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Lattice.UI.DragDrop.Behaviors;
|
||||
|
||||
@@ -176,15 +178,27 @@ public abstract class DropTargetBehaviorBase<TElement> : IDropTarget
|
||||
#region IDropTarget Implementation
|
||||
|
||||
/// <inheritdoc/>
|
||||
public abstract bool CanAcceptDrop(DropInfo dropInfo);
|
||||
public abstract Task<bool> CanAcceptDropAsync(DropInfo dropInfo, CancellationToken ct = default);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual void DragOver(DropInfo dropInfo)
|
||||
public virtual async Task DragOverAsync(DropInfo dropInfo, CancellationToken ct = default)
|
||||
{
|
||||
// Базовая реализация устанавливает эффект по умолчанию
|
||||
if (CanAcceptDrop(dropInfo))
|
||||
if (await CanAcceptDropAsync(dropInfo))
|
||||
{
|
||||
dropInfo.SuggestedEffects = Core.DragDrop.Enums.DragDropEffects.Move;
|
||||
// Установить эффект по умолчанию, если он разрешен
|
||||
if (dropInfo.CanAcceptEffect(Core.DragDrop.Enums.DragDropEffects.Move))
|
||||
{
|
||||
dropInfo.SuggestedEffects = Core.DragDrop.Enums.DragDropEffects.Move;
|
||||
}
|
||||
else if (dropInfo.CanAcceptEffect(Core.DragDrop.Enums.DragDropEffects.Copy))
|
||||
{
|
||||
dropInfo.SuggestedEffects = Core.DragDrop.Enums.DragDropEffects.Copy;
|
||||
}
|
||||
else if (dropInfo.CanAcceptEffect(Core.DragDrop.Enums.DragDropEffects.Link))
|
||||
{
|
||||
dropInfo.SuggestedEffects = Core.DragDrop.Enums.DragDropEffects.Link;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -193,10 +207,10 @@ public abstract class DropTargetBehaviorBase<TElement> : IDropTarget
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public abstract void Drop(DropInfo dropInfo);
|
||||
public abstract Task DropAsync(DropInfo dropInfo, CancellationToken ct = default);
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual void DragLeave()
|
||||
public virtual async Task DragLeaveAsync(CancellationToken ct = default)
|
||||
{
|
||||
// Базовая реализация не делает ничего
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user