DragAndDrop core
This commit is contained in:
93
Lattice.UI.Docking/Utilities/DockUtilities.cs
Normal file
93
Lattice.UI.Docking/Utilities/DockUtilities.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using Lattice.Core.Docking.Abstractions;
|
||||
using Lattice.Core.Docking.Engine;
|
||||
using Lattice.Core.Docking.Models;
|
||||
using Lattice.UI.Docking.Abstractions;
|
||||
using Lattice.UI.Docking.Factories;
|
||||
|
||||
namespace Lattice.UI.Docking.Utilities;
|
||||
|
||||
/// <summary>
|
||||
/// Предоставляет утилитарные методы для работы с док-системой.
|
||||
/// </summary>
|
||||
public static class DockUtilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Создает дерево контролов для указанного менеджера макета.
|
||||
/// </summary>
|
||||
public static IDockControl? CreateControlTree(LayoutManager manager,
|
||||
IDockControlFactory factory, IDockControl? parentControl = null)
|
||||
{
|
||||
if (manager == null) throw new ArgumentNullException(nameof(manager));
|
||||
if (factory == null) throw new ArgumentNullException(nameof(factory));
|
||||
|
||||
return CreateControlForElement(manager.Root, factory, parentControl);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создает контрол для указанного элемента.
|
||||
/// </summary>
|
||||
public static IDockControl? CreateControlForElement(IDockElement? element,
|
||||
IDockControlFactory factory, IDockControl? parentControl = null)
|
||||
{
|
||||
if (element == null) return null;
|
||||
|
||||
var control = factory.CreateControlForElement(element);
|
||||
if (control == null) return null;
|
||||
|
||||
// Устанавливаем родительский контрол
|
||||
if (parentControl != null)
|
||||
{
|
||||
// Здесь может быть установка дополнительных связей
|
||||
}
|
||||
|
||||
// Рекурсивно создаем дочерние контролы
|
||||
if (element is DockGroup group)
|
||||
{
|
||||
if (control is IDockGroupControl groupControl)
|
||||
{
|
||||
var firstChild = CreateControlForElement(group.First, factory, control);
|
||||
var secondChild = CreateControlForElement(group.Second, factory, control);
|
||||
groupControl.SetChildren(firstChild, secondChild);
|
||||
}
|
||||
}
|
||||
|
||||
return control;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Находит контрол для указанного элемента в дереве контролов.
|
||||
/// </summary>
|
||||
public static IDockControl? FindControlForElement(IDockControl root, IDockElement element)
|
||||
{
|
||||
if (root == null) throw new ArgumentNullException(nameof(root));
|
||||
if (element == null) throw new ArgumentNullException(nameof(element));
|
||||
|
||||
if (root.Model?.Id == element.Id)
|
||||
return root;
|
||||
|
||||
if (root is IDockGroupControl groupControl)
|
||||
{
|
||||
var found = FindControlForElement(groupControl.FirstChild, element);
|
||||
if (found != null) return found;
|
||||
|
||||
found = FindControlForElement(groupControl.SecondChild, element);
|
||||
if (found != null) return found;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обновляет дерево контролов при изменении макета.
|
||||
/// </summary>
|
||||
public static void UpdateControlTree(IDockControl root, LayoutManager manager,
|
||||
IDockControlFactory factory)
|
||||
{
|
||||
if (root == null) throw new ArgumentNullException(nameof(root));
|
||||
if (manager == null) throw new ArgumentNullException(nameof(manager));
|
||||
if (factory == null) throw new ArgumentNullException(nameof(factory));
|
||||
|
||||
// TODO: Реализовать эффективное обновление дерева контролов
|
||||
// вместо полной перестройки
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user